This sample code shows how to create a SQLite extension DLL that registers a simple VFS shim + File shim that logs read/write operations:
#include <sqlite3ext.h>
SQLITE_EXTENSION_INIT1
#include <iostream>
using namespace std;
LogIOFileShim() {
cout << "> Constructing file!" << endl;
}
int xRead(void *p, int iAmt, sqlite3_int64 iOfst) override {
cout << "> READ " << iAmt << " bytes starting at " << iOfst << endl;
return SQLiteFileImpl::xRead(p, iAmt, iOfst);
}
int xWrite(const void *p, int iAmt, sqlite3_int64 iOfst) override {
cout << "> WRITE " << iAmt << " bytes starting at " << iOfst << endl;
return SQLiteFileImpl::xWrite(p, iAmt, iOfst);
}
int xClose() override {
cout << "> CLOSE" << endl;
return SQLiteFileImpl::xClose();
}
~LogIOFileShim() {
cout << "> Destroying file!" << endl;
}
};
int result = SQLiteVfsImpl::xOpen(zName, file, flags, pOutFlags);
if (result == SQLITE_OK) {
cout << "> OPENED '" << zName << "'" << endl;
}
else {
cout << "> ERROR OPENING '" << zName << "': " << sqlite3_errstr(result) << endl;
}
return result;
}
};
extern "C" int sqlite3_logiovfs_init(sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi) {
SQLITE_EXTENSION_INIT2(pApi);
int rc = logiovfs.register_vfs(false);
if (rc == SQLITE_OK) {
rc = SQLITE_OK_LOAD_PERMANENTLY;
}
return rc;
}
Definition: SQLiteVfs.hpp:45
Definition: SQLiteVfs.hpp:161
Definition: SQLiteVfs.hpp:58
Definition: SQLiteVfs.hpp:390
Definition: SQLiteVfs.hpp:286