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 error: 'database table is locked'

Hello

I am getting the following error when trying to insert a row into my database:

SQLite error: 'database table is locked'

Sometimes this works, sometimes i get that error.

The table is called 'function' and i had an instance of it opened, so I closed it right before i call the insert, but I still get the locking problem.

How can i fix this?

Thanks!

Tjeu

— asked May 12th 2011 by Tjeu Vdw
  • error
  • locked
  • sqlite
  • table
0 Comments

1 Answer

  • Found the error, I had an open connection to the database on the previous page. When I closed that it was fixed.

    — answered May 12th 2011 by Tjeu Vdw
    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
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.