mirror of
https://github.com/DBD-SQLite/DBD-SQLite
synced 2025-06-08 06:38:12 -04:00
explained finish and rollback issue
This commit is contained in:
parent
b4220250ce
commit
9367bd61a6
1 changed files with 28 additions and 0 deletions
|
@ -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>
|
(non-deferred) transaction. See L<http://sqlite.org/lockingv3.html>
|
||||||
for locking details.
|
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
|
=head2 Processing Multiple Statements At A Time
|
||||||
|
|
||||||
L<DBI>'s statement handle is not supposed to process multiple
|
L<DBI>'s statement handle is not supposed to process multiple
|
||||||
|
|
Loading…
Add table
Reference in a new issue