On Wed, Mar 13, 2002 at 06:07:01AM +0000, [EMAIL PROTECTED] wrote:
> In the past someone posted a problem with mod_perl and DbI giving blank 
> pages from a SQL query. I did some digging around and found some info but I 
> need someone to fill in the holes for me a little.
> 
> I created a DB Table "webtest". In the table, I filled it with the contents 
> of /usr/local/dict/propernames. Fine! it worked beautifully. 
> 
> However, when I do a "random" query I get some blank pages. I traced this to 
> the DBI Log using the "DBH->Trace(2, /tmp/DBI.log)". I found that sometimes 
> the "execute()" returns "0E0". Does anybody knows why?? 
> 
> I did a simple logic to check for the value return by "execute()", if the 
> value is "0E0" then do the same query. Do this same query until the value 
> return by "execute()" is not "0E0". However, I am still getting blank pages. 
> 

SELECT queries return 0E0 from execute() to indicate success, because the
actual number of rows is not known until you fetch them.

UPDATE and DELETE queries return 0E0 from execute() when the execution was
successful but no rows were affected.


You're probably getting a blank page because no row is being found.  This
could happen if there are gaps in ids in the table.  It could also happen
if rand() returns a number close to 1, because you're using ROUND() when
you should be using TRUNC().


Also, the logic in this section of the code does not make sense:

>     17         my $RowHandlesth = $DBH->prepare("SELECT * FROM webtest WHERE id = 
>ROUND( (RAND() * ?) + 1)");
>     18         $RowHandlesth->execute($id);
>     19
>     20         while (! $RowHandlesth ) {
>     21                 $RowHandlesth->execute($id);

If $RowHandlesth is false, it's because prepare() returned undef.  You
can't call a method on the undefined value.

On the other hand, at least this will cause a fatal error; otherwise you
would have an infinite loop, because once you enter the loop $RowHandlesth
will never become true.

>     22
>     23                 if ( $RowHandlesth ) {

You entered the loop because $RowHandlesth was false, and you haven't changed
it's value since entering the loop.  How could it be true all of a sudden?


>     24 #                       my @row = $RowHandlesth->fetchrow;

If this line were not commented out, you would be assigning to a lexical
@row which would go out of scope right after.


>     25                         last;
>     26                 }
>     27         }
>     28         my @row = $RowHandlesth->fetchrow;


Ronald

Reply via email to