簡體   English   中英

無法從SQLite iPhone刪除記錄

[英]Can not delete record from SQLite iPhone

在iPhone模擬器中運行此代碼時,無法從DB刪除記錄。 如果我在SQLite數據庫瀏覽器中運行此查詢,則效果很好。 這是我的代碼

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方法的邏輯。 我的數據庫被復制到文檔目錄中。 其他數據庫操作正常。 請幫我。 謝謝

您兩次調用sqlite3_step?

嘗試這個 :

{
    int result = sqlite3_step(compiledstatement);

    if(SQLITE_DONE != result)

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

也許嘗試:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM