At 16:15 +0000 1/10/03, Jeff Snoxell wrote:
Hi,

I've been using the return value of $sth->execute(); (in Perl DBI) to
determine if I have a result set. I'm not using the value I get back but am
assuming that if it's >=1 then I have some results.
That's incorrect because it's valid for a result set to be empty (have
zero rows).  Consider the result of "SELECT * FROM t WHERE 1 = 0".


You don't need to use the return value at all.  Check the metadata to
see if the number of columns is zero.  If it is, there's no result set.
If it's > 0, there is a result set.

Some code to illustrate:

printf "Query: %s\n", $query;
my $sth = $dbh->prepare ($query);
$sth->execute();
# metadata information becomes available at this point ...
printf "NUM_OF_FIELDS: %d\n", $sth->{NUM_OF_FIELDS};
print "Note: query has no result set\n" if $sth->{NUM_OF_FIELDS} == 0;


Is this a safe thing to do with MySQL?

And

The results do actually seem to be correct for the number of records I get
back. Should this be the case? Is it reliable?
If you mean, can you interpret the $sth->execute() result as a row
count, the DBI docs specifically discourage it.

Thanks,

Jeff

---------------------------------------------------------------------
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to