我有一个现有的sqlite3db文件,我需要在其上进行一些大量的计算.从文件中进行计算是非常缓慢的,因为文件不大(〜10 MB),所以将它加载到内存中应该没有问题.
是否有Pythonic方法将现有文件加载到内存中以加快计算速度?
在不安装额外模块的情况下,如何使用SQLite 备份 API将内存数据库备份到磁盘数据库?我已经成功地执行了磁盘到磁盘备份,但是将已经存在的内存连接传递给sqlite3_backup_init函数似乎是问题所在。
我的玩具示例,改编自https://gist.github.com/achimnol/3021995并减少到最低限度,如下:
import sqlite3
import ctypes
# Create a junk in-memory database
sourceconn = sqlite3.connect(':memory:')
cursor = sourceconn.cursor()
cursor.execute('''CREATE TABLE stocks
(date text, trans text, symbol text, qty real, price real)''')
cursor.execute("INSERT INTO stocks VALUES ('2006-01-05','BUY','RHAT',100,35.14)")
sourceconn.commit()
target = r'C:\data\sqlite\target.db'
dllpath = u'C:\\Python27\DLLs\\sqlite3.dll'
# Constants from the SQLite 3 API defining various return codes of state.
SQLITE_OK = 0
SQLITE_ERROR = 1
SQLITE_BUSY = 5
SQLITE_LOCKED = 6
SQLITE_OPEN_READONLY = 1
SQLITE_OPEN_READWRITE …Run Code Online (Sandbox Code Playgroud)