sqlite3-ocaml icon indicating copy to clipboard operation
sqlite3-ocaml copied to clipboard

Windows compatibility

Open db4 opened this issue 6 years ago • 2 comments

Looking into the commit history I see Improved exception function declarations for MSVC commit, whose name suggests that sqlite3-ocaml can be built for Windows. Unfortunately that's not the case; https://github.com/mmottl/sqlite3-ocaml/commit/03291392186f33e33b6bcc5cb9566a242c65ccd3 destroyed Windows compatibility opportunity introducing pthread API use that cannot be easily emulated under Windows (destructor function passed to pthread_key_create). I could try to put Windows compatibility back, but I would like to know first why user exceptions should be registered on per-thread basis?

db4 avatar Mar 29 '19 06:03 db4

Users can register their own functions for use in SQL statements. These functions may fail with exceptions, which will have to be propagated back through the C-library and the C-bindings to the OCaml user code. The problem here is that multiple threads may be performing SQLite3 calls and hence raise exceptions in user-defined functions simultaneously. Since there is no way of passing these exceptions back through SQLite3 arguments or results (that I know of), the only way seemed to be by storing them using thread-specific data.

Maybe there are (new) SQLite3 features that allow you to return this information through result values or by passing them back imperatively through arguments. If not, then SQLite3 cannot be used from multiple threads under Windows in the presence of potentially failing, user-defined functions.

Please feel free to submit any potential fix without the use of POSIX thread functions if you find one! It would also be possible to fail differently under Windows by not propagating the exact exception raised in the user-defined function and raising a generic exception instead. I guess this loss of information would be acceptable to most users, since exceptions should generally be avoided for control flow anyway.

mmottl avatar Apr 01 '19 15:04 mmottl

We noticed the same thing here, and have an alternative patch. I will try to compare the two approaches, and report there.

yakobowski avatar Apr 04 '19 09:04 yakobowski