From 9367bd61a6b29ad9b0dbb083d094a1c1818d10c5 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Thu, 20 Oct 2011 16:16:17 +0000 Subject: [PATCH] explained finish and rollback issue --- lib/DBD/SQLite.pm | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/DBD/SQLite.pm b/lib/DBD/SQLite.pm index 094b588..a105d60 100644 --- a/lib/DBD/SQLite.pm +++ b/lib/DBD/SQLite.pm @@ -952,6 +952,34 @@ Note that this works only when all of the connections use the same (non-deferred) transaction. See L for locking details. +=head2 C<< $sth->finish >> and Transaction Rollback + +As the L doc says, you almost certainly do B need to +call L method if you fetch all rows (probably in a loop). +However, there are several exceptions to this rule, and rolling-back +of an unfinished C statements in +a transaction (See L for +details). So you need to call C before you issue a rollback. + + $sth = $dbh->prepare("SELECT * FROM t"); + $dbh->begin_work; + eval { + $sth->execute; + $row = $sth->fetch; + ... + die "For some reason"; + ... + }; + if($@) { + $sth->finish; # You need this for SQLite + $dbh->rollback; + } else { + $dbh->commit; + } + =head2 Processing Multiple Statements At A Time L's statement handle is not supposed to process multiple