为什么我会在SQLite3脚本中锁定数据库?

时间:2017-11-07 22:09:47

标签: sqlite

我在运行SQLite脚本时遇到错误。

--drop use table before replacing it
DROP TABLE IF EXISTS db.use;

--Create the use table in the saved database
CREATE TABLE db.use AS SELECT * FROM use2; -- this is the line that generates the error: Error: near line 145: database is locked

这两个语句是异步运行还是其他什么?我不明白导致错误的原因,但我想知道它是否与此有关。

有没有办法以锁步方式运行脚本,即非异步?

2 个答案:

答案 0 :(得分:0)

This is how I was running the command: sqlite3 --init script_name.sql dbname.db, and elsewhere in the script I had an ATTACH statement reading the same database dbname.db. Essentially reading the same file twice.

The way I solved this was by executing the script in the sqlite3 shell:

sqlite3> .read script_name.sql

答案 1 :(得分:-2)

您是否尝试在drop语句后添加commit语句? 我认为这将确保在完成drop语句之后运行create table语句。