Ronald, but (not necessarily in this case, since it's a count(*) query), but
for most others it will also return the first column selected and set it to
undef if that column is NULL, so therefore it will also call the dbError()
sub. The difference with this, is the count(*) returns something, (0+) all
the time, so this won't be a problem, though in general this is not a very
good practice. RaiseError and eval are the best solutions:-)
Ilya
-----Original Message-----
From: Ronald J Kimball
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: 9/24/01 7:01 AM
Subject: Re: Avoid Error if no results
On Sat, Sep 22, 2001 at 06:37:32PM -0500, [EMAIL PROTECTED] wrote:
> this one seems to puzzle me on how to avoid an unnecessary db error. I
> need to run a tally count on a couple tables, and if there isn't any
data
> in the table it displays the dbError, altho there isn't technical any
> syntax error in the query other then no return or results.
> $sqlquery = qq|SELECT COUNT(*) FROM expired WHERE expdate <
CURDATE()|;
> $expire = $dbh->selectrow_array($sqlquery) or dbError();
>
> Is this way to avoid the dbError() if the query returns no
results(which
> would indicate a '0' tally.
If there is an error, selectrow_array() will return an empty list, which
will set $expire to undef. Thus, instead of checking whether $expire is
true, you should check whether it is defined.
defined( $expire = $dbh->selectrow_array($sqlquery) ) or dbError();
Ronald