Hey Everybody. I'm trying to puzzle out how you can copy a disk based sqlite table to some memory database in python.I understand the schema on the table. Can there be any good way to do that?
this code is much more general but maybe it can benefit you:
import 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)
EDIT : to get your specify table you can easily alternation in the for loop such as this:
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
Browse the SQLite Backup API. The example is within C, but this will demonstrate what it is done effectively.