在我的应用程序中,我试图从sqlite数据库中删除一条记录。我在DAO中使用以下代码删除。它正在处理所有其他记录期望特定的记录,尽管删除语句成功执行,我无法删除它,我尝试了所有的事情,但仍然无法弄清楚这条记录有什么特别之处(sqlite3_changes返回0表示这个记录,而对于其他人,它按预期返回1)。我正在验证它没有从表中选择删除,我总是在那里找到它。
我试图从命令行(mac上的sqlite)删除它,但我仍然无法将其删除。欣赏帮助,因为我真的非常绝望。
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;
}