SQL删除似乎不起作用
请帮忙:-) 以下代码应该删除一条记录。它似乎执行正常,没有错误消息,并且 NSLog 显示“记录已删除”消息。但该记录并未被删除。我用终端查看了一下,确实删除的记录还在。令人费解的部分是,我有非常相似的代码来添加和计算记录,而且它们似乎都可以工作...我不是 SQL 专家,所以我希望这群人中的专家能够看到该错误。
谢谢
(void) deleteRecord
{
const char *dbpath = [databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &wfDataBase) == SQLITE_OK)
{
NSLog(@"About to Delete Record %d",currentID);
NSString *querySQL = [NSString stringWithFormat: @"DELETE from wfDataBase WHERE ID = %d", currentID];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(wfDataBase, query_stmt, -1, &statement, NULL) == SQLITE_OK)
l_status.text = @"Record Deleted";
else
l_status.text = @"Can't Delete";
sqlite3_finalize(statement);
sqlite3_close(wfDataBase);
}
}
Help please :-)
Following code is supposed to delete a record. It seems to execute OK, no error message and the NSLog shows "Record Deleted" message. However the record is not deleted. I have used Terminal to check and indeed the deleted record is still there. The puzzling part is that I have very similar code to add and count records and they all seem to work... I am not an SQL expert, so I am hoping that an expert in this crowd can see the error.
Thanks
(void) deleteRecord
{
const char *dbpath = [databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &wfDataBase) == SQLITE_OK)
{
NSLog(@"About to Delete Record %d",currentID);
NSString *querySQL = [NSString stringWithFormat: @"DELETE from wfDataBase WHERE ID = %d", currentID];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(wfDataBase, query_stmt, -1, &statement, NULL) == SQLITE_OK)
l_status.text = @"Record Deleted";
else
l_status.text = @"Can't Delete";
sqlite3_finalize(statement);
sqlite3_close(wfDataBase);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定您已评估 (
sqlite3_step(statement )
) 已编译语句 (sqlite3_prepare_v2(wfDataBase, query_stmt, -1, &statement, NULL)
) 在销毁之前(sqlite3_finalize(语句)
)?注意:我不是 SQLite 专家(事实上我对 SQLite 一无所知),但我想这就是问题的原因。
Are you sure you have evaluated (
sqlite3_step(statement )
) the compiled statement (sqlite3_prepare_v2(wfDataBase, query_stmt, -1, &statement, NULL)
) before destroying it (sqlite3_finalize(statement)
)?Note: I'm not an expert on SQLite (indeed I don't know anything about SQLite) but I guess this is the cause of the problem.