SQLite Forum

Passing variable to SQLite3 fields
Login
Your SQL syntax is ass backwards.

IF you are SURE that the source of your data is reliable, you can just sqlite3_snprintf your statement with a pattern of

"INSERT INTO aoreadings (id, readvalue, status) VALUES (%d,%d,%q);"

and the values you woudl like to insert. Unless you really want to generate id values, you could also declare "id integer primary key" and have SQLite do that for you. In this case, do not provide an id in your statement.

Otherwise you need to call one of the sqlite3_prepare() routines (once only) with an argument of (or similar to)

"INSERT INTO aoreadings (id, readvalue, status) VALUES (?,?,?);"

Then call the sqlite3_bind_xxx() functions suitable for the types of values you are binding to assign values to the parameters.

Then call sqlite3_step() to actually perform the insert.

Repeat the bind and step for however many records you want to insert.

remember to call sqlite3_finalize() when you are done with the statement.

NOTE: To avoid SQL injection attacks, do not pass user input to SQL without checking for malicious content.