Subject: | fetchrow_hashref bug? |
PACKAGE: DBD-SQLite-0.08.tar.gz
PERLVER: 5.6.0
UNAME : Linux mangala.evilfunhouse.com 2.4.2-2smp #1 SMP Sun Apr 8 20:21:34 EDT 2001 i686 unknown
I believe this to be a bug in DBD::SQLite, but it could be a bug in SQLite library. When using DBI's fetchrow_hashref method, the hash keys (table columns) include the SQL alias (if one was given). For example, the query "SELECT t.data FROM table t" might return the hashref { "t.data" => "foo" }. I believe this to be a bug. Testing against DBD::mysql and DBD::Sybase, the same query returns { data => "foo" }.
A test script is included which demonstrates this problem.
Thanks for such an awesome module!
-Greg Williams
#!/usr/bin/perl
use DBI;
use strict;
my $dbh = DBI->connect( "dbi:SQLite:dbname=sqlite.db", "", "" );
$dbh->do( <<"END_SQL" );
CREATE TABLE test (
pkey INT PRIMARY KEY,
data VARCHAR(32)
)
END_SQL
{
my $insert = $dbh->prepare( "INSERT INTO test VALUES (?, ?)" );
$insert->execute( 1, "foo" );
$insert->execute( 2, "bar" );
my $select = $dbh->prepare( "SELECT t.data FROM test t" );
$select->execute;
while (my $h = $select->fetchrow_hashref) {
while (my($k, $v) = each(%{$h})) {
print "$k => $v\n";
}
}
}
$dbh->disconnect;
unlink( "sqlite.db" );