aboutsummaryrefslogtreecommitdiff
path: root/sqlite3_opt_vtable.go
diff options
context:
space:
mode:
authorPatrick DeVivo <patrick.devivo@gmail.com>2020-12-26 09:11:17 -0500
committerGitHub <noreply@github.com>2020-12-26 23:11:17 +0900
commit92d23714a87355a0b7087795126bc0e0e2b06098 (patch)
tree45b6e467fb85afe01fe258e87743cc5539cb6017 /sqlite3_opt_vtable.go
parentRowsColumnTypeNullable not implemented (#848) (diff)
downloadgolite-92d23714a87355a0b7087795126bc0e0e2b06098.tar.gz
golite-92d23714a87355a0b7087795126bc0e0e2b06098.tar.xz
add support for defining an "eponymous only" virtual table (#885)
* add support for defining an "eponymous only" virtual table As suggested here: https://github.com/mattn/go-sqlite3/issues/846#issuecomment-736206222 * add an example of an eponymous only vtab module * add a test case for an eponymous only vtab module
Diffstat (limited to 'sqlite3_opt_vtable.go')
-rw-r--r--sqlite3_opt_vtable.go55
1 files changed, 52 insertions, 3 deletions
diff --git a/sqlite3_opt_vtable.go b/sqlite3_opt_vtable.go
index c0a6214..8fd6cdf 100644
--- a/sqlite3_opt_vtable.go
+++ b/sqlite3_opt_vtable.go
@@ -226,11 +226,43 @@ static sqlite3_module goModule = {
0 // xRollbackTo
};
+// See https://sqlite.org/vtab.html#eponymous_only_virtual_tables
+static sqlite3_module goModuleEponymousOnly = {
+ 0, // iVersion
+ 0, // xCreate - create a table, which here is null
+ cXConnect, // xConnect - connect to an existing table
+ cXBestIndex, // xBestIndex - Determine search strategy
+ cXDisconnect, // xDisconnect - Disconnect from a table
+ cXDestroy, // xDestroy - Drop a table
+ cXOpen, // xOpen - open a cursor
+ cXClose, // xClose - close a cursor
+ cXFilter, // xFilter - configure scan constraints
+ cXNext, // xNext - advance a cursor
+ cXEof, // xEof
+ cXColumn, // xColumn - read data
+ cXRowid, // xRowid - read data
+ cXUpdate, // xUpdate - write data
+// Not implemented
+ 0, // xBegin - begin transaction
+ 0, // xSync - sync transaction
+ 0, // xCommit - commit transaction
+ 0, // xRollback - rollback transaction
+ 0, // xFindFunction - function overloading
+ 0, // xRename - rename the table
+ 0, // xSavepoint
+ 0, // xRelease
+ 0 // xRollbackTo
+};
+
void goMDestroy(void*);
static int _sqlite3_create_module(sqlite3 *db, const char *zName, uintptr_t pClientData) {
return sqlite3_create_module_v2(db, zName, &goModule, (void*) pClientData, goMDestroy);
}
+
+static int _sqlite3_create_module_eponymous_only(sqlite3 *db, const char *zName, uintptr_t pClientData) {
+ return sqlite3_create_module_v2(db, zName, &goModuleEponymousOnly, (void*) pClientData, goMDestroy);
+}
*/
import "C"
@@ -595,6 +627,13 @@ type Module interface {
DestroyModule()
}
+// EponymousOnlyModule is a "virtual table module" (as above), but
+// for defining "eponymous only" virtual tables See: https://sqlite.org/vtab.html#eponymous_only_virtual_tables
+type EponymousOnlyModule interface {
+ Module
+ EponymousOnlyModule()
+}
+
// VTab describes a particular instance of the virtual table.
// See: http://sqlite.org/c3ref/vtab.html
type VTab interface {
@@ -652,9 +691,19 @@ func (c *SQLiteConn) CreateModule(moduleName string, module Module) error {
mname := C.CString(moduleName)
defer C.free(unsafe.Pointer(mname))
udm := sqliteModule{c, moduleName, module}
- rv := C._sqlite3_create_module(c.db, mname, C.uintptr_t(uintptr(newHandle(c, &udm))))
- if rv != C.SQLITE_OK {
- return c.lastError()
+ switch module.(type) {
+ case EponymousOnlyModule:
+ rv := C._sqlite3_create_module_eponymous_only(c.db, mname, C.uintptr_t(uintptr(newHandle(c, &udm))))
+ if rv != C.SQLITE_OK {
+ return c.lastError()
+ }
+ return nil
+ case Module:
+ rv := C._sqlite3_create_module(c.db, mname, C.uintptr_t(uintptr(newHandle(c, &udm))))
+ if rv != C.SQLITE_OK {
+ return c.lastError()
+ }
+ return nil
}
return nil
}