From 16d3af7794af574b4b80fc72f9de6104ffe62188 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Tue, 5 May 2009 09:02:02 +0000 Subject: [PATCH] DBD-SQLite: started using install_method(); ported last_insert_rowid as the first attempt --- SQLite.xs | 2 ++ lib/DBD/SQLite.pm | 12 +++++++++++- t/04_insert.t | 8 +++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/SQLite.xs b/SQLite.xs index fda00aa..76aacf8 100644 --- a/SQLite.xs +++ b/SQLite.xs @@ -24,6 +24,8 @@ list_tables(dbh) IV last_insert_rowid(dbh) SV *dbh + ALIAS: + DBD::SQLite::db::sqlite_last_insert_rowid = 1 CODE: { D_imp_dbh(dbh); diff --git a/lib/DBD/SQLite.pm b/lib/DBD/SQLite.pm index 1d119a4..2ccffae 100644 --- a/lib/DBD/SQLite.pm +++ b/lib/DBD/SQLite.pm @@ -24,13 +24,23 @@ BEGIN { __PACKAGE__->bootstrap($VERSION); +my $methods_are_installed; + sub driver { - $drh or + return $drh if $drh; + + if (!$methods_are_installed && $DBI::VERSION >= 1.608) { + DBI->setup_driver('DBD::SQLite'); + DBD::SQLite::db->install_method('sqlite_last_insert_rowid'); + $methods_are_installed++; + } + $drh = DBI::_new_drh( "$_[0]::dr", { Name => 'SQLite', Version => $VERSION, Attribution => 'DBD::SQLite by Matt Sergeant et al', } ); + return $drh; } sub CLONE { diff --git a/t/04_insert.t b/t/04_insert.t index e3635ed..08ed7a3 100644 --- a/t/04_insert.t +++ b/t/04_insert.t @@ -7,7 +7,7 @@ BEGIN { } use t::lib::Test; -use Test::More tests => 12; +use Test::More tests => 14; use Test::NoWarnings; my $dbh = connect_ok(); @@ -30,6 +30,12 @@ SCOPE: { is( $dbh->last_insert_id(undef, undef, undef, undef), 4 ); is( $dbh->func('last_insert_rowid'), 4, 'last_insert_rowid should be 4' ); } + + SKIP: { + skip( 'method installation requires DBI v1.608', 2 ) if $DBI::VERSION < 1.608; + can_ok($dbh, 'sqlite_last_insert_rowid'); + is( $dbh->sqlite_last_insert_rowid, 4, 'last_insert_rowid should be 4' ); + } } is( $dbh->do("delete from f where f1='test'"), 3 );