views:

1581

answers:

1

Hi,

In my iPhone app, I'm trying to delete a row from an SQLite database. After the delete statement is executed the row seems to be deleted correctly, but after I restart the application the row is still there. I'm using the code blow to delete the 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"]);
A: 

I've solved this problem. Although I don't understand exactly all the details. The problem was the in my 'loading code' I forgot to call sqlite3_finalize for the statements. Not sure why but this influenced somehow future inserts and deletes. Adding sqlite3_finalize to the data loading method solved the problem.

levi