Re: DBD::SQLite 1.09 dies if select returns 0 rows

2005-08-12 Thread Peter J. Holzer
On 2005-08-12 14:36:02 -0400, Owen wrote:
 On Wed, 10 Aug 2005 21:35:31 +0200
 Peter J. Holzer [EMAIL PROTECTED] wrote:
   the next line causes an exception, but shouldn't:
  $tkcount = $dbh-selectrow_array($sth, {}, 'baz');
  print $tkcount\n;
 
 Yes, I get the same error message when s/baz/bar/ but not s/baz/foo/

Oops. Seems I wasn't quite awake when I tested that. I always get the
error at the second selectrow_array, regardless of whether I'm searching
for foo, bar or baz.

If I prepare a new statement handle, all three cases work as expected.

So the issue doesn't seem to be whether the query returns any rows, but
passing a statement handle to multiple selectrow_array calls.

OTOH, reusing the statement handle with execute and fetchrow_array works
fine:

my $sth = $dbh-prepare(select count from tokens where token=?);
my $tkcount;
$sth-execute('foo');
while (($tkcount) = $sth-fetchrow_array) {
print $tkcount\n;
}
$sth-execute('bar');
while (($tkcount) = $sth-fetchrow_array) {
print $tkcount\n;
}
$sth-execute('baz');
while (($tkcount) = $sth-fetchrow_array) {
print $tkcount\n;
}
$dbh-disconnect;

hp

-- 
   _  | Peter J. Holzer| In our modern say,learn,know in a day
|_|_) | Sysadmin WSR   | world, perhaps being an expert is an
| |   | [EMAIL PROTECTED]  | outdated concept.
__/   | http://www.hjp.at/ |-- Catharine Drozdowski on dbi-users.


pgpL4H24NzoJ8.pgp
Description: PGP signature


Re: DBD::SQLite 1.09 dies if select returns 0 rows

2005-08-11 Thread Owen
On Wed, 10 Aug 2005 21:35:31 +0200
Peter J. Holzer [EMAIL PROTECTED] wrote:

  the next line causes an exception, but shouldn't:
 $tkcount = $dbh-selectrow_array($sth, {}, 'baz');
 print $tkcount\n;


Yes, I get the same error message when s/baz/bar/ but not s/baz/foo/

Not sure what to make of that.


Owen
-- 


DBD::SQLite 1.09 dies if select returns 0 rows

2005-08-10 Thread Peter J. Holzer
I just installed the current version of DBD::SQLite from CPAN, and found
that it raises an error if a select returns zero rows. I don't think it
should do that. DBD::SQLite 0.31 didn't, and DBD::Oracle and DBD::mysql
don't either. Here is a simple test program:


---8--8--8--8--8--8--8--8--8---
#!/usr/local/bin/perl
use strict;
use warnings;
use DBI;

my $dbh = DBI-connect(dbi:SQLite:dbname=test.sqlite,,, 
   { AutoCommit = 0, RaiseError = 1 });

#init
my $raiseerror = $dbh-{RaiseError};
$dbh-{RaiseError} = 0;
$dbh-{PrintError} = 0;
$dbh-do(drop table tokens);
$dbh-do(create table tokens(
id integer primary key,
token varchar unique,
count int
  ));
$dbh-{RaiseError} = $raiseerror;

$dbh-do(insert into tokens(token, count) values('foo', 23));
$dbh-do(insert into tokens(token, count) values('bar', 42));

my $sth = $dbh-prepare(select count from tokens where token=?);
my $tkcount = $dbh-selectrow_array($sth, {}, 'foo');
print $tkcount\n;

# the next line causes an exception, but shouldn't:
$tkcount = $dbh-selectrow_array($sth, {}, 'baz');
print $tkcount\n;
---8--8--8--8--8--8--8--8--8---

The result is:

23
DBD::SQLite::db selectrow_array failed: not an error(21) at dbdimp.c
line 371 at ./test_sqlite line 29.
Issuing rollback() for database handle being DESTROY'd without explicit
disconnect().

hp

-- 
   _  | Peter J. Holzer| In our modern say,learn,know in a day
|_|_) | Sysadmin WSR   | world, perhaps being an expert is an
| |   | [EMAIL PROTECTED]  | outdated concept.
__/   | http://www.hjp.at/ |-- Catharine Drozdowski on dbi-users.


pgpxXjpfT0KET.pgp
Description: PGP signature