in reply to Select Count(*) result

Please place <code> tags around your code. It makes it much easier to read, and your square brackets will be properly escaped.

Also, use placeholders in your SQL, like this:

my $sql="Select Count(*) From ClearTransferData Where AccountNo = ? and TransferFlag = ? and TransferType = ? and RejectType = ? and AdpNumber = ? and Shares = ? and ProcessingDate = ? "; my $sth = $dbh->prepare($sql) or die $dbh->errstr; $sth->execute(@data); # Fetch results with $sth->fetchrow_array(), or whatever $sth->disconnect();

This is safer (since it will automagicaly escape naughty database characters), might be faster (depending on your database and the specifics of what you're doing), and is better if you end up using $dbh->prepare_cached->($sql) instead (since the data isn't contain in the SQL, the same statement can be refetched with less performance hit, even when the data chages).

$dbh->do() is for very simple cases (like SELECT COUNT(*) FROM some_table). You don't have a simple case.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Select Count(*) result
by thraxil (Prior) on May 16, 2003 at 14:32 UTC

    $dbh->do() is for very simple cases (like SELECT COUNT(*) FROM some_table). You don't have a simple case.

    actually, $dbh->do() won't work for that either. from the documentation:

    Returns the number of rows affected or "undef" on error. A return value of "-1" means the number of rows is not known, not applicable, or not available.

    This method is typically most useful for non-"SELECT" statements that either cannot be prepared in advance (due to a limitation of the driver) or do not need to be executed repeatedly. It should not be used for "SELECT" statements because it does not return a statement handle (so you can't fetch any data).

    anders pearson