[sqlite] Strange behaviour of sqlite3_stmt_busy
Sorry, I misread the documentation. And do you recommend the strategy used in tclsqlite.c: rcs = sqlite3_step(pStmt); if( rcs==SQLITE_ROW ){ return TCL_OK; } ... rcs = sqlite3_reset(pStmt); ... Reset the stmt as soon as possible after sqlite3_step (except on SQLITE_ROW) ? Thanks. On Fri, Jul 31, 2015 at 12:02 PM, Clemens Ladisch wrote: > Stephan Beal wrote: >> On Thu, Jul 30, 2015 at 11:35 PM, Clemens Ladisch >> wrote: >>> gwenn wrote: sqlite3_stmt_busy returns true after sqlite3_step returns DONE. >>> >>> The documentation says: >>> | The sqlite3_stmt_busy(S) interface returns true (non-zero) if the >>> | prepared statement S has been stepped at least once using >>> | sqlite3_step(S) but has not run to completion and/or has not been >>> | reset using sqlite3_reset(S). >>> >>> The statement has not been reset, and that "and/or" can be read as "or". >> >> Does that means that SQLITE_DONE does _not_ mean "has run to completion"? > > No. > > Let me rephrase that doc snippet: > "sqlite3_stmt_busy() returns true if A but not B and/or not C" (where > A = "stepped", B = "SQLITE_DONE", C = "reset"). > > I do not know if the "but not" and "and/or" operators use the SQL > precedence rules. :) But there exists a way of interpreting this > sentence that matches the actual behavuour. > > > Regards, > Clemens > ___ > sqlite-users mailing list > sqlite-users at mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Strange behaviour of sqlite3_stmt_busy
On 31 Jul 2015, at 6:03pm, gwenn wrote: > And do you recommend the strategy used in tclsqlite.c: > > rcs = sqlite3_step(pStmt); > if( rcs==SQLITE_ROW ){ >return TCL_OK; > } > ... > rcs = sqlite3_reset(pStmt); > ... > > > Reset the stmt as soon as possible after sqlite3_step (except on SQLITE_ROW) ? Using _reset() or _finalize() releases resources. If you're not going to need the statement again then _finalize() is better because it releases more resources. Simon.
[sqlite] Strange behaviour of sqlite3_stmt_busy
On 7/30/15, gwenn wrote: > Hello, > sqlite3_stmt_busy returns true after sqlite3_step returns DONE. Fixed at https://www.sqlite.org/src/info/047d3475e93d08cf -- D. Richard Hipp drh at sqlite.org
[sqlite] Strange behaviour of sqlite3_stmt_busy
Stephan Beal wrote: > On Thu, Jul 30, 2015 at 11:35 PM, Clemens Ladisch > wrote: >> gwenn wrote: >>> sqlite3_stmt_busy returns true after sqlite3_step returns DONE. >> >> The documentation says: >> | The sqlite3_stmt_busy(S) interface returns true (non-zero) if the >> | prepared statement S has been stepped at least once using >> | sqlite3_step(S) but has not run to completion and/or has not been >> | reset using sqlite3_reset(S). >> >> The statement has not been reset, and that "and/or" can be read as "or". > > Does that means that SQLITE_DONE does _not_ mean "has run to completion"? No. Let me rephrase that doc snippet: "sqlite3_stmt_busy() returns true if A but not B and/or not C" (where A = "stepped", B = "SQLITE_DONE", C = "reset"). I do not know if the "but not" and "and/or" operators use the SQL precedence rules. :) But there exists a way of interpreting this sentence that matches the actual behavuour. Regards, Clemens
[sqlite] Strange behaviour of sqlite3_stmt_busy
On Fri, Jul 31, 2015 at 10:51 AM, Hick Gunter wrote: > SQLITE_DONE means that there are no (more) rows to be retrieved. > So that's the difference (for a SELECT) between that and "running to completion"? i think that's the source of the confusion. -- - stephan beal http://wanderinghorse.net/home/stephan/ http://gplus.to/sgbeal "Freedom is sloppy. But since tyranny's the only guaranteed byproduct of those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
[sqlite] Strange behaviour of sqlite3_stmt_busy
On Thu, Jul 30, 2015 at 11:35 PM, Clemens Ladisch wrote: > gwenn wrote: > > sqlite3_stmt_busy returns true after sqlite3_step returns DONE. > > The documentation says: > | The sqlite3_stmt_busy(S) interface returns true (non-zero) if the > | prepared statement S has been stepped at least once using > | sqlite3_step(S) but has not run to completion and/or has not been > | reset using sqlite3_reset(S). > > The statement has not been reset, and that "and/or" can be read as "or". > Does that means that SQLITE_DONE does _not_ mean "has run to completion"? Based on the above doc snippet, i would expect sqlite3_stmt_busy() to return false after step() returns DONE. -- - stephan beal http://wanderinghorse.net/home/stephan/ http://gplus.to/sgbeal "Freedom is sloppy. But since tyranny's the only guaranteed byproduct of those who insist on a perfect world, freedom will have to do." -- Bigby Wolf
[sqlite] Strange behaviour of sqlite3_stmt_busy
SQLITE_DONE means that there are no (more) rows to be retrieved. -Urspr?ngliche Nachricht- Von: Stephan Beal [mailto:sgbeal at googlemail.com] Gesendet: Freitag, 31. Juli 2015 10:12 An: General Discussion of SQLite Database Betreff: Re: [sqlite] Strange behaviour of sqlite3_stmt_busy On Thu, Jul 30, 2015 at 11:35 PM, Clemens Ladisch wrote: > gwenn wrote: > > sqlite3_stmt_busy returns true after sqlite3_step returns DONE. > > The documentation says: > | The sqlite3_stmt_busy(S) interface returns true (non-zero) if the > | prepared statement S has been stepped at least once using > | sqlite3_step(S) but has not run to completion and/or has not been > | reset using sqlite3_reset(S). > > The statement has not been reset, and that "and/or" can be read as "or". > Does that means that SQLITE_DONE does _not_ mean "has run to completion"? Based on the above doc snippet, i would expect sqlite3_stmt_busy() to return false after step() returns DONE. -- - stephan beal http://wanderinghorse.net/home/stephan/ http://gplus.to/sgbeal "Freedom is sloppy. But since tyranny's the only guaranteed byproduct of those who insist on a perfect world, freedom will have to do." -- Bigby Wolf ___ sqlite-users mailing list sqlite-users at mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users ___ Gunter Hick Software Engineer Scientific Games International GmbH FN 157284 a, HG Wien Klitschgasse 2-4, A-1130 Vienna, Austria Tel: +43 1 80100 0 E-Mail: hick at scigames.at This communication (including any attachments) is intended for the use of the intended recipient(s) only and may contain information that is confidential, privileged or legally protected. Any unauthorized use or dissemination of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender by return e-mail message and delete all copies of the original communication. Thank you for your cooperation.
[sqlite] Strange behaviour of sqlite3_stmt_busy
gwenn wrote: > sqlite3_stmt_busy returns true after sqlite3_step returns DONE. The documentation says: | The sqlite3_stmt_busy(S) interface returns true (non-zero) if the | prepared statement S has been stepped at least once using | sqlite3_step(S) but has not run to completion and/or has not been | reset using sqlite3_reset(S). The statement has not been reset, and that "and/or" can be read as "or". Regards, Clemens
[sqlite] Strange behaviour of sqlite3_stmt_busy
Hello, sqlite3_stmt_busy returns true after sqlite3_step returns DONE. Here is the code: #include #include #include "sqlite3.h" int main(int argc, char **argv) { sqlite3 *db = NULL; sqlite3_stmt *stmt = NULL; char *zErrMsg = NULL; const char *z; int rc = 0; rc = sqlite3_open_v2("", , SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); if (db == NULL || SQLITE_OK != rc) { fprintf(stderr, "Error: unable to open database: %s\n", sqlite3_errmsg(db)); exit(1); } rc = sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL); if (SQLITE_OK != rc) { fprintf(stderr, "Error: tx start: %s\n", sqlite3_errmsg(db)); exit(1); } rc = sqlite3_prepare_v2(db, "ROLLBACK", -1, , NULL); if (stmt == NULL || SQLITE_OK != rc) { fprintf(stderr, "Error: prepare stmt: %s\n", sqlite3_errmsg(db)); exit(1); } rc = sqlite3_stmt_busy(stmt); printf("%s busy before step? %d\n", sqlite3_sql(stmt), rc); rc = sqlite3_step(stmt); if (SQLITE_DONE != rc) { fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db)); exit(1); } rc = sqlite3_stmt_busy(stmt); printf("%s busy after step? %d\n", sqlite3_sql(stmt), rc); rc = sqlite3_reset(stmt); if (SQLITE_OK != rc) { fprintf(stderr, "Error: %s\n", sqlite3_errmsg(db)); exit(1); } rc = sqlite3_stmt_busy(stmt); printf("%s busy after reset? %d\n", sqlite3_sql(stmt), rc); sqlite3_finalize(stmt); sqlite3_close(db); } And the output: ROLLBACK busy before step? 0 ROLLBACK busy after step? 1 ROLLBACK busy after reset? 0 SQLite version 3.8.10.2 Darwin Kernel Version 14.4.0 Why does sqlite3_stmt_busy return true even on stmt completion (DONE) ? Regards.