Skip to content

Instantly share code, notes, and snippets.

@fatgy
Created December 3, 2010 05:10
Show Gist options
  • Save fatgy/726606 to your computer and use it in GitHub Desktop.
Save fatgy/726606 to your computer and use it in GitHub Desktop.
Handy Hack:Perl DBI count rows returned from select statment
#From http://alecthegeek.wordpress.com/2007/02/09/handy-hackperl-dbi-count-rows-returned-from-select-statment/
#In theory it’s a bad thing to assume a select will return a single scalar value instead of multiple attributes and rows, however with a count #clause we should be pretty safe. N.B. using the $dbh->rows() function or similar is not correct on a select statement.
my $rowCount = $dbh->selectrow_array(
qq{
SELECT count(*)
FROM my_table
WHERE attr1 = ?
}, undef, $myValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment