Re: [sqlite] Error handling
On 2/15/2017 10:42 PM, Igor Korot wrote: Now I presume that calling sqlite3_finalize() on the NULL handle is safe? Yes; the documentation explicitly states that. -- Igor Tandetnik ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Error handling
Hi, Richard, On Wed, Feb 15, 2017 at 8:20 PM, Richard Hippwrote: > On 2/15/17, Igor Korot wrote: >> >> Well, my question here is a bit different - if sqlite3_step () returns an >> error >> should the statement be released? >> > > You still need to invoke either sqlite3_finalize() or sqlite3_reset() > on the statement. Use sqlite3_finalize() if you will never use that > statement again, and sqlite3_reset() if you want to reuse it. Just be > cause it got an error on one go doesn' t mean that it cannot be > reused, if that is what you are asking. Basically I was asking if the failure on the sqlite3_step() release the statement handle or not. So thank you for confirming it is not. Now I presume that calling sqlite3_finalize() on the NULL handle is safe? Because I am planning to call this function only once - after the loop. Thank you. > > -- > D. Richard Hipp > d...@sqlite.org > ___ > sqlite-users mailing list > sqlite-users@mailinglists.sqlite.org > http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Error handling
On 2/15/17, Igor Korotwrote: > > Well, my question here is a bit different - if sqlite3_step () returns an > error > should the statement be released? > You still need to invoke either sqlite3_finalize() or sqlite3_reset() on the statement. Use sqlite3_finalize() if you will never use that statement again, and sqlite3_reset() if you want to reuse it. Just be cause it got an error on one go doesn' t mean that it cannot be reused, if that is what you are asking. -- D. Richard Hipp d...@sqlite.org ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Error handling
Hi, Igor, On Feb 15, 2017 7:16 PM, "Igor Tandetnik"wrote: On 2/15/2017 7:02 PM, Igor Korot wrote: > My question is: how many calls to "sqlite3_finalize() should be there? > For every successful call to sqlite3_prepare[_v2], there should eventually be a call to sqlite3_finalize; otherwise, you'd leak a statement, and prevent the database handle from closing cleanly. Ok. Do I need one inside lines 2-6? > You don't. If sqlite3_prepare_v2 fails, you wouldn't have a valid handle to pass to sqlite3_finalize. And how to properly handle failure with statement release? > sqlite3_finalize() itself never fails. Through a quirk of history, it may return an error code from the most recent failed sqlite3_step() call (see Goofy Interface Alert section at https://sqlite.org/c3ref/step.html ). Since you are using sqlite3_prepare_v2, you may ignore the return value of sqlite3_finalize. Well, my question here is a bit different - if sqlite3_step () returns an error should the statement be released? Thank you. -- Igor Tandetnik ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Error handling
On 2/15/2017 7:02 PM, Igor Korot wrote: My question is: how many calls to "sqlite3_finalize() should be there? For every successful call to sqlite3_prepare[_v2], there should eventually be a call to sqlite3_finalize; otherwise, you'd leak a statement, and prevent the database handle from closing cleanly. Do I need one inside lines 2-6? You don't. If sqlite3_prepare_v2 fails, you wouldn't have a valid handle to pass to sqlite3_finalize. And how to properly handle failure with statement release? sqlite3_finalize() itself never fails. Through a quirk of history, it may return an error code from the most recent failed sqlite3_step() call (see Goofy Interface Alert section at https://sqlite.org/c3ref/step.html ). Since you are using sqlite3_prepare_v2, you may ignore the return value of sqlite3_finalize. -- Igor Tandetnik ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Error handling
Hi, ALL, Consider the following pseudo-code: [code] int ret = sqlite3_prepare_v2(); if( ret != SQLITE_OK ) { // henerate error message return 1; } while( ; ; ) { ret = sqlite3_step(); if( ret == SQLITE_ROW ) { // everything is good } else if( ret == SQLITE_DONE ) break; else { result = 1; break; } } if( ret != SQLITE_DONE ) return 1; // everything is good - continue processing [/code] My question is: how many calls to "sqlite3_finalize() should be there? Do I need one inside lines 2-6? And how to properly handle failure with statement release? Thank you. ___ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Error handling anomaly ...
Rob Sciuk <[EMAIL PROTECTED]> wrote: > In a test harness, I'm using a sqlite3_prepare/bind/step/finalize > sequence to add rows to a table, and then add them again, > intentionally violating the unique index constraints. It appears > that sqlite3_step reports the violation (sqlite3_errorMessage), and > then the details (the offending column numbers) are only reported > when I check the error in the sqlite3_finalize() routine ... http://sqlite.org/c3ref/prepare.html Igor Tandetnik ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Error handling anomaly ...
In a test harness, I'm using a sqlite3_prepare/bind/step/finalize sequence to add rows to a table, and then add them again, intentionally violating the unique index constraints. It appears that sqlite3_step reports the violation (sqlite3_errorMessage), and then the details (the offending column numbers) are only reported when I check the error in the sqlite3_finalize() routine ... ::: Error ::: sq3_step: Error 19 returned from sqlite3_step. constraint failed ::: Error ::: sq3_finish: Error 19 returned from sqlite3_finalize. columns sname, fname, dob are not unique This is not a problem, per se, but in an ideal world, one might handle the error one time, and receive all the relevant information at one go. Is there a reason to defer reporting the details until the transaction is completed? Just wondering ... Cheers, Rob Sciuk ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Error handling.
On 8/27/06, Anders Aagaard <[EMAIL PROTECTED]> wrote: Jay Sprenkle wrote: > On 8/26/06, Anders Aagaard <[EMAIL PROTECTED]> wrote: >> Hi >> >> Is there any way to handle the different error messages from sqlite >> without doing strcmp? For example SQLITE_CONSTRAINT? > > will the conflict handling options do what you need? > http://www.sqlite.org/lang_conflict.html Unfortunately not :/, all I'd need is to return a different error code to the system based on which constraint it is. But string parsing to get the error codes seems awfully inefficient to me :/ I don't believe that particular error is delimited in the return codes. Maybe DRH would consider adding it in the future. - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] Error handling.
Jay Sprenkle wrote: On 8/26/06, Anders Aagaard <[EMAIL PROTECTED]> wrote: Hi Is there any way to handle the different error messages from sqlite without doing strcmp? For example SQLITE_CONSTRAINT? will the conflict handling options do what you need? http://www.sqlite.org/lang_conflict.html Unfortunately not :/, all I'd need is to return a different error code to the system based on which constraint it is. But string parsing to get the error codes seems awfully inefficient to me :/ -- SqliteImporter and SqliteReplicator: Command line utilities for Sqlite http://www.reddawn.net/~jsprenkl/Sqlite OSX version now available Cthulhu Bucks! http://www.cthulhubucks.com - To unsubscribe, send email to [EMAIL PROTECTED] - - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] Error handling.
On 8/26/06, Anders Aagaard <[EMAIL PROTECTED]> wrote: Hi Is there any way to handle the different error messages from sqlite without doing strcmp? For example SQLITE_CONSTRAINT? will the conflict handling options do what you need? http://www.sqlite.org/lang_conflict.html -- SqliteImporter and SqliteReplicator: Command line utilities for Sqlite http://www.reddawn.net/~jsprenkl/Sqlite OSX version now available Cthulhu Bucks! http://www.cthulhubucks.com - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] Error handling.
Looks like you're not alone... http://www.gatago.com/comp/databases/20027474.html /m - To unsubscribe, send email to [EMAIL PROTECTED] -
[sqlite] Error handling.
Hi Is there any way to handle the different error messages from sqlite without doing strcmp? For example SQLITE_CONSTRAINT? What I'm doing now is: id = SELECT id FROM Table WHERE parent=0; if id = NULL: handle parent does not exist code = INSERT INTO Table(NULL,'a',id); if (code == SQLITE_CONSTRAINT): handle data already exists (as that's the only other constraint I can have here) return data added ok What I'd like to do is: code = INSERT INTO Table VALUES(NULL,'a',(SELECT id FROM FileDir WHERE Path='pathname')) if (code == SQLITE_CONSTRAINT): if sqlite_error == SQL_NOT_NULL handle parent does not exist else if sqlite_error == SQL_EXISTS handle entry already exists return data added ok I can do that now by using: rc = sqlite3_exec(db, query, NULL, 0, ); if (rc == SQLITE_CONSTRAINT) if (strcmp(zErrMsg,"table can not be null") == ) // handle data Is there really no way to get these errors in another way? So I can avoid use of string compares. - To unsubscribe, send email to [EMAIL PROTECTED] -
[sqlite] error handling when aborting from sqlite3_exec callback
When using the sqlite3_exec for executing queries, it is possible to abort execution from the callback (returning a number different than 0). If i do that, sqlite3_exec will return SQLITE_ABORT with no error message, and if i call sqlite3_errcode later it will tell me no error occurred and the documentation says that it should return the error code for the most recent sqlite3_* API call. Documentation of sqlite3_exec function says: "... If an error occurs while parsing or evaluating the SQL (but not while executing the callback) then an appropriate error message is written into memory obtained from malloc() and *errmsg is made to point to that message..." So it behaves as expected, but shoudln't sqlite3_errcode still return SQLITE_ABORT in this case? Tiago