2 separate connections to the same in-memory DB?

40 views
Skip to first unread message

Ashwin Jayaprakash

unread,
May 3, 2012, 8:16:48 PM5/3/12
to sqlit...@googlegroups.com
Hi, the docs say that multiple threads can open separate connections to the same DB.

But if my DB is purely in-memory - new SQLiteConnection().open(true), it doesn't look like I can open 2 connections to it, can I?

Also, is SQLiteQueue the way to do multi-statement transactions? I didn't see separate begin/commit methods.

Thanks for making the library available,
Ashwin.

Igor Sereda

unread,
May 4, 2012, 3:32:12 AM5/4/12
to sqlite4java
Ashwin, thanks

Yes, you can't connect to an in-memory database with several
connections. This is a limitation of SQLite (which uses file locks to
sync between several connections to the same database).

SQLiteQueue is a utility class for organizing multi-threaded access to
the same SQLiteConnection. It is not related to multi-statement
transactions in particular (although you are expected to end a
transaction at the end of SQLiteJob, or override jobFinished()).

To begin or end a transaction in SQLite, you execute SQL:
connection.exec("BEGIN") and connection.exec("COMMIT")

Hope this helps
Igor


On May 4, 4:16 am, Ashwin Jayaprakash <ashwin.jayaprak...@gmail.com>
wrote:

Ashwin Jayaprakash

unread,
May 4, 2012, 1:13:14 PM5/4/12
to sqlit...@googlegroups.com
exec("COMMIT") sounds obvious now :) It would be helpful to add that snippet to your Wiki.

Thanks!
Reply all
Reply to author
Forward
0 new messages