In my app, I am trying to delete one record from an sqlite db. I use the following code in my DAO to delete. it is working with all other records expect specific one, I can't delete it eventhough the delete statement is executed successfully, I tried every thing but still can't figure out what special about this record (sqlite3_changes return 0 for this record while for others it returns 1 as expected). I am verifying it is not deleted by selecting from the table, I always find it there.
I tried to delete it from command line (sqlite on mac), still I can't delete it. Appreciate the help as I am really desperate here.
sqlite3_stmt *deleteVideoStmt = nil;
const char *sql = "delete from video where videoID = ?";
if(sqlite3_prepare_v2([DBUtil db], sql, -1, &deleteVideoStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating delete video statement. '%s'", sqlite3_errmsg([DBUtil db]));
sqlite3_bind_text(deleteVideoStmt, 1, [v.videoId UTF8String], -1, SQLITE_TRANSIENT);
double t = CFAbsoluteTimeGetCurrent();
/*
if (sqlite3_exec([DBUtil db], "BEGIN IMMEDIATE TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) {
NSLog(@"couldn't begin transacton!!! %s",sqlite3_errmsg([DBUtil db]));
}
*/
int result = sqlite3_step(stmt);
if(SQLITE_DONE != result){
NSLog(@"Error while executing video stmt. '%s'", sqlite3_errmsg([DBUtil db]));
sqlite3_finalize(stmt);
return NO;
}else{
NSLog(@"Update stmt executed successfully. in %ld ms",lroundf(((CFAbsoluteTimeGetCurrent()-t)*1000)));
/*
if (sqlite3_exec([DBUtil db], "COMMIT TRANSACTION", NULL, NULL, NULL) != SQLITE_OK) {
NSLog(@"couldn't commit transacton!!! %s",sqlite3_errmsg([DBUtil db]));
}
*/
NSLog(@"number of rows affected = %d", sqlite3_changes([DBUtil db]));
return YES;
}