tags:

views:

130

answers:

1

hi guys,

I'm wondering how to bind an NSNumber object into a sqlite3 query:

const char *sql = "select name from myTable where section_id=1 order by name ASC";

I have a NSNumber object called 'nmbr' and want to assign its value to the section id..

Thomas

+1  A: 

Try this:

const char *sql = "select name from myTable where section_id=? order by name ASC";
sqlite3_prepare_v2(db_handle, sql, -1, &stmt, NULL) == SQLITE_OK;
NSNumber sid = [NSNumber numberWithInt:1];
sqlite3_bind_int  (stmt, 1, [sid intValue]);   
sqlite3_step(stmt);
sqlite3_reset(stmt);

Remember: you should deal with error return codes. For the sake of simplicity I am ignoring them here.

Pablo Santa Cruz
Thanks, works like a charm!
Thomas Joos
Glad it helped. If it was a solution for you, I would suggest to mark the answer as accepted. Regards.
Pablo Santa Cruz