简体   繁体   中英

How do I use execute, rather than execute script in SQLite3?

In the following code, scheduling.sql is executing properly, while dummy.sql is not. I'm not getting an error message. It just doesn't appear to be doing anything. For dummy.sql, I prefer to use execute, rather than executescript, so I can pass it some parameters. What am I doing wrong here?

db = sqlite3.connect(':memory:')
cursor = db.cursor()

with open('scheduling.sql', 'r') as sql_file:
    sql_script = sql_file.read()
cursor.executescript(sql_script)

with open('dummy.sql', 'r') as sql_file:
    sql_script = sql_file.read()
fetch=cursor.fetchone()
while fetch:
    cursor.execute(fetch)
    fetch=cursor.fetchone()

It never executes dummy.sql . What is fetch after fetch=cursor.fetchone() executes ? Guess is something falsey. fetch... comes after execute.... .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM