0

我有 Sql 数据库,一切正常

  NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO CONTACTS where (modifiedAdress) VALUES (\"%@\")", hemaInsert];

我用它来插入,但我是怎么做的

只有我需要插入到联系人列中的 Sql 语句修改地址值 hemainsert(condition hemaInsert = ID )

NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO CONTACTS where (modifiedAdress) VALUES (\"%@\")", hemaInsert];
4

2 回答 2

1
- (void) InserRecorinTable:(NSString*) hemaInsert
{


        int ret;
        const char *sql =   "insert into CONTACTS (modifiedAdress) values (?);";

        sqlite3_stmt *insStmt = NULL;
        if ( !insStmt )
            if ( (ret = sqlite3_prepare_v2(_database, sql, -1, &insStmt, NULL)) != SQLITE_OK ) {}

        // bind values
        sqlite3_bind_text(insStmt, 1, hemaInsert, -1, SQLITE_TRANSIENT);                

        if ((ret = sqlite3_step(insStmt)) != SQLITE_DONE) {NSLog(@"error while inserting marker");}
        sqlite3_reset(insStmt);


}
于 2013-03-02T13:50:01.203 回答
0

如果要插入整行/元组/记录。

NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO CONTACTS where modifiedAdress is '%@'", hemaInsert];//you can go for " or ' as per oracle or other sqls.


NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO CONTACTS where modifiedAdress = \"%@\"", hemaInsert];//you can go for " or ' as per oracle or other sqls.

编辑:

INSERT 用于添加元组(行)。如果您只想在特定列中插入,则需要使用UPDATE

语法是:

UPDATE tableName
SET column1=value, column2=value2,...
WHERE some_column=some_value

采用:

NSString *insertSQL = [NSString stringWithFormat: @"UPDATE CONTACTS SET modifiedAdress  = \"%@\"", hemaInsert];
于 2013-03-02T13:28:47.617 回答