IOS - SQLite DELETE数据失败

时间:2014-04-21 04:05:39

标签: ios sqlite

我的数据库有点问题,上次是它的工作。

但现在我无法从数据库中删除我的数据。

此处的代码

   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"ShopBook.db"];
    if (sqlite3_open([path UTF8String], &db) == SQLITE_OK) {
        const char *sql = "SELECT * FROM ShopBook";
        sqlite3_stmt *searchStatement;
        if (sqlite3_prepare_v2(db, sql, -1, &searchStatement, NULL) == SQLITE_OK) {

            while (sqlite3_step(searchStatement) == SQLITE_ROW) {

                NSString *tempQRcodeList = [NSString stringWithUTF8String:(char *)sqlite3_column_text(searchStatement, 5)];

//                {...do something...}             
                sqlite3_finalize(searchStatement);
                NSString *deleteSQL = [NSString stringWithFormat: @"DELETE FROM ShopBook WHERE qrCode = \"%@\"", tempQRcodeList];//I already have this data in database.

                const char *delete_stmt = [deleteSQL UTF8String];
                sqlite3_prepare_v2(db, delete_stmt, -1, &searchStatement, NULL);
                int smt = sqlite3_step(searchStatement);
                if (smt == SQLITE_DONE){

                    NSLog(@"Deleted");

                } else {
                    NSLog(@"Delete Fail : %d",smt);// alway go fail 

                }
                return YES;  
            }
        }       
        sqlite3_finalize(searchStatement);
    }
    sqlite3_close(db);
    return NO;
如果你有任何想法,请给我一个想法。 感谢。

亲切的问候,

Kabitis。

0 个答案:

没有答案