DBD::SQLite 1.09 dies if select returns 0 rows

DBD::SQLite 1.09 dies if select returns 0 rows

am 10.08.2005 21:35:31 von hjp

--PEIAKu/WMn1b1Hv9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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 =3D DBI->connect("dbi:SQLite:dbname=3Dtest.sqlite","","",=20
{ AutoCommit =3D> 0, RaiseError =3D> 1 });

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

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

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

# the next line causes an exception, but shouldn't:
$tkcount =3D $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

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

--PEIAKu/WMn1b1Hv9
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iQDQAwUBQvpXA1LjemazOuKpAQHCvQXUCv0eAQ1EZaxt97gZjMR1aUfmhEHc 5aIP
oulV06j8iBW/87S2+kM5HAxpl5d38981UoLIrsVl2iQxTmR0xAVYZIOSaasY 7U1n
bHP5C3KsJYvZ1xMdLbtLKiqeOqvYfBPvEThI9vWzJpLg44o0Wt+Anf6oeJJD HYVz
/JbszozJ/5gzGA+g0/7Ho8WTQpKVSjhdRTRIAX4nuQRIBwOyf6D2JWlHnz59 OGL/
cJrh1vBT31d4Y+Ie5urFj/9T8g==
=TnSj
-----END PGP SIGNATURE-----

--PEIAKu/WMn1b1Hv9--

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

am 12.08.2005 15:02:18 von hjp

--HWvPVVuAAfuRc6SZ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2005-08-12 14:36:02 -0400, Owen wrote:
> On Wed, 10 Aug 2005 21:35:31 +0200
> "Peter J. Holzer" wrote:
> > the next line causes an exception, but shouldn't:
> > $tkcount =3D $dbh->selectrow_array($sth, {}, 'baz');
> > print "$tkcount\n";
>=20
> 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 =3D $dbh->prepare("select count from tokens where token=3D?");
my $tkcount;
$sth->execute('foo');
while (($tkcount) =3D $sth->fetchrow_array) {
print "$tkcount\n";
}
$sth->execute('bar');
while (($tkcount) =3D $sth->fetchrow_array) {
print "$tkcount\n";
}
$sth->execute('baz');
while (($tkcount) =3D $sth->fetchrow_array) {
print "$tkcount\n";
}
$dbh->disconnect;

hp

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

--HWvPVVuAAfuRc6SZ
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iQDQAwUBQvyd2lLjemazOuKpAQGtSQXSAkIh4KqHww+vyp94PVYRSG4jbfec f9Oq
CLIy+XzuVAUGx29vrci3j3yG+z+gW8LCxz0oRlOlRINWVspgIzVwCavKL5Kk SzDC
inW9SbYd/h4YECOYsupI4lo8eD/nCDsEQ/gNO18zKfBXi2aqAUy4wuJYexS8 DS42
UKtKxXomzKLybSZkfqSwv5wbh25VlK8+UCJEAQFHsdScN6BkW/HnZklvOIPP IYJs
0Km7Essg6eZCEkOLPjg3Zhdmmw==
=ZyE6
-----END PGP SIGNATURE-----

--HWvPVVuAAfuRc6SZ--

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

am 12.08.2005 20:36:02 von rcook

On Wed, 10 Aug 2005 21:35:31 +0200
"Peter J. Holzer" 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
--