perl DBD::ODBC 回滚在启用 AutoCommit 时无效
我目前有一个如下所示的块。因此,我们设置自动提交并执行提交/回滚。现在,在回滚行,我们收到一条错误消息,指出“在启用自动提交的情况下回滚无效”。既然 AutoCommit 确实被 begin_work 禁用了,怎么会发生这种情况呢?这个问题已经很久没有出现了,突然出现。
在进一步调查中,我发现 update_sql1 创建了一个 #temp 表,而 update_sql2、update_sql3、update_sql4 查询相同的 #temp 表,并且因无效的对象名称“#temp”错误而失败。立即控制流到 if($@) ,其中 $dbh->{AutoCommit} 设置为 1。首先,当 update_sql1 确实成功时,为什么 update_sql2 和以后的计数找不到对象 #temp 真的很奇怪。
有什么指点吗?
====
$dbh->db_Main()->begin_work;
eval {
$dbh->do($update_sql1);
$dbh->do($update_sql2);
$dbh->do($update_sql3);
$dbh->do($update_sql4);
$dbh->commit;
1;
}
if ($@) {
$logger->info("inside catch");
$logger->info("autocommit is $dbh->{AutoCommit}");
$dbh->rollback;
}
===
这是完整的错误消息
Issuing rollback() due to DESTROY without explicit disconnect() of DBD::ODBC::db handle ..
rollback ineffective with AutoCommit enabled ...
I am currently having a block like below. So with this we set autocommit off and and do a commit/rollback. Now at the rollback line , we are getting a failure saying that "rollback ineffective with AutoCommit enabled at" . How could this happen since AutoCommit was indeed disabled by the begin_work. This problem was not there for a long time and it is suddenly occuring.
On investigating further , i found that the update_sql1 created a #temp table , and update_sql2,update_sql3,update_sql4 query the same #temp table, and are failing with Invalid object name '#temp' error. Immediately control flows to if($@) where $dbh->{AutoCommit} is set to 1. First of all its really wierd as to why update_sql2 and onwards count not find object #temp , when update_sql1 was indeed successful.
Any pointers ?
====
$dbh->db_Main()->begin_work;
eval {
$dbh->do($update_sql1);
$dbh->do($update_sql2);
$dbh->do($update_sql3);
$dbh->do($update_sql4);
$dbh->commit;
1;
}
if ($@) {
$logger->info("inside catch");
$logger->info("autocommit is $dbh->{AutoCommit}");
$dbh->rollback;
}
===
Here is the full error message
Issuing rollback() due to DESTROY without explicit disconnect() of DBD::ODBC::db handle ..
rollback ineffective with AutoCommit enabled ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在自动提交下,
begin
启动一个事务,该事务会自动提交。您必须关闭自动提交才能获取事务。Under autocommit, the
begin
starts a transaction, which is automatically committed. You have to turn off AutoCommit to get a transaction.