2

I have a bytestring that holds the contents of a valid sqlite3 database. I have to save this bytestring to a file and call:

conn=sqlite3.connect("FILE_NAME")

I would rather not have to save this string to a file because I already have it in memory. Is there any way to create the connection object without this intermediate step?

Thanks.

This is Python 3.

1
  • 2
    If your version of sqlite was built with support for it, and if the python sqlite bindings provide it, there's sqlite3_deserialize() to get an in-memory database handle. Those are pretty big ifs though. I wouldn't depend on it unless you're using C or C++ and can easily embed the sqlite source directly in your program and compile it with the appropriate option turned on. Commented Apr 26, 2019 at 16:28

1 Answer 1

2

AFAIK you cannot. There are various ways to use a in memory database, either with a memory file system, or with the special database ':memory:'. But in either case, the database is an opaque object that is known only by its Connection object, and you can neither (easily) load or store it.

The best I can imagine with a memory file system is to use it to write the byte string in a memory file, and let sqlite use it. That way nothing has been writen on disk, but you have not really accessed directly the byte string....

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I'll just save it to a file like I have been doing.
That's :memory: with colons on either end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.