如何设置Sqlite结果集以在iOS中插入唯一不同的值?

时间:2015-01-19 05:59:04

标签: ios objective-c sqlite insert-update distinct-values

我是iOS的新手,也是sqllite数据库中的新手,所以请帮助我解决问题。我想在sqllite表中只插入不同的值,就像在这里我将值插入到我的表中

sqlite3_stmt    *statement;
const char *dbpath = [_databasePath UTF8String];
if (sqlite3_open(dbpath, &_myDatabase) == SQLITE_OK) {

    NSString *insertSQL = [NSString stringWithFormat:
                           @"INSERT INTO ALLREADTABLE (PostId, PostTitle, ImageLink, ShortDescription,Category,PostDate) VALUES (\"%@\", \"%@\", \"%@\", \"%@\",\"%@\",\"%@\")",
                           post_id, cell.headLabel.text, image,self.shortDiscription,cell.categoryLabel.text,cell.timeLabel.text];

    const char *insert_stmt = [insertSQL UTF8String];

    sqlite3_prepare_v2(_myDatabase, insert_stmt,
                       -1, &statement, NULL);
    if (sqlite3_step(statement) == SQLITE_DONE)
    {
        NSString *string=[NSString stringWithFormat:@"Value Added %@ %@ %@ %@ %@ %@ ",post_id, cell.headLabel.text, image,self.shortDiscription,cell.categoryLabel.text,cell.timeLabel.text];
        NSLog(@"String %@",string);
    } else
    {
       NSLog(@"Failed to add contact");
    }
    sqlite3_finalize(statement);
    sqlite3_close(_myDatabase);
}

现在我想要当我在表中插入相同的值时,我希望删除旧值并将新值插入到我的表中。如何可能请给我解决方案。

0 个答案:

没有答案