Skip to content

Commit 4960a71

Browse files
committed
shell: add .walmethodslist
The command is heavily inspired by .vfslist and lists all the registered custom WAL methods.
1 parent bfe450b commit 4960a71

6 files changed

Lines changed: 56 additions & 0 deletions

File tree

src/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3975,6 +3975,11 @@ int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
39753975
}else if( op==SQLITE_FCNTL_DATA_VERSION ){
39763976
*(unsigned int*)pArg = sqlite3PagerDataVersion(pPager);
39773977
rc = SQLITE_OK;
3978+
#ifndef SQLITE_OMIT_WAL
3979+
}else if( op==SQLITE_FCNTL_WAL_METHODS_POINTER ){
3980+
*(libsql_wal_methods**)pArg = sqlite3PagerWalMethods(pPager);
3981+
rc = SQLITE_OK;
3982+
#endif
39783983
}else if( op==SQLITE_FCNTL_RESERVE_BYTES ){
39793984
int iNew = *(int*)pArg;
39803985
*(int*)pArg = sqlite3BtreeGetRequestedReserve(pBtree);

src/pager.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7050,6 +7050,15 @@ sqlite3_vfs *sqlite3PagerVfs(Pager *pPager){
70507050
return pPager->pVfs;
70517051
}
70527052

7053+
#ifndef SQLITE_OMIT_WAL
7054+
/*
7055+
** Return the WAL methods structure for the pager.
7056+
*/
7057+
libsql_wal_methods *sqlite3PagerWalMethods(Pager *pPager){
7058+
return pPager->pWalMethods;
7059+
}
7060+
#endif
7061+
70537062
/*
70547063
** Return the file handle for the database file associated
70557064
** with the pager. This might return NULL if the file has

src/pager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ u32 sqlite3PagerDataVersion(Pager*);
214214
int sqlite3PagerMemUsed(Pager*);
215215
const char *sqlite3PagerFilename(const Pager*, int);
216216
sqlite3_vfs *sqlite3PagerVfs(Pager*);
217+
#ifndef SQLITE_OMIT_WAL
218+
libsql_wal_methods *sqlite3PagerWalMethods(Pager*);
219+
#endif
217220
sqlite3_file *sqlite3PagerFile(Pager*);
218221
sqlite3_file *sqlite3PagerJrnlFile(Pager*);
219222
const char *sqlite3PagerJournalname(Pager*);

src/shell.c.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10836,6 +10836,24 @@ static int do_meta_command(char *zLine, ShellState *p){
1083610836
}
1083710837
}else
1083810838

10839+
#ifndef SQLITE_OMIT_WAL
10840+
if( c=='w' && cli_strncmp(azArg[0], "walmethodslist", n)==0 ){
10841+
libsql_wal_methods *pWal;
10842+
libsql_wal_methods *pCurrent = 0;
10843+
if( p->db ){
10844+
sqlite3_file_control(p->db, "main", SQLITE_FCNTL_WAL_METHODS_POINTER, &pCurrent);
10845+
}
10846+
for(pWal=libsql_wal_methods_find(0); pWal; pWal=libsql_wal_methods_next(pWal)){
10847+
10848+
utf8_printf(p->out, "wal.zName = \"%s\"%s\n", libsql_wal_methods_name(pWal),
10849+
pWal==pCurrent ? " <--- CURRENT" : "");
10850+
if( libsql_wal_methods_next(pWal) ){
10851+
raw_printf(p->out, "-----------------------------------\n");
10852+
}
10853+
}
10854+
}else
10855+
#endif
10856+
1083910857
if( c=='w' && cli_strncmp(azArg[0], "wheretrace", n)==0 ){
1084010858
unsigned int x = nArg>=2 ? (unsigned int)integerValue(azArg[1]) : 0xffffffff;
1084110859
sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 3, &x);

src/sqlite.h.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,13 @@ struct sqlite3_io_methods {
10121012
** ^When there are multiple VFS shims in the stack, this opcode finds the
10131013
** upper-most shim only.
10141014
**
1015+
** <li>[[SQLITE_FCNTL_WAL_METHODS_POINTER]]
1016+
** ^The [SQLITE_FCNTL_WAL_METHODS_POINTER] opcode finds a pointer to the top-level
1017+
** WAL methods currently in use. ^(The argument X in
1018+
** sqlite3_file_control(db,SQLITE_FCNTL_WAL_METHODS_POINTER,X) must be
1019+
** of type "[libsql_wal_methods] **". This opcodes will set *X
1020+
** to a pointer to the top-level WAL methods.)^
1021+
**
10151022
** <li>[[SQLITE_FCNTL_PRAGMA]]
10161023
** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]
10171024
** file control is sent to the open [sqlite3_file] object corresponding
@@ -1242,6 +1249,9 @@ struct sqlite3_io_methods {
12421249
#define SQLITE_FCNTL_EXTERNAL_READER 40
12431250
#define SQLITE_FCNTL_CKSM_FILE 41
12441251

1252+
// libSQL extension
1253+
#define SQLITE_FCNTL_WAL_METHODS_POINTER 129
1254+
12451255
/* deprecated names */
12461256
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
12471257
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
@@ -7733,6 +7743,9 @@ libsql_wal_methods *libsql_wal_methods_find(const char *zName);
77337743
int libsql_wal_methods_register(libsql_wal_methods*);
77347744
int libsql_wal_methods_unregister(libsql_wal_methods*);
77357745

7746+
libsql_wal_methods *libsql_wal_methods_next(libsql_wal_methods *w);
7747+
const char *libsql_wal_methods_name(libsql_wal_methods *w);
7748+
77367749
/*
77377750
** CAPI3REF: Mutexes
77387751
**

src/wal.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4209,4 +4209,12 @@ int libsql_wal_methods_unregister(libsql_wal_methods *pWalMethods) {
42094209
return SQLITE_OK;
42104210
}
42114211

4212+
libsql_wal_methods *libsql_wal_methods_next(libsql_wal_methods *w) {
4213+
return w->pNext;
4214+
}
4215+
4216+
const char *libsql_wal_methods_name(libsql_wal_methods *w) {
4217+
return w->zName;
4218+
}
4219+
42124220
#endif /* #ifndef SQLITE_OMIT_WAL */

0 commit comments

Comments
 (0)