SQLite3 connection from StringIO (Python)
I am wondering if anyone knows a way to generate a connection to a SQLite database in python from a StringIO object.
I have a compressed SQLite3 database file and I would like to decompress it using the gzip
library and then connect to it without first making a temp file.
I've looked into the slqite3
library source, but it looks like filename
gets passed all the way through into the C code. Are there any other SQLite3 connection libraries that you could use a file ID for? Or is there some why I can trick the builtin sqlite3
library into thinking that my StringIO (or some other object type) is an actual file?
The Python sqlite3 module cannot open a database from a file number, and even so, using StringIO will not give you a file number (since it does not open a file, it just emulates the Python file
object).
You can use the :memory:
special file name to avoid writing a file to disk, then later write it to disk once you are done with it. This will also make sure the file is optimized for size, and you can opt not to write eg indexes if size is really a big issue.