1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 22:28:47 -04:00

explained finish and rollback issue

This commit is contained in:
Kenichi Ishigaki 2011-10-20 16:16:17 +00:00
parent b4220250ce
commit 9367bd61a6

View file

@ -952,6 +952,34 @@ Note that this works only when all of the connections use the same
(non-deferred) transaction. See L<http://sqlite.org/lockingv3.html>
for locking details.
=head2 C<< $sth->finish >> and Transaction Rollback
As the L<DBI> doc says, you almost certainly do B<not> need to
call L<DBI/finish> 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<SELECT> statement is one of such exceptional
cases.
SQLite prohibits C<ROLLBACK> of unfinished C<SELECT> statements in
a transaction (See L<http://sqlite.org/lang_transaction.html> for
details). So you need to call C<finish> 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<DBI>'s statement handle is not supposed to process multiple