doglas
doglas

Reputation: 115

python + Sqlite: How to save the changes into a new db file?

After the changes were made to a db file, I want to save the data into a new db file.

import sqlite3
conn = sqlite3.connect('Original.db')
cur = conn.cursor()
# make changes here.
conn.close() #Close without save

connA = sqlite3.connect('NewFile.db')
connA.commit() # Here is my problem. How to save the changed data into this new file?

Thanks for your help!

UPDATE: My db file is huge. If I make a copy of it at the beginning, it takes to much time. I would rather let it run after I made the changes, to save the starting time.

Upvotes: 1

Views: 2243

Answers (1)

Zixian Cai
Zixian Cai

Reputation: 955

Each databases have their own table, data, schema, etc. If you just commit those changes on a brand new file, errors will occur.

If you want to save the changed data into a new database, you can make a copy of current database file by using shutil.copyfile and then operate on the new database.

Upvotes: 2

Related Questions