Jyotsna Kadam
Jyotsna Kadam

Reputation: 213

Database is locked when tried to insert values in table?

I am creating a database for my app. I am successfully able to create the table also able to insert the value in that table. After I terminate my app, again when I launch the app & tried to insert some new values in it, it gives errorString as "Database is locked". Here is my code

if (sqlite3_open([path UTF8String], &database) == SQLITE_OK)
{
sqlStmt = [ [ NSString stringWithFormat:@"Insert into ePubTable values ( '%@') ; " ,ePubTitle] cStringUsingEncoding:NSUTF8StringEncoding ] ;

int retVal = sqlite3_exec ( database,sqlStmt,NULL,NULL, & errString );
if(retVal==0)
printf("Data inserted");
}

sqlite3_close(database);

I am not able to understand why databse get locked, where I am making mistake.
Please help me out this. Thank in advance.

Upvotes: 1

Views: 3205

Answers (2)

Jyotsna Kadam
Jyotsna Kadam

Reputation: 213

I got the proper solution on this database locked error. Whenever we are updating or selecting any value from database, we need to finalize the statement before closing the database else it locked your database. Syntax is as follows:

sqlite3_finalize(statement);

The bellow link help me a lot http://iphoneramble.blogspot.com/2009/07/sqlite-and-database-is-locked.html

Upvotes: 6

Kazzar
Kazzar

Reputation: 1442

the database must be copy from main bundle to documents folder to write or the database are set read-only

sorry bad english, i'm italian

Upvotes: 0

Related Questions