With the release of iOS 5 we are getting more and more errors when setting the serialized option for the sqlite database (so its save to be used for multithreading). We are getting SQLITE_MISUSE error code on sqlite3_config. Has someone noticed this odd behavior? And does someone know how I can fix this? It works perfectly fine on previous iOS versions.
here is the code:
- (sqlite3 *)getNewDBConnection {
NSLog(@"sqlite3 lib version: %s", sqlite3_libversion());
//sqlite3_config() has to be called before any sqlite3_open calls.
if (sqlite3_threadsafe() > 0) {
int retCode = sqlite3_config(SQLITE_CONFIG_SERIALIZED);
if (retCode == SQLITE_OK) {
NSLog(@"Can now use sqlite on multiple threads, using the same connection");
} else {
NSLog(@"setting sqlite thread safe mode to serialized failed!!! return code: %d", retCode);
}
} else {
NSLog(@"Your SQLite database is not compiled to be threadsafe.");
}
sqlite3 *newDBconnection;
// Open the database
if (sqlite3_open([[self getDatabaseFilePath] UTF8String], &newDBconnection) == SQLITE_OK) {
NSLog(@"Database Successfully Opened :)");
} else {
sqlite3_close(newDBconnection);
NSLog(@"Error in opening database :(");
}
return newDBconnection;
}
and this is the output:
sqlite3 lib version: 3.7.7
setting sqlite thread safe mode to serialized failed!!! return code: 21
Database Successfully Opened :)