Configuring a VFS from SQL
(1) By anonymous on 2020-03-31 07:01:04 [source]
I'm developing a VFS shim which offers various logging options, and I would like to be able to configure it at runtime. One option would be to implement different VFS versions for each option and choose an appropriate version on opening a database file, but a more flexible approach would be to be able to turn options on or off from SQL. Is there a way to accomplish that?
I found out that it is possible to implement specialized PRAGMAs through the file control method. However, such PRAGMAs are only handled, if there actually exists a database file, which is not the case if one opens for example a memory based database (filename :memory:
). Does this mean that operations on a memory based database can't be intercepted by a VFS?
Additionally, a VFS doesn't seem to be able to identify the database connection (sqlite3*
instance) from which it is used. Have I overlooked something? Or is this intentional?
(2) By Gunter Hick (gunter_hick) on 2020-03-31 07:28:04 in reply to 1 [link] [source]
Add a user defined function or eponymous-only virtual table to your VFS implementation. CREATE VIRTUAL TABLE vfs_options ( connection INTEGER, option TEXT, value TEXT);
(3) By Gunter Hick (gunter_hick) on 2020-03-31 07:36:16 in reply to 2 [link] [source]
Looking at the interface, the VFS does not know about connections, only about "files", so the table declaration should be "filehandle" instead of "Connection"
(4) By anonymous on 2020-03-31 14:47:26 in reply to 2 [link] [source]
Ok, that's an idea that could work. Thanks.
However, I see one problem with user-defined functions resp virtual table modules: in both cases a user/developer could override them with a different implementation. Sure, for well-behaving users this is unlikely to happen on purpose. But it doesn't seem to be possible to prevent overriding certain functions or modules.
IMHO it would be nice if SQLite would support user-defined PRAGMAs.