Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Sqlite locking problem

I'm getting a locking error on a query. Looks like an update is locking that table.

[ERROR] Error occurred calling next on a PLSqliteResultSet. SQLite error: 'database table is locked' for 'UPDATE …[rest of update statement]'

The update statement is running as background process using setInterval. I tried to unblock the reading with db.execute('PRAGMA read_uncommitted=true') but that didn't work.

Anyone got any ideas?

— asked August 4th 2010 by Curtis Olson
  • database
  • db
  • lock
  • sqlite
0 Comments

5 Answers

  • Accepted Answer

    Found it! I had an SQL function where I forgot to call close() after the execute(…). Once I closed it, the error went away. Hopefully that's all it is (was?) for you as well.

    — answered August 10th 2010 by Mike Dosey
    permalink
    1 Comment
    • The database file will lock when a write action is being performed such as a insert, delete or update. You'll need to ensure that you close and/or end the transaction of any insert/delete/update queries to prevent a locking run-time error. It's also worth noting that currently a try-catch around the query execution will not catch any SQL error notice.

      Docs: "while the database supports concurrent read access, only one user may write to it at a time. This is because a filesystem lock is placed on the file during write operations. This is an important point to bear in mind with multi-threaded applications" – http://wiki.appcelerator.org/display/guides/Working+with+Local+Data

      — commented September 13th 2011 by Dan Boorn
  • Same issue occured…

    one more tip is to close SQLite browser when u launch application

    — answered August 13th 2010 by Varun Atluri
    permalink
    1 Comment
    • I had the same problem and was getting the error: [ERROR] Error occurred calling next on a PLSqliteResultSet. SQLite error: 'database table is locked' for

      I'm using SQLite Database Browser 2.0, after closing it the error went away.

      — commented February 22nd 2012 by Hugo Costa
  • The database file will lock when a write action is being performed such as a insert, delete or update. You'll need to ensure that you close and/or end the transaction of any insert/delete/update queries to prevent a locking run-time error. It's also worth noting that currently a try-catch around the query execution will not catch any SQL error notice.

    Docs: "while the database supports concurrent read access, only one user may write to it at a time. This is because a filesystem lock is placed on the file during write operations. This is an important point to bear in mind with multi-threaded applications" – http://wiki.appcelerator.org/display/guides/Working+with+Local+Data

    — answered September 13th 2011 by Dan Boorn
    permalink
    0 Comments
  • I have a similar problem - an Update statement running in the background with setInterval, which results in a 'database table is locked' error. If anyone has a guess, it'd be appreciated.

    — answered August 10th 2010 by Mike Dosey
    permalink
    1 Comment
    • I found a select statement that wasn't being closed. After fixing that, my problem seems to have went away. Or at least I haven't seen the error in a since I found that. The problem was intermittent before so I can't be 100% sure.

      — commented August 10th 2010 by Curtis Olson
  • database may be locked due to running the titanium project again and again.This occurs
    while copying resources.Since the resources are huge ,it takes time to run on the
    emulater or device.so better keep the images or other resources in sdcard.

    — answered March 1st 2012 by Vaibhav Saini
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.