>From: Guillaume BIENKOWSKI <guitre...@gmail.com> To: General Discussion of SQLite Database <sqlite-users@sqlite.org> Sent: Thu, May 5, 2011 3:00:55 PM Subject: Re: [sqlite] Profile API: triggered only when sqlite3_step() returns DONE?
>Okay we answered at the same time. Indeed :) >I have no problem concerning the retrieving of data, I use sqlite3_column() to get the data I need. The callback I'm talking about is the *profiling* callback, not the one you're thinking about (you're talking about the callback you pass when using sqlite3_exec()). >The problem is that the *profiling* function (that you register with sqlite3_profile() ) gets called only when you step over to the end, to retrieve all the records you wanted. Since, in my case, I'm only interested in the first record, I don't step() until the end, so the profiling function is never called. I have no idea about the 'profile' thing, but since you want your statement to end (i.e. return SQLITE_DONE) after the first retrieved record, I recommend using 'LIMIT 1' in your query. >Well, except when I accidentally try to retrieve a non-existent id, which I have in my test cases. This time, the single step() I use directly returns "SQLITE_DONE" and the profiling function is called. >Anyway, what's disturbing is that I was expecting the function to be called event if I don't step() until the end. Typically when I perform the finalize() on my query. >From what I see in the code, the profiling function is called in step(), which I think is strange. >Guillaume >On Thu, May 5, 2011 at 1:52 PM, Marian Cascaval <mariancasca...@yahoo.com>wrote: > Please, read once more the documentation: > > http://www.sqlite.org/cintro.html > > > sqlite3_step() does not trigger any callback function, it only tells you if > there's any data to retrieve. > > If you want to retrieve data, either use sqlite3_column() in your > exemplified > typical code, or use sqlite3_exec() - which triggers callback function. > > > > Marian Cascaval > > > > > > ________________________________ > From: Guillaume B <guitre...@gmail.com> > To: sqlite-users@sqlite.org > Sent: Thu, May 5, 2011 11:38:56 AM > Subject: [sqlite] Profile API: triggered only when sqlite3_step() returns > DONE? > > Hey guys, > > I'm trying to use the sqlite3_profile() function to monitor the delays > of the requests I make in my application. > I can see some of the statements in my trace, but it seems that not > all the statements trigger the callback. > > Some context informations first: > - sqlite3 is in version 3.6.0, running on an SH4 platform under linux > - the code is in C/C++ and uses the sqlite3 API with the "v2" statements > > My typical code flow is something like that: > > - prepare a SELECT query > - sqlite3_step(), make sure it returns SQLITE_ROW (I expect to get one > record, and only one) > - finalize() > > In this mode, I never see the callback triggered, or just in erroneous > queries. > I actually narrowed down that the callback is only called when > sqlite3_step() *doesn't* return SQLITE_ROW, but rather SQLITE_DONE, > which means it didn't find any record and is finished. > > Problem is, I only need to get one record out of the query, so I never > call step() after my SQLITE_ROW again to make the function return > SQLITE_DONE. > > My questions now: > > - Is the profiling callback triggered only when reaching the end of > the query (<=> sqlite3_step() returns "DONE") ? > > - If yes, is it normal? Timing the request time should only be a > matter on stepping once, since the whole query gets passed to the > sqlite engine and successive steps should hit a cache or something > (i'm extrapolating there...)? > Or does the sqlite3 C API proceeds by... steps and then computes the > total amount of time spent in successive sqlite3_step() calls? > > - Then wouldn't it be more convenient to place the callback trigger > when one finalizes the query? So that even if we don't get all the > records from the query (<=> don't call step() until we hit > SQLITE_DONE), we still get a timing? > > Thanks to whoever answers :) > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users