Subject: | $dbd->func('last_insert_rowid') incompatibilities |
The attached demo.pl demonstrates $dbd->func('last_insert_rowid') fails to work (it returns the same number) when either prepare_cached() and/or selectrow_hashref() is also being used. This is on Perl v5.8.1-RC3 running on OS X 10.3.4 (Darwin 7.4.1). demo.pl works as expected when running under 0.31. (On a different Mac, though I'd be surprised if this made any difference.)
--Michael
#!/usr/bin/env perl
use strict;
use warnings;
use DBI;
my $dbh = DBI->connect("DBI:SQLite:dbname=test.db", "", "");
$dbh->do(q{
DROP TABLE foo
});
$dbh->do(q{
CREATE TABLE foo (
pkey INTEGER PRIMARY KEY
)
});
my $s1 = q{
INSERT INTO foo(pkey) VALUES(NULL)
};
my $s2 = q{
SELECT * FROM foo WHERE pkey = ?
};
foreach (1 .. 5) {
# WORKS IF:
# 1. THE BELOW IS prepare(), NOT prepare_cached()
my $sth1 = $dbh->prepare_cached($s1);
$sth1->execute;
my $last = $dbh->func('last_insert_rowid');
print "last_insert_rowid = $last\n";
# 2. THE BELOW IS COMMENTED OUT
my $sth2 = $dbh->selectrow_hashref($s2, {}, $last);
}