Dear list,

It seems that after sqlite3_prepare_v2() and sqlite3_step() we have that sqlite3_errcode() returns meaningful result right away when some function invokes sqlite3_result_error() during sqlite3_step(). OK so far.

The issue is with sqlite3_errmsg(). If a function post an ad-hoc message using sqlite3_result_error(), then this message is only available after sqlite3_finalize() or sqlite3_reset(). In the meantime (that is after sqlite3_step and before sqlite3_reset or _finalize) only the standard message hardcoded in SQLite code is available using sqlite3_errmsg().

E.g. suppose you have loaded an extension which has a sqrt() function returning a custom error message in case the argument passed is negative. Then this is the scenario:

sqlite3_prepare_v2("select sqrt(-1);")
sqlite3_step()          // error returned by sqrt here
sqlite3_finalize()
sqlite3_errmsg()        // check the error message

We get the expected custom message "sqrt domain error". But if I execute

sqlite3_prepare_v2("select sqrt(-1);")
sqlite3_step()          // error returned by sqrt here
sqlite3_errmsg()        // check the error message

We get "SQL logic error or missing database".
Looks like the custom error message is not reachable unless the statement is finalized or reset.

If this a design "feature" that future releases aren't going to fix anytime soon, at least the docs should explain the situation clearly. Lack of sync between errcode and errmsg is highly unexpected.

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to