I am making an app with many database operations. Since SQLite caches data, in my applicationDidReceiveMemoryWarning method, I am closing the database and opening it again to delete the cached data.
When the do this, I get this error *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error: failed to open database with message 'not an error'.'
Here's the code I am using to close the database and open again where database is of type 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));
}
Can someone please tell me how to avoid this or what I am doing wrong?
Thanks