I am working a project with sqlite.In my project I am inserting ,getting and updating data to the datbase.But some times I am geeting error of database is locked and no such table:tablename.I have checked in my code sqlite3_open,sqlite3_prepare_v2,sqlite3_step,sqlite3_finalize and sqlite3_close. But i am getting Problem.Can any one help Me with it
1 Answers
This error code occurs when you try to do two incompatible things with a database at the same time from the same database connection. For example, if you are in the middle of a SELECT statement and you try to DROP one of the tables being read by the SELECT, you will get an SQLITE_LOCKED error. Here is an example (using Tcl):
db eval {SELECT rowid FROM ex1} {
if {$rowid==10} {
db eval {DROP TABLE ex1} ;# will give SQLITE_LOCKED error
}
}
Note that an SQLITE_LOCKED error is distinct from SQLITE_BUSY (5). SQLITE_BUSY means that another database connection (probably in another process) is using the database in a way that prevents you from using it. SQLITE_LOCKED means the source of contention is internal and comes from the same database connection that received the SQLITE_LOCKED error.
Here are other reasons for getting an SQLITE_LOCKED error:
Trying to CREATE or DROP a table or index while a SELECT statement is still pending.
Sometimes people think they have finished with a SELECT statement because sqlite3_step() has returned SQLITE_DONE. But the SELECT is not really complete until sqlite3_reset() or sqlite3_finalize() have been called.
As of check-in [3902] (2007-05-02 after version 3.3.17) this is now allowed for CREATE statement.
Trying to write to a table while a SELECT is active on that same table.
- As of check-in [3355] (2006-08-16 after version 3.3.7) this is now allowed.
Trying to do two SELECT on the same table at the same time in a
multithread application, if sqlite is not set to do so.fcntl(3, F_SETLK call on DB file fails. This could be caused by an
NFS locking issue, for example. One solution for this issue, is to mv the DB away, and copy it back so that it has a new Inode
value.