sqlite setting serial mode, ios4 practice:
sqlite3 * database;
sqlite3_config (SQLITE_CONFIG_SERIALIZED);
if (sqlite3_open ([dataPath UTF8String], & database) == SQLITE_OK) {
...
}
Or:
sqlite3 * database;
if (sqlite3_open_v2 ([dataPath UTF8String], & database, SQLITE_OPEN_FULLMUTEX, NULL) == SQLITE_OK) {
...
}
But on ios5.0.1 test is unsuccessful, the online search to others experiencing this problem:
- (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;
}
Output:
sqlite3 lib version: 3.7.7
setting sqlite thread safe mode to serialized failed return code:!!! 21
Database Successfully Opened :)
I do not know how to solve this problem?
Reply:
Why not open too sqlite library
Reply:
By
sqlite3_open_v2 ([dataPath UTF8String], & database, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL);
Nor suspected iphone5 fixed sqlite is a multi-threaded mode.
Upstairs proposed sqlite library with open source, I do not know where? In addition, program compatibility influential?
No comments:
Post a Comment