无法从 SQLite iPhone 中删除记录

发布于 2024-10-30 17:50:27 字数 1153 浏览 1 评论 0原文

当我在 iPhone 模拟器中运行此代码时,我无法从数据库中删除记录。如果我在 SQLite DB 浏览器中运行此查询,它效果很好。这是我的代码

SQLiteDB *sqliteConnect=[[SQLiteDB alloc] init];
sqlite3 *database;

if(sqlite3_open([sqliteConnect.databasePath UTF8String], &database)==SQLITE_OK)
{   
    sqlite3_stmt *compiledstatement;

    const char *sqlstmt="delete from searchHistory where id = (select min(id) from searchHistory) ";

    if(sqlite3_prepare_v2(database, sqlstmt, -1, &compiledstatement, NULL)==SQLITE_OK)
    {
        sqlite3_step(compiledstatement);

        if(SQLITE_DONE != sqlite3_step(compiledstatement))

            NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(database) );
    }
    NSLog(@"delete DONE");
    sqlite3_finalize(compiledstatement);
}
sqlite3_close(database);

当我使用调试器运行时,我收到以下错误=>

2011-04-08 08:42:34.049 MyApp[1838:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error while creating delete statement => not an error'

SQLiteDB 是我的类,其中包含 init 和 SQLiteDB 的逻辑。 checkAndCopyDB 方法。我的数据库被复制到文档目录中。其他数据库操作工作正常。请帮我。谢谢

When I run this code in iPhone simulator ,I can not delete record from DB . If I run this query in SQLite DB Browser it works well. Here is my code

SQLiteDB *sqliteConnect=[[SQLiteDB alloc] init];
sqlite3 *database;

if(sqlite3_open([sqliteConnect.databasePath UTF8String], &database)==SQLITE_OK)
{   
    sqlite3_stmt *compiledstatement;

    const char *sqlstmt="delete from searchHistory where id = (select min(id) from searchHistory) ";

    if(sqlite3_prepare_v2(database, sqlstmt, -1, &compiledstatement, NULL)==SQLITE_OK)
    {
        sqlite3_step(compiledstatement);

        if(SQLITE_DONE != sqlite3_step(compiledstatement))

            NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(database) );
    }
    NSLog(@"delete DONE");
    sqlite3_finalize(compiledstatement);
}
sqlite3_close(database);

When I run using debugger , I get following error =>

2011-04-08 08:42:34.049 MyApp[1838:20b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Error while creating delete statement => not an error'

SQLiteDB is my class which contains logic for init & checkAndCopyDB methods. My DB gets copied in documents directory. Other DB operations works fine. Please help me. Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

花辞树 2024-11-06 17:50:27

你调用 sqlite3_step 两次?

试试这个:

{
    int result = sqlite3_step(compiledstatement);

    if(SQLITE_DONE != result)

        NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(database) );
 }

you're calling sqlite3_step twice?

Try this :

{
    int result = sqlite3_step(compiledstatement);

    if(SQLITE_DONE != result)

        NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(database) );
 }
朕就是辣么酷 2024-11-06 17:50:27

也许尝试:

if(SQLITE_DONE != sqlite3_step(compiledstatement))
    NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(database));

Perhaps try:

if(SQLITE_DONE != sqlite3_step(compiledstatement))
    NSAssert1(0,@"Error while creating delete statement => %s",sqlite3_errmsg(database));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文