I am experiencing issues with deleting a row / data record from an SQLite database located on the iPhone. I followed advice given in the following post, but the result code from SQLite is 5. From the SQLite reference manual, 5 means:
SQLITE_BUSY 5 /* The database file is locked */
Has anyone else come across this problem or have any ideas why this would be the case?
Here is an excerpt of my code (dbrc is set to 5):
NSString *retrievedContactID = [archivedContact objectForKey:@"contact_id"];
sqlite3 *database = [FollowUPAppDelegate checkAndCreateDatabase];
NSString *deleteSQL = [NSString stringWithFormat:@"DELETE FROM Contacts WHERE contact_id = %@", retrievedContactID];
const char *delete_stmt = [deleteSQL UTF8String];
sqlite3_stmt *compiledStatement;
int dbrc; //database return code
dbrc = sqlite3_prepare_v2(database, delete_stmt, -1, &compiledStatement, NULL);
dbrc = sqlite3_step(compiledStatement);
sqlite3_finalize(compiledStatement);
compiledStatement = NULL;
if (dbrc != 101) { //anything except 101 (SQLITE_DONE for delete, *not* SQLITE_OK)
NSLog(@"Error deleting contact from database: result code %i", dbrc);
return;
}
else {
NSLog(@"deleted the customer from datasets");
}
sqlite3_close(database);