Created
December 3, 2010 05:10
-
-
Save fatgy/726606 to your computer and use it in GitHub Desktop.
Handy Hack:Perl DBI count rows returned from select statment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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