Exception handling during create table from a virtual one

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Exception handling during create table from a virtual one

Max Vlasov
Hi,

I have a virtual table that raises an unhandled exception during a create
table ... as select * from {myvirtualtable} command, inside xColumn
callback. I already fixed the error inside my library to handle the
situation reasonably, but there's something I noticed for the non-handled
exception scenario.

Аfter the exception is thrown ....

.... If I continue the execution, then the following symptoms are shown:
- The sqlite returns "unknown" error for this query
- Select * from sqlite_master reveals an empty row.
- integrity_check:  *** in database main *** Page 2 is never used
- after I reopen this db, Pragma encoding query and probably other queries
produces "schema is malformed" error

...... If I halt the process when the debugger stops at the exception
- The db is restored (rolled back) to correct state (no new table created,
no integrity errors)

Is this expected? I mean, sqlite usually handles well unexpected halts and
this is something that might be desired (for example, computers might shut
down abruptly), but unexpected exception is something about code control
flow which no sane library can guarantee to handle well.

sqlite 3.25.2
If necessary I can provide small copies of the original db (1024 bytes) and
malformed (2048)

Thanks,

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

Re: Exception handling during create table from a virtual one

Clemens Ladisch
Max Vlasov wrote:
> I have a virtual table that raises an unhandled exception during a create
> table

SQLite is written in C.  The C language does not have exceptions.

> Аfter the exception is thrown ....
> .... If I continue the execution

You must return from the callback function normally, or abort the process.
Anything else will corrupt SQLite's internal state.


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

Re: Exception handling during create table from a virtual one

Max Vlasov
On Fri, Oct 26, 2018 at 5:50 PM Clemens Ladisch <[hidden email]> wrote:

> > Аfter the exception is thrown ....
> > .... If I continue the execution
>
> You must return from the callback function normally, or abort the process.
> Anything else will corrupt SQLite's internal state.
>
>
Thanks, probably it's better for me to wrap any sensitive callback handler
in an exception catcher with SQLITE_ERROR code return.
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users