I have written a delete query in applicationDidEnterBackground Appdelegate METHOD. But when i stop the simulator it does not delete the database table. I want to delete the database tables when the app enters in the background or when the app terminates. Here is my applicationDidEnterBackground METHOD for delete table query.
- (void)applicationDidEnterBackground:(UIApplication *)application {
sqlite3 *database;
NSArray * dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* docsDir = [dirPaths objectAtIndex:0];
NSString * databasePath = [docsDir stringByAppendingPathComponent:@"sssw.sqlite"];
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
NSString *sqlStatement_userInfo =[NSString stringWithFormat:@"DELETE * from SHOPDATA"];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, [sqlStatement_userInfo UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK)
{
NSLog(@"table deleted");
}
else
{
NSLog(@"Unable to delete table");
}
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
}
please tell me what should i do and what am i doing wrong here. Any help will be appreciated.
