python的sqlite3.executemany:在单个事务中更改表?锁定错误

时间:2013-06-08 11:51:24

标签: sqlite autocommit executemany

我有一个应用程序,我在任何地方使用sqlite3的自动提交功能,通常可以正常工作。该应用程序包括数据库方案更新程序。

基本上它只是每个版本升级的一组SQL命令,应该在单个事务中调用。我使用.executemany()调用实现了这一点,直到现在。现在是第一次,我想用这个方法改变表描述(我做了一个简短的例子,因为原始表格相当大):

想想

-- the Table in the current Version:
table: foo (foo_id INTEGER PRIMARY KEY, quantity INTEGER, 
            single_price REAL, all_price REAL)
-- where I want to end:
table: foo (foo_id INTEGER PRIMARY KEY, quantity INTEGER, 
            single_price REAL, total_price REAL)
(so renaming the 4th column)

我不是在谈论索引,没有问题也是如此:)

我尝试在单个executemany()中运行的是:

ALTER TABLE foo RENAME TO foo_PREv2;
CREATE TABLE foo (foo_id INTEGER PRIMARY KEY, quantity INTEGER, 
            single_price REAL, total_price REAL);
INSERT INTO foo (foo_id, quantity, 
            single_price, total_price)
SELECT foo_id, quantity, 
            single_price, all_price
FROM foo_PREv2;
DROP TABLE foo_PREv2; -- <<<--- here it fails with a database locked error

即使我将DROP移动到第二个executemany()调用它也不起作用。我必须在我可以DROP之前重新启动我的应用程序。

据我所知,executemany()为我处理BEGIN TRANSACTION ... COMMIT的东西。 我错过了什么?

提前致谢, 王问候, 弗洛里安。

0 个答案:

没有答案