Problem with sqlite delete on iPhone

In my iPhone application, I am trying to delete a row from a SQLite database. After executing the delete statement, the line seems to be deleted correctly, but after restarting the application, the line still exists. I use code punch to delete a record. Any idea what could be the problem?

NSString *deleteSQL = [NSString stringWithFormat:@"DELETE FROM table1 WHERE actId=%d", actId];

char *errorMsg;

if (database == nil) {
    NSLog(@"ERROR db not initialized but trying to delete record!!!");
}else{
    if (sqlite3_exec(database, [deleteSQL UTF8String], NULL, NULL, &errorMsg) != SQLITE_OK){
        NSAssert1(0, @"Error updating tables: %s", errorMsg);
        sqlite3_free(errorMsg);
        return NO;
    }   
}

NSLog([NSString stringWithFormat:@"DELETE Successful"]);
+3
source share
1 answer

I solved this problem. Although I do not quite understand all the details. The problem was that in my "boot code" I forgot to call sqlite3_finalize for statements. I don’t know why, but it affected some future insertion and deletion. Adding sqlite3_finalize to the data loading method solved the problem.

+3

Source: https://habr.com/ru/post/1710981/


All Articles