开发者

How to bind dynamic NSNumber Object to SQLite query?

开发者 https://www.devze.com 2022-12-24 07:22 出处:网络
I\'m wondering how to bind an NSNumber o开发者_JS百科bject into a sqlite3 query: const char *sql = \"select name from myTable where section_id=1 order by name ASC\";

I'm wondering how to bind an NSNumber o开发者_JS百科bject 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..


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.

0

精彩评论

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

关注公众号