Re: [sqlite] Prepare and exec
Hum.. I'm sorry but I've followed your explanations, but I can't use it as I want.. The code is really simple : int i =0; for(i=0;i<=3;i++) { sqlite3_step(Stmt); callback; } sqlite3_reset(Stmt); (And after, _finalize, when I don't need it anymore). Is there an error in it? I've only one line in my table, ans 4 columns, that's why I've done i=0 to 3. Simon Slavin-3 wrote: > > > On 23 May 2011, at 2:05pm, Dev_lex wrote: > >> Well I know that _step is not a callback, but I have a callback to call.. >> With _exec I can call it without any problem, because I can pass it in >> the >> third argument.. But with the _prepare and _step method, I don't know how >> to >> bind my callback with the SELECT statement.. ? > > The _exec() function involves many calls to _step(). It does something > like this: > > sqlite3_prepare_v2() > ONE OR MORE TIMES: > sqlite3_step() > call your callback function > sqlite3_finalize() > > (I have omitted result-checking for clarity). With _exec, as above, you > can supply a callback and _exec() will call it immediately after each time > it calls _step(). > > But if you're calling _step(), then instead of calling _exec() you are > calling each of these three functions yourself, (i.e. writing your own C > code to implement the above pseudocode). You don't need a callback > function because you can put whatever code you want after calling _step(). > And before it. It could be one line that just calls another function, or > many lines with whatever logic you like. > > There are other places for callback functions which are called while > aggregate functions are evaluated, or long procedures are being run, or to > handle _BUSY errors, or at various other times. But you don't seem to be > referring to these. If I misunderstood, please post again. > > Simon. > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > -- View this message in context: http://old.nabble.com/Prepare-and-exec-tp31681326p31681900.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Prepare and exec
Well that's good, I understand the concept. I'm going to write a small code for this then ! Thanks a lot for your help ! Simon Slavin-3 wrote: > > > On 23 May 2011, at 2:05pm, Dev_lex wrote: > >> Well I know that _step is not a callback, but I have a callback to call.. >> With _exec I can call it without any problem, because I can pass it in >> the >> third argument.. But with the _prepare and _step method, I don't know how >> to >> bind my callback with the SELECT statement.. ? > > The _exec() function involves many calls to _step(). It does something > like this: > > sqlite3_prepare_v2() > ONE OR MORE TIMES: > sqlite3_step() > call your callback function > sqlite3_finalize() > > (I have omitted result-checking for clarity). With _exec, as above, you > can supply a callback and _exec() will call it immediately after each time > it calls _step(). > > But if you're calling _step(), then instead of calling _exec() you are > calling each of these three functions yourself, (i.e. writing your own C > code to implement the above pseudocode). You don't need a callback > function because you can put whatever code you want after calling _step(). > And before it. It could be one line that just calls another function, or > many lines with whatever logic you like. > > There are other places for callback functions which are called while > aggregate functions are evaluated, or long procedures are being run, or to > handle _BUSY errors, or at various other times. But you don't seem to be > referring to these. If I misunderstood, please post again. > > Simon. > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > -- View this message in context: http://old.nabble.com/Prepare-and-exec-tp31681326p31681664.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Prepare and exec
Simon Slavin-3 wrote: > > > On 23 May 2011, at 1:50pm, Dev_lex wrote: > >> I would like to do this : >> >> sqlite3_exec(query_handle.db,"SELECT * FROM DHSS", callback, 0, NULL); >> >> But I need to prepare the statement.. So I can prepare the statement : >> "SELECT * FROM DHSS" , but how can I call the callback with sqlite3_step? > > _step() is not a callback, it's a routine you call when you want the next > row. > > Take a look at this page: > > http://www.sqlite.org/c3ref/stmt.html > > and follow whatever links you like. If have a specific question about > callbacks, we can answer it. > > Simon. > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > Hello, Well I know that _step is not a callback, but I have a callback to call.. With _exec I can call it without any problem, because I can pass it in the third argument.. But with the _prepare and _step method, I don't know how to bind my callback with the SELECT statement.. ? -- View this message in context: http://old.nabble.com/Prepare-and-exec-tp31681326p31681456.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Prepare and exec
Hello everyone ! I've got a new question : I would like to do this : sqlite3_exec(query_handle.db,"SELECT * FROM DHSS", callback, 0, NULL); But I need to prepare the statement.. So I can prepare the statement : "SELECT * FROM DHSS" , but how can I call the callback with sqlite3_step? I hope this is understandable.. Thanks ! -- View this message in context: http://old.nabble.com/Prepare-and-exec-tp31681326p31681326.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Unknown parameter for prepare_v2
Forget my last post.. The error was that I didn't initialize pzTail to NULL... That's ok :) Dev_lex wrote: > > > Simon Slavin-3 wrote: >> >> >> On 19 May 2011, at 9:35am, Dev_lex wrote: >> >>> I need to prepare the statement before to know the name of the table, >>> but >>> I'll find an other way.. >>>> >>>>> >>>>> I would like to do this : >>>>> >>>>> const char *zSql = "INSERT INTO ?(ID, MyData) VALUES('1',?)"; >> >> Instead of using a const, use a C string, or select one of a few >> different consts. >> >> But what your problem is really telling you is that those tables are >> actually all one big table. The thing you think of as a table name is >> really just another column. >> >> Simon. >> ___ >> sqlite-users mailing list >> sqlite-users@sqlite.org >> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users >> >> > > > Yeah, thanks, I've found another way to solve my problem.. this wasn't too > hard ^^.. > > But now I've got a new problem, again with this function.. > > > I've create a structure in a header file (called init_handle) that > contains the informations like sqlite3 *db // sqlite3_stmt *Stmt // ... > > And in a .c file I've made a function that prepare a command, but I obtain > an error.. > > > Here is the line : > > if( sqlite3_prepare_v2(init_handle.db, zSql_stmt[i][j], > strlen(zSql_stmt[i][j])+1, &init_handle.Stmt[i][j], init_handle.pzTail) != > SQLITE_OK ) > { >fprintf(stderr, "Can't prepare : %s\n", > sqlite3_errmsg(init_handle.db)); >sqlite3_close(init_handle.db); >exit(1); > } > > And the error says : > > Can't create table : table DHSS already exists > Can't prepare : near "create": syntax error > > Do I have made a syntax error? > -- View this message in context: http://old.nabble.com/Unknown-parameter-for-prepare_v2-tp31653746p31662807.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Unknown parameter for prepare_v2
Simon Slavin-3 wrote: > > > On 19 May 2011, at 9:35am, Dev_lex wrote: > >> I need to prepare the statement before to know the name of the table, but >> I'll find an other way.. >>> >>>> >>>> I would like to do this : >>>> >>>> const char *zSql = "INSERT INTO ?(ID, MyData) VALUES('1',?)"; > > Instead of using a const, use a C string, or select one of a few different > consts. > > But what your problem is really telling you is that those tables are > actually all one big table. The thing you think of as a table name is > really just another column. > > Simon. > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > Yeah, thanks, I've found another way to solve my problem.. this wasn't too hard ^^.. But now I've got a new problem, again with this function.. I've create a structure in a header file (called init_handle) that contains the informations like sqlite3 *db // sqlite3_stmt *Stmt // ... And in a .c file I've made a function that prepare a command, but I obtain an error.. Here is the line : if( sqlite3_prepare_v2(init_handle.db, zSql_stmt[i][j], strlen(zSql_stmt[i][j])+1, &init_handle.Stmt[i][j], init_handle.pzTail) != SQLITE_OK ) { fprintf(stderr, "Can't prepare : %s\n", sqlite3_errmsg(init_handle.db)); sqlite3_close(init_handle.db); exit(1); } And the error says : Can't create table : table DHSS already exists Can't prepare : near "create": syntax error Do I have made a syntax error? -- View this message in context: http://old.nabble.com/Unknown-parameter-for-prepare_v2-tp31653746p31662252.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Unknown parameter for prepare_v2
Oh ok.. Thanks a lot, I thought there was some way to do that.. I need to prepare the statement before to know the name of the table, but I'll find an other way.. Thanks ! Martin Engelschalk wrote: > > Hi, > > you cannot bind the name of a table. Bind variables only work for Values > in the database, like you used in the VALUES('1', ?) - clause. > Names of tables, columns or other items of the schema must be written in > the sql statement. > You will have to build your statement (using sprintf() or similar) > before preparig it. > > This is not uniqe to sqlite, but to SQL in general. > > Martin > > Am 19.05.2011 10:04, schrieb Dev_lex: >> Hello, >> >> I've a little question about sqlite3_prepare_v2 : >> >> I would like to do this : >> >>const char *zSql = "INSERT INTO ?(ID, MyData) VALUES('1',?)"; >> >> if(ppStmt) >>{ >>sqlite3_bind_parameter_name(ppStmt, "atest"); >>sqlite3_bind_blob(ppStmt, 2,&blob, sizeof(blob), >> SQLITE_TRANSIENT); >>sqlite3_step(ppStmt); >>sqlite3_finalize(ppStmt); >>} >> >> So then I've just to bind values.. It works great for the second '?' >> which >> is a blob, so bind_blob(), but for the first one I don't really know what >> to >> use ? >> >> Maybe the '?' syntax is incorrect? I've not understood everything about >> it.. >> >> Regards > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > -- View this message in context: http://old.nabble.com/Unknown-parameter-for-prepare_v2-tp31653746p31653969.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Unknown parameter for prepare_v2
Hello, I've a little question about sqlite3_prepare_v2 : I would like to do this : const char *zSql = "INSERT INTO ?(ID, MyData) VALUES('1',?)"; if(ppStmt) { sqlite3_bind_parameter_name(ppStmt, "atest"); sqlite3_bind_blob(ppStmt, 2, &blob, sizeof(blob), SQLITE_TRANSIENT); sqlite3_step(ppStmt); sqlite3_finalize(ppStmt); } So then I've just to bind values.. It works great for the second '?' which is a blob, so bind_blob(), but for the first one I don't really know what to use ? Maybe the '?' syntax is incorrect? I've not understood everything about it.. Regards -- View this message in context: http://old.nabble.com/Unknown-parameter-for-prepare_v2-tp31653746p31653746.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users