lundi 26 octobre 2015

How to use IN clause with SQLite for C?

I am facing an issue with executing SQL query in C library for SQLite. Here issue is when query contains IN clause.

Eg.,

Query:

SELECT * FROM EMPLOYEE WHERE ID IN (?);

C:

sqlite3_stmt *elems_stmt;
char empIds[40];
...
...
...
sqlite3_bind_text(elems_stmt, 1, (const char *)empIds, -1, SQLITE_TRANSIENT);

Here empIds could be 4,5,6

But as result, elems_stmt not getting any results.

Instead, if I hard code the values in the query as

SELECT * FROM EMPLOYEE WHERE ID IN (4,5,6);

I am able to see the results.

Please let me know what is missing in the first query and corresponding code.

Thanks.

Aucun commentaire:

Enregistrer un commentaire