diff --git a/ext/vwal/vwal.c b/ext/vwal/vwal.c index e53a73f9b9..619770d602 100644 --- a/ext/vwal/vwal.c +++ b/ext/vwal/vwal.c @@ -151,6 +151,7 @@ void libsql_register_vwal() { .xDb = v_db, .xPathnameLen = v_pathname_len, .xGetWalPathname = v_get_wal_pathname, + .xPreMainDbOpen = NULL, .zName = "vwal" }; libsql_wal_methods_register(&methods); diff --git a/src/pager.c b/src/pager.c index f4b8578e5a..9c8a5eb5eb 100644 --- a/src/pager.c +++ b/src/pager.c @@ -4893,6 +4893,14 @@ int sqlite3PagerOpen( sqlite3FileSuffix3(zFilename, pPager->zWal); pPtr = (u8*)(pPager->zWal + sqlite3Strlen30(pPager->zWal)+1); #endif + + if (pWalMethods->xPreMainDbOpen) { + int rc = pWalMethods->xPreMainDbOpen(zPathname); + if (rc != SQLITE_OK) { + return rc; + } + } + }else{ pPager->zWal = 0; } diff --git a/src/wal.c b/src/wal.c index 2e782e4bb2..bc751ae823 100644 --- a/src/wal.c +++ b/src/wal.c @@ -4092,6 +4092,10 @@ static void libsqlGetWalPathname(char *buf, const char *orig, int orig_len) { memcpy(buf + orig_len, "-wal", 4); } +static int libsqlPreMainDbOpen(Wal *, const char *) { + return SQLITE_OK; +} + libsql_wal_methods *libsql_wal_methods_find(const char *zName) { static libsql_wal_methods methods; static libsql_wal_methods *methods_head = NULL; @@ -4146,6 +4150,7 @@ libsql_wal_methods *libsql_wal_methods_find(const char *zName) { methods.xDb = sqlite3WalDb; methods.xPathnameLen = libsqlWalPathnameLen; methods.xGetWalPathname = libsqlGetWalPathname; + methods.xPreMainDbOpen = libsqlPreMainDbOpen; methods.bUsesShm = 1; methods.zName = "default"; diff --git a/src/wal.h b/src/wal.h index 5380889b49..6383fb5e6a 100644 --- a/src/wal.h +++ b/src/wal.h @@ -141,6 +141,13 @@ typedef struct libsql_wal_methods { ** */ void (*xGetWalPathname)(char *buf, const char *orig, int orig_len); + /* + ** This optional callback gets called before the main database file which owns + ** the WAL file is open. It is a good place for initialization routines, as WAL + ** is otherwise open lazily. + */ + int (*xPreMainDbOpen)(Wal *pWal, const char *main_db_path); + /* True if the implementation relies on shared memory routines (e.g. locks) */ int bUsesShm;