I want to save the data from USB into the database sqlite3.
Here is data from USB
char T0[8], T1[8], T2[8], T3[8], T4[8];
I create a table with
const char* Temprature_table = "Create table Temprature_1 (ID INTERGER PRIMARY KEY,Thermo_0 decimal(5,1),Thermo_1 decimal(5,1),Thermo_2 decimal(5,1),Thermo_3 decimal(5,1),Thermo_4 decimal(5,1),time DATETIME)";
then I insert data into the table
result = sqlite3_exec (DB,"Insert into Temprature VALUES(NULL, T0, T1, T2, T3, T4, time)",0,0,&errmsg);
or
char array[256];
sprintf(array, "Insert into Temprature_1 VALUES(NULL, T0, T1, T2, T3, T4, time)");
result = sqlite3_exec (DB,array,0,0,&errmsg);
but there is a problem: “cannot insert data: no such column: T0”.
I do not know why.
Thanks.
You should use prepared statements to bind values to your query. A regular SQL has the form
A prepared statement looks like
which allows for security and performance enhancements. So your final code will look like
See this SQLite introduction to the C API. Your code doesn’t work because you submit the following string to the query engine
while the syntax of the INSERT statement looks like
When the database engine evaluates your query, it can’t know that
TOhappens to be the name of a variable somewhere in your code, thus issue that error. The SQL is a language of its own, it doesn’t share anything with the C context.As a final note, the correct spelling seems to be TEMPERATURE, not TEMPRATURE (you missed an E after PR)