In-memory sqlite database to blob?

287 views
Skip to first unread message

thatsanice...@mac.com

unread,
Mar 4, 2011, 4:50:46 PM3/4/11
to sqlal...@googlegroups.com
Hi,

I'd like to write a script that creates an in-memory SQLite database via SQLAlchemy, but when I've finished with it I'd like to upload it as a file to a server, preferably without ever creating a temporary file on the client side. Is this possible?

Cheers,
Demitri

Michael Bayer

unread,
Mar 4, 2011, 5:15:28 PM3/4/11
to sqlal...@googlegroups.com
you can ATTACH the memory database to a file and then transfer tables using insert-from-select. Don't think there's a way to go straight to a stream, though.

> --
> You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>

A.M.

unread,
Mar 4, 2011, 5:26:15 PM3/4/11
to sqlal...@googlegroups.com

On Mar 4, 2011, at 4:50 PM, thatsanice...@mac.com wrote:

> Hi,
>
> I'd like to write a script that creates an in-memory SQLite database via SQLAlchemy, but when I've finished with it I'd like to upload it as a file to a server, preferably without ever creating a temporary file on the client side. Is this possible?

It is possible but potentially difficult. You could accomplish this by using the backup facility (sqlite3_backup_*) to push the in-memory database to the remote location, perhaps over a network-mounted file share. (http://www.sqlite.org/backup.html)

It would likely be easier to use iterdump in pysqlite to generate a database dump and push the SQL dump text to a server.

If you are trying to avoid hitting the disk, perhaps you can create the sqlite db on an in-memory filesystem. Then you could use normal filesystem operations to manipulate the resultant database.

In any case, SQLAlchemy won't be directly helpful here.

Cheers,
M


thatsanice...@mac.com

unread,
Mar 4, 2011, 6:17:06 PM3/4/11
to sqlal...@googlegroups.com

Thanks for the pointers. I'l probably just write it to a file initially to keep it simple!

Cheers,
Demitri

Reply all
Reply to author
Forward
0 new messages