Ebrahim Elgeded
Ebrahim Elgeded

Reputation: 40

Need Correct Sql Stmt

I have Sql Data Base every Thing Work Right

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

i use this for insert but how i but condition

only i Need Sql Statement That Said Insert into contact column modifiedAdress Value hemainsert (condition hemaInsert = ID )

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

Upvotes: 0

Views: 76

Answers (2)

iPatel
iPatel

Reputation: 47069

- (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);


}

Upvotes: 1

Anoop Vaidya
Anoop Vaidya

Reputation: 46543

If you want to Insert an entire row/tuple/record.

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.

EDIT:

INSERT is used to add a tuple(row). If you want to insert only at a particular column you need to use UPDATE.

The syntax is :

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

Use:

NSString *insertSQL = [NSString stringWithFormat: @"UPDATE CONTACTS SET modifiedAdress  = \"%@\"", hemaInsert];

Upvotes: 0

Related Questions