c++ - sqlite3 bind variables syntax -


i trying implement c++11 wrapper c api of sqlite, particularly sqlite3_bind functions. in shape of (example code):

sqlt3::exec<void>(     _db,     "insert or replace window values('position', ?3, ?4);\n"     "insert or replace window values('size', ?1, ?2);\n"     "insert or replace window values('maximized', ?5, '0');\n",     size.x,     size.y,     position.x,     position.y,     static_cast<int>(ismaximized())     ); 

the problem here ? shared between different statements. exec function internally prepares subsequent sql statements 1 one. cannot determine parameters should bound statements, because there no api statement slots statement contains. can count of slots n (a max nnn ?nnns) unable determine whether particular slots 0 n occupied. because there can single ? no number , sqlite3_bind_parameter_name returns null both nameless parameter , lack of parameter. ideally have function returns list of indexes of binding points used in given statement or @ least way discriminate whether given index has associated 'nameless' binding point or no binding point @ all.

one solution came upon bind parameters, in order passed exec, of statements didn't found in documentation legal bind nonexistent parameter. drawback complexity v times s v number of variables bound , s number of statements.

so, came workaround parse whole string passed exec , gather info binding points (?, ?nnn, :vvv etc.). but, think isn't quite trivial task because special symbol not special in contexts string , quatations. so, contexts in sql statements, in special tokens ?, ?nnn, etc. have not meaning of binding points?

some explanations:

"trying parse sql pointless."

i not want parse sql, detect presence , indexes of arguments (binding points).

"do think v*s become large enough matters?"

in common case no, still not know if legal bind parameter slot wasn't occurred in statement. , there problem ?, if occurs @ beginning of second sentence, should not has index 1, should rather have index of last binding point in previous sentence increased 1.

"and why want allow multiple statements in single function call?"

i found ability handy, when need execute them in 1 transaction.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -