わいえむねっと

Contents
Categories
Calendar
2009/12
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Monthly Archives
~2000/01
Recent Entries
RSS1.0
Templates
Information
Processed: 0.017 sec
Chashed: -
2009/12/30 Wed
以前書いたモジュールの AutoCommit を手当たり次第に切っていったら自動テストの出力に

Issuing rollback() for database handle being DESTROY'd without explicit disconnect().

とかいうのが混じるようになって ちょと調べたのでメモ。

use DBI;

my $dbh = DBI->connect('dbi:SQLite:dbname=foo.db');
$dbh->{AutoCommit} = 0;
$dbh->do('update foo set bar=1');
$dbh->commit;
$dbh->disconnect;
まず普通に。

use DBI;

my $dbh = DBI->connect('dbi:SQLite:dbname=foo.db');
$dbh->{AutoCommit} = 0;
$dbh->do('update foo set bar=1');
$dbh->commit;
#$dbh->disconnect;
disconnectを省略しても変化なし。

use DBI;

my $dbh = DBI->connect('dbi:SQLite:dbname=foo.db');
$dbh->{AutoCommit} = 0;
$dbh->do('update foo set bar=1');
#$dbh->commit;
$dbh->disconnect;
commitを省略。警告はでない。当然、コミットもされない。

use DBI;

my $dbh = DBI->connect('dbi:SQLite:dbname=foo.db');
$dbh->{AutoCommit} = 0;
$dbh->do('update foo set bar=1');
#$dbh->commit;
#$dbh->disconnect;
両方省略したところで件の警告。

モジュールを眺めたら、select の後の条件分岐で disconnect せずに抜けてる箇所があった。
disconnect の漏れはともかくとして、select でも commit/rollback が必要なものなのか。

use DBI;

my $dbh = DBI->connect('dbi:SQLite:dbname=foo.db');
$dbh->{AutoCommit} = 0;
my $sth = $dbh->prepare('select * from foo');
$sth->execute;
undef $sth;
#$dbh->commit;
#$dbh->disconnect;
これだと警告。

use DBI;

my $dbh = DBI->connect('dbi:SQLite:dbname=foo.db');
$dbh->{AutoCommit} = 0;
my $sth = $dbh->prepare('select * from foo');
$sth->execute;
undef $sth;
$dbh->commit;
#$dbh->disconnect;
警告でない。rollback でも同様。