It worked out with pre-compiled statements (using sqlite3_bind_int).
But I still wonder if there is a way to set integer values (dynamic values) 
into DB with INSERT and UPDATE?



If you don't want to use prepared statements, I believe you can get the effect you are after with calls to sqlite3_mprintf and sqlite3_exec, for example:

//here's our variables
char * strFoo="isn't this nice?";
int nBar=123;

//use sqlite's built in string formatter - note that %q helpfully does escaping for us
char * strSQL=sqlite3_mprintf("insert into mytable(col1,col2) values (%d, '%q')", bBar, strFoo);


//execute our sql
sqlite3_exec(db, strSQL, NULL, NULL,NULL);

//and remember to free up the return value from sqlite3_mprintf
sqlite3_free(strSQL);


If you use this technique, you'll may want to roll your own function or class method with a signature like exec(const char* fmt, ....) - easy to do, just use sqlite3_vmprintf instead to pick up the argument list.


Paul






Reply via email to