Quantcast

sqlite3_errmsg() after sqlitr3_exec() on ATTACHed DB

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

sqlite3_errmsg() after sqlitr3_exec() on ATTACHed DB

Ward Willats
Hello.

In our embedded system we have two databases ATTACHed to each other and size constrained with max_page pragmas directed at each. (Different filesystems: one is on a tmpfs in RAM, the other on JFFS).

When I perform an sqlite3_exec() to DELETE too many rows in the secondary ATTACHed database and a disk or database full error occurs, I properly get a code 13 returned from the API.

But if I then turn around and call sqlite3_errmsg() I get "not an error" returned. (Our too-complicated custom sqlite wrapper does this.)

Guesses:

The error string returned by sqlite3_errmsg() comes from the connection structure, and it says "not an error" because, indeed, there as no error on the primary DB.

There is a hidden handle/structure for the ATTACHed DB that has the correct error string, but sqlite3_errmsg() does not look there.

If I passed in an error string pointer to the exec() call itself, I would properly get a "disk or database full" message. In fact, that may be one of the reasons such a parameter exists on this API.

The rule is, if it is an exec(), get your error string from the exec() call, otherwise, you can get it from sqlite3_errmsg().

(This is no big deal as it is just for our internal logging, and, obviously I am being lazy by not just running a test in the shell to see, and, also, our wrapper code is likely buggy and is also obscuring what I am really doing even from myself (!), but thought it worth throwing this out for others and to be sure my conceptual model was not too far off the mark before I start hacking away.)

Thanks again.

-- Ward





_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: sqlite3_errmsg() after sqlitr3_exec() on ATTACHed DB

Igor Tandetnik-2
On 2/1/2017 10:32 AM, Ward WIllats wrote:
> When I perform an sqlite3_exec() to DELETE too many rows in the secondary ATTACHed database and a disk or database full error occurs, I properly get a code 13 returned from the API.
>
> But if I then turn around and call sqlite3_errmsg() I get "not an error" returned.

With sqlite3_exec(), the error message is returned via its last
parameter, not via sqlite3_errmsg(). sqlite3_exec is a wrapper that
calls other SQLite APIs internally, and the one that failed may not be
the last call, so the error may already have been reset by the time you
get around to sqlite3_errmsg(). Which is why sqlite3_exec() makes the
effort to preserve the message and forward it to you, should you choose
to accept it.
--
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: sqlite3_errmsg() after sqlitr3_exec() on ATTACHed DB

Ward Willats

> On Feb 1, 2017, at 1:18 PM, Igor Tandetnik <[hidden email]> wrote:
>
> On 2/1/2017 10:32 AM, Ward WIllats wrote:
>> When I perform an sqlite3_exec() to DELETE too many rows in the secondary ATTACHed database and a disk or database full error occurs, I properly get a code 13 returned from the API.
>>
>> But if I then turn around and call sqlite3_errmsg() I get "not an error" returned.
>
> With sqlite3_exec(), the error message is returned via its last parameter, not via sqlite3_errmsg(). sqlite3_exec is a wrapper that calls other SQLite APIs internally, and the one that failed may not be the last call, so the error may already have been reset by the time you get around to sqlite3_errmsg(). Which is why sqlite3_exec() makes the effort to preserve the message and forward it to you, should you choose to accept it.

Thanks Igor. Makes perfect sense.

-- Ward


_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Loading...