隨着iOS 5的發佈,我們在爲sqlite數據庫設置序列化選項時出現越來越多的錯誤(所以它的保存用於多線程)。我們正在sqlite3_config上獲取SQLITE_MISUSE錯誤代碼。有人注意到這種奇怪的行爲?有人知道我能如何解決這個問題嗎?它在以前的iOS版本上工作得非常好。設置sqlite配置SQLITE_CONFIG_SERIALIZED返回iOS 5上的SQLITE_MISUSE
這裏是代碼:
- (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;
}
,這是輸出:
sqlite3 lib version: 3.7.7
setting sqlite thread safe mode to serialized failed!!! return code: 21
Database Successfully Opened :)
我遇到了同樣的問題,並且在sqlite3_config()沒有解決問題之後調用sqlite3_initialize()。對config()的調用仍然會返回SQLITE_MISUSE(代碼21)。任何人都能弄清楚這一點? – 2011-10-28 20:47:25