Skip to content

Commit

Permalink
shell: add .walmethodslist
Browse files Browse the repository at this point in the history
The command is heavily inspired by .vfslist
and lists all the registered custom WAL methods.
  • Loading branch information
psarna committed Nov 28, 2022
1 parent bfe450b commit 4960a71
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3975,6 +3975,11 @@ int sqlite3_file_control(sqlite3 *db, const char *zDbName, int op, void *pArg){
}else if( op==SQLITE_FCNTL_DATA_VERSION ){
*(unsigned int*)pArg = sqlite3PagerDataVersion(pPager);
rc = SQLITE_OK;
#ifndef SQLITE_OMIT_WAL
}else if( op==SQLITE_FCNTL_WAL_METHODS_POINTER ){
*(libsql_wal_methods**)pArg = sqlite3PagerWalMethods(pPager);
rc = SQLITE_OK;
#endif
}else if( op==SQLITE_FCNTL_RESERVE_BYTES ){
int iNew = *(int*)pArg;
*(int*)pArg = sqlite3BtreeGetRequestedReserve(pBtree);
Expand Down
9 changes: 9 additions & 0 deletions src/pager.c
Original file line number Diff line number Diff line change
Expand Up @@ -7050,6 +7050,15 @@ sqlite3_vfs *sqlite3PagerVfs(Pager *pPager){
return pPager->pVfs;
}

#ifndef SQLITE_OMIT_WAL
/*
** Return the WAL methods structure for the pager.
*/
libsql_wal_methods *sqlite3PagerWalMethods(Pager *pPager){
return pPager->pWalMethods;
}
#endif

/*
** Return the file handle for the database file associated
** with the pager. This might return NULL if the file has
Expand Down
3 changes: 3 additions & 0 deletions src/pager.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ u32 sqlite3PagerDataVersion(Pager*);
int sqlite3PagerMemUsed(Pager*);
const char *sqlite3PagerFilename(const Pager*, int);
sqlite3_vfs *sqlite3PagerVfs(Pager*);
#ifndef SQLITE_OMIT_WAL
libsql_wal_methods *sqlite3PagerWalMethods(Pager*);
#endif
sqlite3_file *sqlite3PagerFile(Pager*);
sqlite3_file *sqlite3PagerJrnlFile(Pager*);
const char *sqlite3PagerJournalname(Pager*);
Expand Down
18 changes: 18 additions & 0 deletions src/shell.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -10836,6 +10836,24 @@ static int do_meta_command(char *zLine, ShellState *p){
}
}else

#ifndef SQLITE_OMIT_WAL
if( c=='w' && cli_strncmp(azArg[0], "walmethodslist", n)==0 ){
libsql_wal_methods *pWal;
libsql_wal_methods *pCurrent = 0;
if( p->db ){
sqlite3_file_control(p->db, "main", SQLITE_FCNTL_WAL_METHODS_POINTER, &pCurrent);
}
for(pWal=libsql_wal_methods_find(0); pWal; pWal=libsql_wal_methods_next(pWal)){

utf8_printf(p->out, "wal.zName = \"%s\"%s\n", libsql_wal_methods_name(pWal),
pWal==pCurrent ? " <--- CURRENT" : "");
if( libsql_wal_methods_next(pWal) ){
raw_printf(p->out, "-----------------------------------\n");
}
}
}else
#endif

if( c=='w' && cli_strncmp(azArg[0], "wheretrace", n)==0 ){
unsigned int x = nArg>=2 ? (unsigned int)integerValue(azArg[1]) : 0xffffffff;
sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 3, &x);
Expand Down
13 changes: 13 additions & 0 deletions src/sqlite.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,13 @@ struct sqlite3_io_methods {
** ^When there are multiple VFS shims in the stack, this opcode finds the
** upper-most shim only.
**
** <li>[[SQLITE_FCNTL_WAL_METHODS_POINTER]]
** ^The [SQLITE_FCNTL_WAL_METHODS_POINTER] opcode finds a pointer to the top-level
** WAL methods currently in use. ^(The argument X in
** sqlite3_file_control(db,SQLITE_FCNTL_WAL_METHODS_POINTER,X) must be
** of type "[libsql_wal_methods] **". This opcodes will set *X
** to a pointer to the top-level WAL methods.)^
**
** <li>[[SQLITE_FCNTL_PRAGMA]]
** ^Whenever a [PRAGMA] statement is parsed, an [SQLITE_FCNTL_PRAGMA]
** file control is sent to the open [sqlite3_file] object corresponding
Expand Down Expand Up @@ -1242,6 +1249,9 @@ struct sqlite3_io_methods {
#define SQLITE_FCNTL_EXTERNAL_READER 40
#define SQLITE_FCNTL_CKSM_FILE 41

// libSQL extension
#define SQLITE_FCNTL_WAL_METHODS_POINTER 129

/* deprecated names */
#define SQLITE_GET_LOCKPROXYFILE SQLITE_FCNTL_GET_LOCKPROXYFILE
#define SQLITE_SET_LOCKPROXYFILE SQLITE_FCNTL_SET_LOCKPROXYFILE
Expand Down Expand Up @@ -7733,6 +7743,9 @@ libsql_wal_methods *libsql_wal_methods_find(const char *zName);
int libsql_wal_methods_register(libsql_wal_methods*);
int libsql_wal_methods_unregister(libsql_wal_methods*);

libsql_wal_methods *libsql_wal_methods_next(libsql_wal_methods *w);
const char *libsql_wal_methods_name(libsql_wal_methods *w);

/*
** CAPI3REF: Mutexes
**
Expand Down
8 changes: 8 additions & 0 deletions src/wal.c
Original file line number Diff line number Diff line change
Expand Up @@ -4209,4 +4209,12 @@ int libsql_wal_methods_unregister(libsql_wal_methods *pWalMethods) {
return SQLITE_OK;
}

libsql_wal_methods *libsql_wal_methods_next(libsql_wal_methods *w) {
return w->pNext;
}

const char *libsql_wal_methods_name(libsql_wal_methods *w) {
return w->zName;
}

#endif /* #ifndef SQLITE_OMIT_WAL */

0 comments on commit 4960a71

Please sign in to comment.