开发者

can't execute '.read create.sql'

This might 开发者_StackOverflowbe an obvious error but I'm trying to create a database within python from a script I've already created.

conn = sqlite3.connect('testDB')
c = conn.cursor()
c.execute('.read create.sql')

This gives an error "sqlite3.OperationalError: near ".": syntax error"

If I do the same thing at the sqlite3 cmd line it works fine

[me@myPC ~]$ sqlite3 testDB
SQLite version 3.3.6
Enter ".help" for instructions
sqlite> .read create.sql 
sqlite> 

It seems that any commands that start with a . give me problems.


just pass the content of the file to the .execute method:

conn = sqlite3.connect('testDB')
c = conn.cursor()
SQL = open('create.sql').read()
c.executescript(SQL)


I would suppose that commands starting with . are for the CLI client itself, not for the backend.

So you have no chance to do so and would have to do file reading and executing the queries by yourself, i.e. in Python.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜