Reputation: 3107
I am working on sqlite and inserting value in database but I am getting Database is locked error Here is my code
-(void)addmoreDATADetails
{
if(addStmt == nil)
{
const char *sql = "insert into moreBankroll(MoreName) Values(?)";
if(sqlite3_prepare_v2(database, sql, -1, &addStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating add statement. '%s'", sqlite3_errmsg(database));
}
sqlite3_bind_text(addStmt, 1, [moreName UTF8String], -1, SQLITE_TRANSIENT);
if(SQLITE_DONE != sqlite3_step(addStmt))
{
NSAssert1(0, @"Error while inserting data. '%s'", sqlite3_errmsg(database));
}
else
{
moreId=sqlite3_last_insert_rowid(database);
}
sqlite3_reset(addStmt);
}
IF I am adding
XYZAppDelegate *appDelegate = (XYZAppDelegate *)[UIApplication sharedApplication].delegate;
dbPath =[appDelegate getDBPath];
if (sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK)
this in above function it is saying that no Such table moreBankroll
This code is working fine in another project but not in my project , please help
Upvotes: 1
Views: 1447
Reputation: 6587
Database lock error comes only when you are creating some database operation and inside it you start with another database operation. Try separating out two operations if there are. Reason for this is that every-time it create a transaction and so you get this error.
Hope, this description helps you.
Upvotes: 1
Reputation: 1116
Your DB is locked because other thread/operation is performing a query to it. Using SQLite in iPhone is very painful the way you do it, maybe you should consider rewriting it with use of FMDB wrapper - it handles all locks by itself and query the data. https://github.com/ccgus/fmdb
Upvotes: 2