我正在製作一個包含許多數據庫操作的應用程序。由於SQLite緩存數據,在我的applicationDidReceiveMemoryWarning方法中,我正在關閉數據庫並再次打開它以刪除緩存的數據。由於未捕獲異常'NSInternalInconsistencyException'而終止應用程序,原因:'錯誤:未能用消息打開數據庫'沒有錯誤'。'
當做到這一點,我得到這個錯誤
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error: failed to open database with message 'not an error'.'
下面是我使用關閉數據庫並在數據庫類型的sqlite3再次打開代碼* [MySQLInter finalizeStatements]
if(sqlite3_close(database) == SQLITE_OK){
//open again
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"mydb.sql"];
if(sqlite3_open([path UTF8String], &database) != SQLITE_OK){
NSAssert1(0, @"Error: failed to open database with message '%s'.", sqlite3_errmsg(database));
}
}
else{
NSAssert1(0, @"Error: failed to close database on memwarning with message '%s'.", sqlite3_errmsg(database));
}
如何避免這種情況?