What I need to do is load an sqlite3 database from the disk into memory, work with it, and when the script exits save the in-memory database to the disk. How would I go about doing this? Thanks!
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
All you need to do is
connectto the database – you can do anything you want to with it then.If you need to be able to run a series of commands and roll them all back if one does not succeed you should use a transaction.
If you need to make a copy of the existing database, make alterations to it and then save it somewhere else only if the alterations succeed then you can do one of the following things:
ATTATCH DATABASEcommand to attach the existing database to the new in-memory database. Once you have copied all of the data over from the existing database into the in-memory database and transformed it you can attach a new database and copy everything over again.sqlite3‘sConnection.iterdumpto get the contents of the tables as a SQL script which you can then pass tosqlite3.Cursor.executescriptas this answer suggests (using either an in-memory or an on-disk connection string for your new database).