[Fixed]-Python and sqlite3 – importing and exporting databases

24👍

sql = f.read() # watch out for built-in `str`
cur.executescript(sql)

Documentation.

4👍

Try using

con.executescript(str)

Documentation

Connection.executescript(sql_script)
    This is a nonstandard shortcut that creates an intermediate cursor object
    by calling the cursor method, then calls the cursor’s executescript
    method with the parameters given.

Or create the cursor first

import sqlite3

con = sqlite3.connect('../sqlite.db')
f = open('../dump.sql','r')
str = f.read()
cur = con.cursor()
cur.execute(str)

Leave a comment