jangoslackgit / sqlite4java

Automatically exported from code.google.com/p/sqlite4java
0 stars 0 forks source link

Patch to support the Unlock Notify feature for shared-cache mode: blocking prepare and step #36

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I've just begun to investigate using sqlite4java as a database backend for a 
web application.

I noticed in shared cache mode that I was getting a lot SQLITE_LOCKED errors.

I realized I needed sqlite3_unlock_notify() to implement blocking prepare() and 
step() and that sqlite4java hadn't implemented it yet.

So here's a patch for it!

I implemented it based on the documentation/code presented at 
http://www.sqlite.org/unlock_notify.html.

Here's how to enable blocking prepare() and step() (I added Javadoc documention 
too):

SQLiteConnection db = new SQLiteConnection(new File("test.db"));

// must be in shared cache mode to use unlock notify blocking
db.openV2(SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_SHAREDCACHE);

// call setBlocking(true) to turn on blocking of prepare() and step()
db.setBlocking(true);

// prepare() and step() will now attempt to block when locked in accordance 
with sqlite3_unlock_notify() documentation

I have tested on my web application in a test environment and I no longer get 
the SQLITE_LOCKED (or SQLITE_LOCKED_SHARECACHE) errors so it's looking good, 
but granted it hasn't been battle-tested yet in any kind of high-traffic 
production environment.

It's my hope you can merge this into the mainline after reviewing it.

Original issue reported on code.google.com by bko...@gmail.com on 22 Sep 2011 at 9:39

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the patch! We'll review it and possibly merge it next time we have 
an iteration on sqlite4java.

Cheers
Igor

Original comment by ser...@gmail.com on 22 Sep 2011 at 10:12