我正在使用这种方法。如果sql中有错误,则回滚仅发生在asset_group的第一个id上。其余的ID被忽略。我是否正确地做?perl dbi回滚不起作用
my $sql = "sql batch that update and insert depending on the condition";
$dbh->{RaiseError} = 1;
$dbh->{PrintError} = 0;
$dbh->{AutoCommit} = 0;
my $sth = $dbh->prepare($sql);
my @error =();
my $num = 0;
foreach my $id (@asset_group) {
next if ($id eq '');
eval {
$sth->bind_param(1, $id);
$sth->bind_param(2, $vars{'other_id'});
$sth->execute();
};
if ([email protected]) {
$dbh->rollback();
push @error, [email protected]
} else {
$dbh->commit();
}
}
你是什么意思“其余的ID被忽略?” – cam 2010-09-10 16:47:22
即使您关闭了AutoCommit,您可能也希望使用'BEGIN'和'END/COMMIT/ROLLBACK'明确设置事务。你正在使用哪些DBMS? – vol7ron 2010-09-10 17:27:45
小心,提交也会失败。 – bohica 2010-09-13 08:40:46