为什么 $dbh->do('VACUUM') 使用 Perl 的 DBD::SQLite 会失败?
我想在 Perl 下的 SQLite 数据库上的某个时间执行 VACUUM ,但它总是说
DBD::SQLite::db 失败:无法从事务内进行 VACUUM
那么我该如何执行此操作?
my %attr = ( RaiseError => 0, PrintError => 1, AutoCommit => 0 );
my $dbh = DBI->connect('dbi:SQLite:dbname='.$file'','',\%attr)
or die $DBI::errstr;
我正在使用 AutoCommit => 0 。并且错误发生在:
$dbh->do('DELETE FROM soap');
$dbh->do('DELETE FROM result');
$dbh->commit;
$dbh->do('VACUUM');
I want to do VACUUM
at a certain time on a SQLite database under Perl, but it always says
DBD::SQLite::db do failed: cannot VACUUM from within a transaction
So how do I do this?
my %attr = ( RaiseError => 0, PrintError => 1, AutoCommit => 0 );
my $dbh = DBI->connect('dbi:SQLite:dbname='.$file'','',\%attr)
or die $DBI::errstr;
I am using AutoCommit => 0
. And the error happens while:
$dbh->do('DELETE FROM soap');
$dbh->do('DELETE FROM result');
$dbh->commit;
$dbh->do('VACUUM');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您有 AutoCommit => 0 在 connect 调用中,因为以下方法有效:
您不必放弃事务即可
VACUUM
:您可以使用以下内容,以便AutoCommit
code> 为VACUUM
打开,并且在VACUUM
之后,AutoCommit
状态将恢复到原来的状态。如果您未设置 RaiseError,请添加错误检查。称之为:
I am assuming you have
AutoCommit => 0
in the connect call because the following works:You don't have to give up on transactions to be able to
VACUUM
: You can use the following so thatAutoCommit
is turned on forVACUUM
and after theVACUUM
theAutoCommit
state is reverted back to whatever it was. Add error checking to taste if you do not setRaiseError
.Call it:
默认情况下,DBI 已打开自动提交。连接期间将其关闭:
The DBI has autocommit turned on by default. Turn it off during the connect: