On 2/11/2015 5:46 PM, Jono Poff wrote:
I wonder if anybody could give me a simple example in C to bind an array
of values to a prepared statement?
The effect I'm looking for is ....
sqlite3_stmt* stmt = Compile(db, "select * in Things where thing1 in
( <what goes here?> );");
sqlite3_bind_???(stmt, 0 , <what goes here? an array?> );
With small number of values, you can generate a string like "?, ?, ?"
with one question mark per parameter, embed it into the statement
between parens, and bind each element individually. Or, just sprintf
them all into a string and embed into the query as literals (especially
if they are numbers; with strings, beware SQL injection).
With large number of values, create a temp table, insert them into that
table one per row (using an auxiliary single-parameter INSERT
statement), then reformulate your query to do a nested select on that table.
These approaches use stock capabilities of SQLite and don't require
heroic efforts (like patching source or implementing a virtual table).
--
Igor Tandetnik
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users