参见英文答案 >
How to load existing db file to memory in Python sqlite3?6个答案如何将基于磁盘的sqlite表复制到python中的内存数据库?我知道表的模式。
这个代码更一般,但也许它可以帮助你:
原文链接:https://www.f2er.com/sqlite/198077.htmlimport sqlite3 new_db = sqlite3.connect(':memory:') # create a memory database old_db = sqlite3.connect('test.db') query = "".join(line for line in old_db.iterdump()) # Dump old database in the new one. new_db.executescript(query)
编辑:为了获得你的指定表,你可以只是在for循环中这样改变:
name_table = "test_table" # name of the table that you want to get. for line in old_db.iterdump(): if name_table in line: query = line break