mardi 20 janvier 2015

iOS SQLite3 database is locked



  1. I've got a JSON file which contains more than 2000 arrays, and in each array there may have an array with 5 strings.




  2. I'm running two for() loops in one function, so I think the 2ed one will be run after the 1st one is done?


    and it sometimes appears the following(random data error appear):



    database is locked



    when I'm executing



    INSERT INTO problemTags(problem_IDIndex)VALUES('93E')





And I use the code below to execute my SQL statement



+ (void)execSqliteWithSQL:(NSString *)sql{
sqlite3 *sqlite = nil;
int openResult = sqlite3_open([DBPath UTF8String], &sqlite);
if(openResult != SQLITE_OK){
NSLog(@"open DB error");
}
char *error;
int execResult = sqlite3_exec(sqlite, [sql UTF8String], nil, nil, &error);
if(execResult != SQLITE_OK){
NSString *errorString = [NSString stringWithFormat:@"\n execResult error=>\n %s \n SQL:\n%@\n",error,sql];
NSLog(@"%@",errorString);
}
sqlite3_close(sqlite);
}




I'm thinking about the reason to this issue is that when I'm running the for loop, it sends several SQL statement to the execSqliteWithSQL function and when it can't run fast enough the data base would be closed?


Aucun commentaire:

Enregistrer un commentaire