On Fri, Mar 21, 2003 at 02:20:51PM -0800, John Costello wrote:

> I have a simple query that, when run via Oracle SQL*Plus returns 38947 
> rows.
> 
> If I run the query using Activestate/DBI/DBD, I get 187 rows.  Does DBI 
> buffer results?
> 
> Here is the script, with the original query:
> 
> ----
> use DBI;
> 
> $port = "1521";
> $host = "myhost.mydomain.com";
> $sid = "LYST";
> $user = $passwd = $ARGV[0];
> $dbh = DBI->connect("dbi:Oracle:host=$host;sid=$sid;port=$port", $user, 
> $passwd) || die "Unable to connect to host $host SID $sid on port 
> $port\n";
> 
> $query = 'SELECT id FROM solution_container';
> 
> $sth = $dbh->prepare($query);
> print $sth->errstr; print "\n";
> if (($num_rows = $sth->execute() || die "Unable to select") < 0) {
>               print "No rows selected.\n";
>               exit(1);
>       }
> print "Number of rows: $num_rows\n";

perldoc DBI:

       rows

             $rv = $sth->rows;

           Returns the number of rows affected by the last row
           affecting command, or -1 if the number of rows is not
           known or not available.

           Generally, you can only rely on a row count after a
           non-SELECT execute (for some specific operations like
           UPDATE and DELETE), or after fetching all the rows of
           a SELECT statement.


You have not fetched all the rows from the statement handle.  Therefore,
you cannot rely on the value returned by rows().

You can either fetch all the rows, or select count() in the SQL instead.

Ronald

Reply via email to