Skip Menu |

This queue is for tickets about the DBD-SQLite CPAN distribution.

Report information
The Basics
Id: 80676
Status: stalled
Priority: 0/
Queue: DBD-SQLite

People
Owner: Nobody in particular
Requestors: cst [...] dbs.uni-hannover.de
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 1.35
  • 1.37
Fixed in: (no value)



Subject: Indirectly Defined Columns and Prepared Queries
If a column is defined indirectly, like so: CREATE TABLE master ( id INTEGER PRIMARY KEY ); CREATE TABLE test2 ( id REFERENCES master, str VARCHAR(10) ); where 'id' in table 'test2' is derived from 'id' in 'master', a prepared query may falsely return an undefined row. E.g. let table 'test2' contain the row (25, 'hello!'). Then the following code should not return an undefined row: $sth = $dbh->prepare('select * from test2 where id = ?'); $sth->execute(25); $row = $sth->fetchrow_arrayref; See the attached code for a more detailed example. (This may be a bug from upstream, but I don't know how to differentiate that, sorry. :-/)
Subject: sqlite-bug.pl
#!/usr/bin/perl use strict; use warnings; use DBI; my $dbh = DBI->connect("dbi:SQLite:dbname=","","", { RaiseError => 1 } ); map { $dbh->do($_) } split /;/, <<SCHEMA; CREATE TABLE master ( id INTEGER PRIMARY KEY ); CREATE TABLE test1 ( id INTEGER REFERENCES master, str VARCHAR(10) ); CREATE TABLE test2 ( id REFERENCES master, str VARCHAR(10) ); INSERT INTO test1 VALUES ( 25, 'hello!'); INSERT INTO test2 VALUES ( 25, 'hello!'); SCHEMA my ($sth, $row); # query 1 $sth = $dbh->prepare('select * from test1 where id = ?'); $sth->execute(25); $row = $sth->fetchrow_arrayref; print defined $row ? "row: @$row" : 'row is undefined!'; print "\n"; # query 2 $sth = $dbh->prepare('select * from test2 where id = 25'); $sth->execute(); $row = $sth->fetchrow_arrayref; print defined $row ? "row: @$row" : 'row is undefined!'; print "\n"; # query 3 $sth = $dbh->prepare('select * from test2 where id = ?'); $sth->execute(25); $row = $sth->fetchrow_arrayref; print defined $row ? "row: @$row" : 'row is undefined!'; print "\n";
This is a known issue of DBD::SQLite. See the following: https://metacpan.org/module/DBD::SQLite#Functions-And-Bind-Parameters Thanks. On Wed Nov 07 09:47:06 2012, chrstahl wrote: Show quoted text
> If a column is defined indirectly, like so: > > CREATE TABLE master ( id INTEGER PRIMARY KEY ); > CREATE TABLE test2 ( id REFERENCES master, str VARCHAR(10) ); > > where 'id' in table 'test2' is derived from 'id' in 'master', > a prepared query may falsely return an undefined row. > > E.g. let table 'test2' contain the row (25, 'hello!'). > Then the following code should not return an undefined row: > > $sth = $dbh->prepare('select * from test2 where id = ?'); > $sth->execute(25); > $row = $sth->fetchrow_arrayref; > > See the attached code for a more detailed example. > > (This may be a bug from upstream, but I don't know how to
differentiate Show quoted text
> that, sorry. :-/)
From: cst [...] dbs.uni-hannover.de
On Tue Nov 06 21:39:17 2012, ISHIGAKI wrote: Show quoted text
> This is a known issue of DBD::SQLite. See the following: > > https://metacpan.org/module/DBD::SQLite#Functions-And-Bind-Parameters > > Thanks.
Thank you for your help. The workarounds mentioned in the documentation solve my problem. However I still think that the queries in my example should be consistent and return the same result. This seems to be problem with SQLite itself though, so I brought the issue to the attention of the developers: http://article.gmane.org/gmane.comp.db.sqlite.general/77945 kind regards, Christian