"how to copy a sqlite table from a disk database to a memory database in python? " Code Answer

4

this code is more general but maybe it can help 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 : for getting your specify table you can just change in the for loop like 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
By kacalapy on September 20 2022

Answers related to “how to copy a sqlite table from a disk database to a memory database in python? ”

Only authorized users can answer the Search term. Please sign in first, or register a free account.