上一次我的数据库有问题,这是正常的。

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

这是代码

   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。

  ask by Kabitis translate from so

本文未有回复,本站智能推荐: