On Oct 02 2022, "Roger Binns" <
rog...@rogerbinns.com> wrote:
> On Sun, 2 Oct 2022, at 04:51, Nikolaus Rath wrote:
>>> I'm struggling to get this to work.
>
> It does work, but one detail is important!
>
>>> conn = apsw.Connection(file_)
>
> The vfs is looked up at the time the Connection is made, so this uses the existing vfs.
>
>>> populate(cur)
>>> vfs = VFS() # should call sqlite3_vfs_register()
>>> modify(cur)
>
> This still operates on the existing opened connection. Changing VFS registration only affects new connections. Changed to:
>
> populate(cur)
> vfs = VFS() # should call sqlite3_vfs_register()
> conn = apsw.Connection(file_) # reopen with new vfs
> cur = conn.cursor() # and new cursor on new vfs
> modify(cur)
>
Ah, thanks, that makes sense!
> Which would work except for this:
>
> class VFSFile(apsw.VFSFile):
> def __init__(self, fname: str, flags: list[int]) -> None:
> super().__init__(vfs='', filename=fname, flags=flags)
>
> At the point the super().__init__ is called, your VFS is now the
> default, so the super call calls itself, which calls itself, which
> calls itself ...
>
> I'd recommend you call apsw.vfsnames() at the very beginning which
> will tell you the default name and that way you can always reference
> the one intended.
I'm not sure I follow. Do you mean something like this?
default_vfs = apsw.vfsnames()[0]
class VFSFile(apsw.VFSFile):
def __init__(self, fname: str, flags: list[int]) -> None:
super().__init__(vfs=default_vfs, filename=fname, flags=flags)
Best,
-Nikolaus
--
GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
»Time flies like an arrow, fruit flies like a Banana.«