开发者

Deleting data from SQLite3 iPhone SDK?

Hey, How can I delete data from SQLite3 iPhone SDK? I am able to insert data into the database by using this code:

-(void)insertRecordIntoTableNamed:(NSString *)tableName
                   withField1:(NSString *)field1
                  field1Value:(NSString*)field1Value
                    andField2:(NSString *)field2
                  field2Value:(NSString *)field2Value
{
    NSString *sql = [NSString stringWithFormat:@"INSERT OR REPLACE INTO '%@' ('%@' , '%@')     VALUES ('%@','%@')",tableName,field1,field2, field1Value,field2Value];
    char *err;      
    if (sqlite3_exec(db, [s开发者_如何学编程ql UTF8String], NULL, NULL, &err) != SQLITE_OK) {
        sqlite3_close(db);
        NSAssert(0,@"error updating table.");
    }
} 

I think I have to change something in NSString *sql but I can't figure out what do I have to change it to.

Thanks.


You need to use an SQL DELETE statement:

NSString *sql = [NSString stringWithFormat:@"DELETE FROM '%@' WHERE '%@' = '%@'", tableName, field1, field1Value];

The WHERE clause, of course, depends on what you want to delete from tableName.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜