From 6de5c908f713d4da522011174f17e756fdef8cab Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Thu, 13 Aug 2009 11:28:40 +0000 Subject: [PATCH] DBD-SQLite: now BegunWork (set by begin_work) is handled properly (as requested in DBI::Changes; see notes for 1.20), and this resolved rt #48393. In fact, it looks like I lost this code by mistake while preparing the previous release. I remember I wrote this before... I added a test for this, but as it requires the perl debugger, it is disabled by default. Wondering if we can do it without calling system() and the likes... --- dbdimp.c | 10 +++++ t/rt_48393_debug_panic_with_commit.t | 57 ++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 t/rt_48393_debug_panic_with_commit.t diff --git a/dbdimp.c b/dbdimp.c index 0dc4552..0c9a4f4 100644 --- a/dbdimp.c +++ b/dbdimp.c @@ -201,6 +201,11 @@ sqlite_db_rollback(SV *dbh, imp_dbh_t *imp_dbh) int retval; char *errmsg; + if (DBIc_is(imp_dbh, DBIcf_BegunWork)) { + DBIc_off(imp_dbh, DBIcf_BegunWork); + DBIc_on(imp_dbh, DBIcf_AutoCommit); + } + if (!sqlite3_get_autocommit(imp_dbh->db)) { sqlite_trace(dbh, (imp_xxh_t*)imp_dbh, 2, "ROLLBACK TRAN"); if ((retval = sqlite3_exec(imp_dbh->db, "ROLLBACK TRANSACTION", @@ -229,6 +234,11 @@ sqlite_db_commit(SV *dbh, imp_dbh_t *imp_dbh) return TRUE; } + if (DBIc_is(imp_dbh, DBIcf_BegunWork)) { + DBIc_off(imp_dbh, DBIcf_BegunWork); + DBIc_on(imp_dbh, DBIcf_AutoCommit); + } + if (!sqlite3_get_autocommit(imp_dbh->db)) { sqlite_trace(dbh, (imp_xxh_t*)imp_dbh, 2, "COMMIT TRAN"); if ((retval = sqlite3_exec(imp_dbh->db, "COMMIT TRANSACTION", diff --git a/t/rt_48393_debug_panic_with_commit.t b/t/rt_48393_debug_panic_with_commit.t new file mode 100644 index 0000000..34eb0ea --- /dev/null +++ b/t/rt_48393_debug_panic_with_commit.t @@ -0,0 +1,57 @@ +#!/usr/bin/perl + +use strict; +BEGIN { + $| = 1; + $^W = 1; +} + +use t::lib::Test; +use Test::More; + +BEGIN { + plan skip_all => + 'set $ENV{TEST_DBD_SQLITE_WITH_DEBUGGER} '. + 'to enable this test' + unless $ENV{TEST_DBD_SQLITE_WITH_DEBUGGER}; +} + +use Test::NoWarnings; + +plan tests => 2; + +my $file = 't/panic.pl'; +open my $fh, '>', $file; +print $fh ; +close $fh; + +ok !system("$^X -Mblib -d $file"); + +END { + unlink $file if $file && -f $file; + unlink 'test.db' if -f 'test.db'; +} + +__DATA__ +use strict; +use warnings; +use DBI; + +my $db_file = 'test.db'; + +unlink($db_file); +die "Could not delete $db_file - $!" if(-e $db_file); + +my $dbh = DBI->connect("dbi:SQLite:dbname=$db_file", undef, undef, { +RaiseError => 1, AutoCommit => 1 }); + +$dbh->do('CREATE TABLE t1 (id int)'); + +$dbh->begin_work or die $dbh->errstr; + +my $sth = $dbh->prepare('INSERT INTO t1 (id) VALUES (1)'); +$sth->execute; + +# XXX: Panic occurs here when running under the debugger +$dbh->commit or die $dbh->errstr; +