Click here to get back home

DBI does not do what I expect...

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
DBI does not do what I expect... Mark Jaffe 03-12-2008
Posted by Mark Jaffe on March 12, 2008, 4:18 am
Please log in for more thread options
Hi,

I am working with a CGI to inspect a database, and I want to include a
count of records in each table in the display. I have two screens
available in the UI: one to list the tables in the d/b, and the other to
show the records in each table. I want to provide a preview of how big
each table is in the table listing, so the code preparing the table list
is doing this:

my $ary_ref = $dbh->selectcol_arrayref ( "SHOW TABLES FROM $db_name" );
# Construct a bullet list using the ul() and li functions. Each item
# is a hyperlink that re-invokes the script to display a particular
table.
my @item;
foreach my $tbl_name (@) {
my $url = sprintf ("%s?tbl_name=%s", url(), escape($tbl_name));
my $link = a ({-href => $url}, escapeHTML($tbl_name));
my $sth = $dbh->prepare ( qq (
SELECT COUNT(*) FROM $tbl_name ) );
my $rv = $sth->execute();
my $rows = $sth->rows;
push (@item, li ($link . " $rows in table" ) );
}
print ul (@item);

But when I execute the SQL, I only get "1" returned for each "$rows",
rather than what I expect, the number of rows.

Why is this not working for me?

Thanks,
Mark

Posted by Frank Seitz on March 12, 2008, 4:48 am
Please log in for more thread options
Mark Jaffe wrote:
>
> But when I execute the SQL, I only get "1" returned for each "$rows",
> rather than what I expect, the number of rows.
>
> Why is this not working for me?

"SELECT COUNT(*) ..." returns one row, which is the number
of counted rows.

Frank
--
Dipl.-Inform. Frank Seitz; http://www.fseitz.de/
Anwendungen für Ihr Internet und Intranet
Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Posted by Keith on March 13, 2008, 9:00 am
Please log in for more thread options
> Mark Jaffe wrote:
>
> > But when I execute the SQL, I only get "1" returned for each "$rows",
> > rather than what I expect, the number of rows.
>
> > Why is this not working for me?
>
> "SELECT COUNT(*) ..." returns one row, which is the number
> of counted rows.
>
> Frank
> --
> Dipl.-Inform. Frank Seitz;http://www.fseitz.de/
> Anwendungen f=FCr Ihr Internet und Intranet
> Tel: 04103/180301; Fax: -02; Industriestr. 31, 22880 Wedel

Exactly. So, not to put too fine a point on it what Mark wanted to do
was something like:

"SELECT COUNT(*) Cnt..."
=2E..
my $srcHref =3D $sth->fetchrow_hashref();
print $srcHref->;

# QED



Similar ThreadsPosted
using Net::SSH::Perl with Expect November 21, 2005, 3:41 pm
Expect::Simple December 1, 2005, 4:19 pm
Expect::Simple December 2, 2005, 9:22 am
Expect: Getting PID at both ends of ssh January 22, 2007, 3:08 pm
Expect and xterm February 27, 2007, 11:12 pm
Perl Expect question November 8, 2004, 12:20 pm
username passwd expect September 14, 2006, 12:36 am
Simple expect problem . March 21, 2007, 2:31 pm
Expect.pm module help - simple question... March 15, 2005, 12:27 pm
Problem with very simple Expect script April 24, 2005, 8:42 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap