【问题标题】:Can not delete record from SQLite iPhone无法从 SQLite iPhone 中删除记录
【发布时间】:2011-04-07 16:25:13
【问题描述】:

当我在 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 和 checkAndCopyDB 方法的逻辑。我的数据库被复制到文档目录中。其他数据库操作工作正常。请帮我。谢谢

【问题讨论】:

    标签: iphone sqlite delete-row


    【解决方案1】:

    你要调用 sqlite3_step 两次?

    试试这个:

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

    【讨论】:

      【解决方案2】:

      或许可以试试:

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

      【讨论】:

        猜你喜欢
        • 2013-10-06
        • 1970-01-01
        • 2014-10-16
        • 1970-01-01
        • 2011-02-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-11
        相关资源
        最近更新 更多