Skip to content

Commit 998ed1a

Browse files
committed
ext: add a stub for custom WAL methods
This commit adds a stub implementation of custom WAL methods in ext/vwal subdirectory. It can be used as a starting point for implementing custom WAL routines.
1 parent 14b7ed6 commit 998ed1a

File tree

1 file changed

+148
-0
lines changed

1 file changed

+148
-0
lines changed

ext/vwal/vwal.c

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
#include "sqliteInt.h"
2+
#include "wal.h"
3+
4+
/*
5+
** This file contains a stub for implementing one's own WAL routines.
6+
** Registering a new set of WAL methods can be done through
7+
** libsql_wal_methods_register(). Later, a registered set can
8+
** be used by passing its name as a parameter to libsql_open().
9+
*/
10+
11+
extern int libsql_wal_methods_register(libsql_wal_methods*);
12+
13+
static int v_open(sqlite3_vfs *pVfs, sqlite3_file *pDbFd, const char *zWalName, int bNoShm, i64 mxWalSize, libsql_wal_methods *pMethods, Wal **ppWal) {
14+
//TODO: implement
15+
return SQLITE_MISUSE;
16+
}
17+
18+
static int v_close(Wal *wal, sqlite3 *db, int sync_flags, int nBuf, u8 *zBuf) {
19+
//TODO: implement
20+
return SQLITE_MISUSE;
21+
}
22+
23+
static void v_limit(Wal *wal, i64 limit) {
24+
//TODO: implement
25+
}
26+
27+
static int v_begin_read_transaction(Wal *wal, int *) {
28+
//TODO: implement
29+
return SQLITE_MISUSE;
30+
}
31+
32+
static void v_end_read_transaction(Wal *wal) {
33+
//TODO: implement
34+
}
35+
36+
static int v_find_frame(Wal *wal, Pgno pgno, u32 *frame) {
37+
//TODO: implement
38+
return SQLITE_MISUSE;
39+
}
40+
41+
static int v_read_frame(Wal *wal, u32 frame, int nOut, u8 *pOut) {
42+
//TODO: implement
43+
return SQLITE_MISUSE;
44+
}
45+
46+
static Pgno v_dbsize(Wal *wal) {
47+
//TODO: implement
48+
return 0;
49+
}
50+
51+
static int v_begin_write_transaction(Wal *wal) {
52+
//TODO: implement
53+
return SQLITE_MISUSE;
54+
}
55+
56+
static int v_end_write_transaction(Wal *wal) {
57+
//TODO: implement
58+
return SQLITE_MISUSE;
59+
}
60+
61+
static int v_undo(Wal *wal, int (*xUndo)(void *, Pgno), void *pUndoCtx) {
62+
//TODO: implement
63+
return SQLITE_MISUSE;
64+
}
65+
66+
static void v_savepoint(Wal *wal, u32 *wal_data) {
67+
//TODO: implement
68+
}
69+
70+
static int v_savepoint_undo(Wal *wal, u32 *wal_data) {
71+
//TODO: implement
72+
return SQLITE_MISUSE;
73+
}
74+
75+
static int v_frames(Wal *pWal, int szPage, PgHdr *pList, Pgno nTruncate, int isCommit, int sync_flags) {
76+
//TODO: implement
77+
return SQLITE_MISUSE;
78+
}
79+
80+
static int v_checkpoint(Wal *wal, sqlite3 *db, int eMode, int (xBusy)(void *), void *pBusyArg, int sync_flags, int nBuf, u8 *zBuf, int *pnLog, int *pnCkpt) {
81+
//TODO: implement
82+
return SQLITE_MISUSE;
83+
}
84+
85+
static int v_callback(Wal *wal) {
86+
//TODO: implement
87+
return SQLITE_MISUSE;
88+
}
89+
90+
static int v_exclusive_mode(Wal *wal, int op) {
91+
//TODO: implement
92+
return SQLITE_MISUSE;;
93+
}
94+
95+
static int v_heap_memory(Wal *wal) {
96+
//TODO: implement
97+
return SQLITE_MISUSE;
98+
}
99+
100+
static sqlite3_file *v_file(Wal *wal) {
101+
//TODO: implement
102+
return NULL;
103+
}
104+
105+
static void v_db(Wal *wal, sqlite3 *db) {
106+
//TODO: implement
107+
}
108+
109+
__attribute__((__visibility__("default")))
110+
void libsql_register_vwal() {
111+
static libsql_wal_methods methods = {
112+
.xOpen = v_open,
113+
.xClose = v_close,
114+
.xLimit = v_limit,
115+
.xBeginReadTransaction = v_begin_read_transaction,
116+
.xEndReadTransaction = v_end_read_transaction,
117+
.xFindFrame = v_find_frame,
118+
.xReadFrame = v_read_frame,
119+
.xDbsize = v_dbsize,
120+
.xBeginWriteTransaction = v_begin_write_transaction,
121+
.xEndWriteTransaction = v_end_write_transaction,
122+
.xUndo = v_undo,
123+
.xSavepoint = v_savepoint,
124+
.xSavepointUndo = v_savepoint_undo,
125+
.xFrames = v_frames,
126+
.xCheckpoint = v_checkpoint,
127+
.xCallback = v_callback,
128+
.xExclusiveMode = v_exclusive_mode,
129+
.xHeapMemory = v_heap_memory,
130+
#ifdef SQLITE_ENABLE_SNAPSHOT
131+
.xSnapshotGet = NULL,
132+
.xSnapshotOpen = NULL,
133+
.xSnapshotRecover = NULL,
134+
.xSnapshotCheck = NULL,
135+
.xSnapshotUnlock = NULL,
136+
#endif
137+
#ifdef SQLITE_ENABLE_ZIPVFS
138+
.xFramesize = NULL,
139+
#endif
140+
.xFile = v_file,
141+
#ifdef SQLITE_ENABLE_SETLK_TIMEOUT
142+
.xWriteLock = NULL,
143+
#endif
144+
.xDb = v_db,
145+
.zName = "vwal"
146+
};
147+
libsql_wal_methods_register(&methods);
148+
}

0 commit comments

Comments
 (0)