views:

51

answers:

2

I have sql query statement which used to display the contents in the table.The sql statement consist of a where clause which is to be appended with numeric value as 1 ,2 3 etc depends upon the previously selected content.I am having the numeric value as int and i want it to append to sql statement which is const char.how can i append both the values.Please help me out.

My query is ==> select * from Book where id=1;

i have the id value is integer

Thanks.

+1  A: 

You simply bind the parameter. E.g.:

sqlite3 *db;
... // open database
sqlite3_stmt *pStmt;

sqlite3_prepare_v2(
  db,
  "select * from book where id = ?",
  -1,
  &pStmt,
  NULL
);

sqlite3_bind_int(pStmt, 1, bookId);

See the SQLite documentation on compiling and binding prepared statements. You can reuse the same statement more than once. sqlite3_clear_bindings lets you reset the values.

Matthew Flaschen
Your answer was totally incomplete when down voted. I'll reverse it now though.
Geoff
Thanks,It works fine.
Warrior
A: 

Is this what you're looking for?

NSString* result = [NSString stringWithFormat:@"SELECT * FROM Book WHERE id=%d", myInt];

to compose your SQL string?

Geoff