SQL删除似乎不起作用

发布于 2024-10-31 12:22:47 字数 897 浏览 2 评论 0原文

请帮忙:-) 以下代码应该删除一条记录。它似乎执行正常,没有错误消息,并且 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里寻她 2024-11-07 12:22:48

您确定您已评估 (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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文