1
votes

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

2
That can be any number of things. Another function has probably not released the database.MPelletier
@MPelletier see edited questioniProgrammer
What's the content of dbPath?Phillip Mills
Db path is /Users/Library/Application Support/iPhone Simulator/5.1/Applications/29886D95-C7E7-4D8A-9A14-C9BA63549E19/Documents/PokerDatabase.sqliteiProgrammer
I am having this error when I added foriegn key . but the above table has no reference with foriegn keyiProgrammer

2 Answers

2
votes

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

1
votes

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.