这是我为flask应用程序编写的代码段:
import sqlite3from io import StringIOdef init_sqlite_db(app): # Read database to tempfile con = sqlite3.connect(app.config['SQLITE_DATAbase']) tempfile = StringIO() for line in con.iterdump(): tempfile.write('%sn' % line) con.close() tempfile.seek(0) # Create a database in memory and import from tempfile app.sqlite = sqlite3.connect(":memory:") app.sqlite.cursor().executescript(tempfile.read()) app.sqlite.commit() app.sqlite.row_factory = sqlite3.Row


