From 998ed1aa662defaccd54913fbb9a32f70bf5b0b0 Mon Sep 17 00:00:00 2001 From: Piotr Sarna Date: Tue, 25 Oct 2022 14:09:05 +0200 Subject: [PATCH] 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. --- ext/vwal/vwal.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 ext/vwal/vwal.c diff --git a/ext/vwal/vwal.c b/ext/vwal/vwal.c new file mode 100644 index 00000000000..51fa54db044 --- /dev/null +++ b/ext/vwal/vwal.c @@ -0,0 +1,148 @@ +#include "sqliteInt.h" +#include "wal.h" + +/* +** This file contains a stub for implementing one's own WAL routines. +** Registering a new set of WAL methods can be done through +** libsql_wal_methods_register(). Later, a registered set can +** be used by passing its name as a parameter to libsql_open(). +*/ + +extern int libsql_wal_methods_register(libsql_wal_methods*); + +static int v_open(sqlite3_vfs *pVfs, sqlite3_file *pDbFd, const char *zWalName, int bNoShm, i64 mxWalSize, libsql_wal_methods *pMethods, Wal **ppWal) { + //TODO: implement + return SQLITE_MISUSE; +} + +static int v_close(Wal *wal, sqlite3 *db, int sync_flags, int nBuf, u8 *zBuf) { + //TODO: implement + return SQLITE_MISUSE; +} + +static void v_limit(Wal *wal, i64 limit) { + //TODO: implement +} + +static int v_begin_read_transaction(Wal *wal, int *) { + //TODO: implement + return SQLITE_MISUSE; +} + +static void v_end_read_transaction(Wal *wal) { + //TODO: implement +} + +static int v_find_frame(Wal *wal, Pgno pgno, u32 *frame) { + //TODO: implement + return SQLITE_MISUSE; +} + +static int v_read_frame(Wal *wal, u32 frame, int nOut, u8 *pOut) { + //TODO: implement + return SQLITE_MISUSE; +} + +static Pgno v_dbsize(Wal *wal) { + //TODO: implement + return 0; +} + +static int v_begin_write_transaction(Wal *wal) { + //TODO: implement + return SQLITE_MISUSE; +} + +static int v_end_write_transaction(Wal *wal) { + //TODO: implement + return SQLITE_MISUSE; +} + +static int v_undo(Wal *wal, int (*xUndo)(void *, Pgno), void *pUndoCtx) { + //TODO: implement + return SQLITE_MISUSE; +} + +static void v_savepoint(Wal *wal, u32 *wal_data) { + //TODO: implement +} + +static int v_savepoint_undo(Wal *wal, u32 *wal_data) { + //TODO: implement + return SQLITE_MISUSE; +} + +static int v_frames(Wal *pWal, int szPage, PgHdr *pList, Pgno nTruncate, int isCommit, int sync_flags) { + //TODO: implement + return SQLITE_MISUSE; +} + +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) { + //TODO: implement + return SQLITE_MISUSE; +} + +static int v_callback(Wal *wal) { + //TODO: implement + return SQLITE_MISUSE; +} + +static int v_exclusive_mode(Wal *wal, int op) { + //TODO: implement + return SQLITE_MISUSE;; +} + +static int v_heap_memory(Wal *wal) { + //TODO: implement + return SQLITE_MISUSE; +} + +static sqlite3_file *v_file(Wal *wal) { + //TODO: implement + return NULL; +} + +static void v_db(Wal *wal, sqlite3 *db) { + //TODO: implement +} + +__attribute__((__visibility__("default"))) +void libsql_register_vwal() { + static libsql_wal_methods methods = { + .xOpen = v_open, + .xClose = v_close, + .xLimit = v_limit, + .xBeginReadTransaction = v_begin_read_transaction, + .xEndReadTransaction = v_end_read_transaction, + .xFindFrame = v_find_frame, + .xReadFrame = v_read_frame, + .xDbsize = v_dbsize, + .xBeginWriteTransaction = v_begin_write_transaction, + .xEndWriteTransaction = v_end_write_transaction, + .xUndo = v_undo, + .xSavepoint = v_savepoint, + .xSavepointUndo = v_savepoint_undo, + .xFrames = v_frames, + .xCheckpoint = v_checkpoint, + .xCallback = v_callback, + .xExclusiveMode = v_exclusive_mode, + .xHeapMemory = v_heap_memory, +#ifdef SQLITE_ENABLE_SNAPSHOT + .xSnapshotGet = NULL, + .xSnapshotOpen = NULL, + .xSnapshotRecover = NULL, + .xSnapshotCheck = NULL, + .xSnapshotUnlock = NULL, +#endif +#ifdef SQLITE_ENABLE_ZIPVFS + .xFramesize = NULL, +#endif + .xFile = v_file, +#ifdef SQLITE_ENABLE_SETLK_TIMEOUT + .xWriteLock = NULL, +#endif + .xDb = v_db, + .zName = "vwal" + }; + libsql_wal_methods_register(&methods); +}