I’m having great difficulty to find a working example on the net regarding getting multiple values from a SQlite DB using xcode and cocos2dx. Here is the sql query I have:
char sql_query[100];
sprintf(sql_query, "SELECT * FROM SQList WHERE ColumnD BETWEEN %d AND %d ORDER BY RANDOM() LIMIT 1", MinColumnD, MaxColumnD);
The query it self seems to work, the main problem is how do I get the values that I collect from ‘select *’ into another int or char parameter so that I can use it?
Some example I found referred to using a callback to a struct or mentioned about using sqlite3_prepare_v2 and the step method.
I’m unable to find an example for either methods though, please help!
When using
sqlite3_exec, you have to convert all values from strings, and you have to use the callback’svoid *pointer or some global variable to return data:When using
sqlite3_prepare*, you have to callsqlite3_stepin a loop until it does not returnSQLITE_ROWanymore (when you expect only one record, you can call it only once):