我正在使用这种方法。如果 sql 中有错误,则只会对asset_group 的第一个 id 进行回滚。其余的 id 被忽略。我做对了吗?
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 ($@) {
$dbh->rollback();
push @error, $@
} else {
$dbh->commit();
}
}