如何将现有的数据库文件加载到Python sqlite3中的内存中?

如何将现有的数据库文件加载到Python sqlite3中的内存中?,第1张

如何将现有的数据库文件加载到Python sqlite3中的内存中?

这是我为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


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5616504.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存