> -----Original Message-----
> From: Steven Vetzal [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, September 23, 2001 8:06 AM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: RE: Avoid Error if no results
>
>
> Ahh yes, what I commonly call the "null vs. 0 gank"... The perl syntax
> allowing you to run alternate code during an assignment if the return
> value of the assignment is 0 OR undef.
>
> I'm assuming you only want to call dbError if the result from
> selectrow_array() is undef (an actual error)
No, it doesn't necessarily mean an error. It returns undef also if there
are no rows to fetch, when your query did not produce results. That is the
reason you don't use (|| ....) on the fetch method, unless you specifically
want it.
and not if the result from
> selectrow_array() was that count() == 0.
>
> You should replace:
>
> $expire = $dbh->selectrow_array($sqlquery) or dbError();
>
> with 2 lines:
>
> $expire = $dbh->selectrow_array($sqlquery);
> dbError() unless defined($expire);
What happens if there is something returned, but the first column is NULL,
which will set $expire to undef? This will not produce the wanted results,
see perldoc DBI.
Ilya
>
> IMHO just one of those places it's best _not_ to use a nice compact
> perlism to reduce the size of your code.
>
> Steve
>
>
>
> > -----Original Message-----
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> > Sent: Saturday, September 22, 2001 7:38 PM
> > To: [EMAIL PROTECTED]
> > Subject: Avoid Error if no results
> >
> >
> > Hi All,
> >
> > 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.
> >
> > my $active = 0;
> > my $expire = 0;
> >
> > $sqlquery = qq|SELECT COUNT(m.memid) FROM members m,payhistory p
> > WHERE p.active = 'Y' AND p.memid = m.memid|;
> > $active = $dbh->selectrow_array($sqlquery) or dbError();
> >
> > $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.
> >
> > thx's
> >
> > Mike(mickalo)Blezien
> > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> > Thunder Rain Internet Publishing
> > Providing Internet Solutions that work!
> > http://www.thunder-rain.com
> > Tel: 1(225)686-2002
> > =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> >
> >