I'm trying to update the data in my SQLite database on iPhone. I'd like to开发者_高级运维 drop and recreate the table (it's not big), or just truncate it, but I can't seem to do that.
Running
char *errorMsg;
NSString *truncSQL = @"TRUNCATE TABLE GAMES;";
if (sqlite3_exec(database, [truncSQL UTF8String], NULL, NULL, &errorMsg) != SQLITE_OK){
NSLog(@"Error: %s", errorMsg);
NSLog(truncSQL);
}
gives me a database is locked error. There shouldn't be any active reads or anything from the database. How do I get it to do this?
Thanks!
Sometimes older versions of SQLite will give a "database locked" error if the file [DATABASE].journal
exists. If you are sure nothing is accessing the database, try deleting that file.
Whoops, that was stupid.
Figured it out!
Accidentally missed a sqlite3_finalize(); statement somewhere!
精彩评论