无法从sqlite数据库中删除行

时间:2012-02-15 11:22:40

标签: iphone

任何人都可以帮我解决他在代码中遇到的问题。我无法从数据库中删除Row。

-(void) deleteData {

    sqlite3_stmt    *statement;

    NSString *destinationPath = [self getDestinationPath];

    const char *dbpath = [destinationPath UTF8String];

    if (sqlite3_open(dbpath, &database) == SQLITE_OK)
    {


        NSString *updateSQL = [NSString stringWithFormat: @"DELETE FROM BirthdayListDB WHERE id=\"%@\"",details.ids];

        const char *insert_stmt = [updateSQL UTF8String];

        sqlite3_prepare_v2(database, insert_stmt, -1, &statement, NULL);
        if (sqlite3_step(statement) == SQLITE_DONE)
        {
            NSLog(@"Row deleted");

        } 

        else
        {
            NSLog(@"Failed to delete row");
        }
        sqlite3_finalize(statement);
        sqlite3_close(database);
    }

}

这里(sqlite3_stmt * statement;)我没有得到语句值。我得到了声明的空值。可以帮助我解决这个问题。

谢谢!

1 个答案:

答案 0 :(得分:3)

只需替换

    NSString *updateSQL = [NSString stringWithFormat: @"DELETE FROM BirthdayListDB WHERE id=\"%@\"",details.ids];

使用

    NSString *updateSQL = [NSString stringWithFormat: @"DELETE FROM BirthdayListDB WHERE id='%@'",details.ids];

谢谢,