diff --git a/conn.go b/conn.go index 1222bd51..862d4306 100644 --- a/conn.go +++ b/conn.go @@ -68,7 +68,7 @@ func OpenFlags(filename string, flags OpenFlag) (*Conn, error) { return newConn(context.Background(), filename, flags) } -type connKey struct{} +type connKey = util.ConnKey func newConn(ctx context.Context, filename string, flags OpenFlag) (res *Conn, _ error) { err := ctx.Err() diff --git a/internal/util/module.go b/internal/util/module.go index 4089dcab..ba5754a3 100644 --- a/internal/util/module.go +++ b/internal/util/module.go @@ -8,6 +8,8 @@ import ( "github.com/ncruces/go-sqlite3/internal/alloc" ) +type ConnKey struct{} + type moduleKey struct{} type moduleState struct { mmapState diff --git a/vfs/api.go b/vfs/api.go index e29a0c8c..77612332 100644 --- a/vfs/api.go +++ b/vfs/api.go @@ -191,3 +191,8 @@ type fileControl interface { File fileControl(ctx context.Context, mod api.Module, op _FcntlOpcode, pArg uint32) _ErrorCode } + +type filePDB interface { + File + SetDB(any) +} diff --git a/vfs/vfs.go b/vfs/vfs.go index 6edfe275..713d0a51 100644 --- a/vfs/vfs.go +++ b/vfs/vfs.go @@ -376,6 +376,12 @@ func vfsFileControlImpl(ctx context.Context, mod api.Module, file File, op _Fcnt return _OK } } + + case _FCNTL_PDB: + if file, ok := file.(filePDB); ok { + file.SetDB(ctx.Value(util.ConnKey{})) + return _OK + } } // Consider also implementing these opcodes (in use by SQLite):