Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eponymous-only virtual tables #846

Closed
anacrolix opened this issue Aug 26, 2020 · 6 comments · Fixed by #885
Closed

Eponymous-only virtual tables #846

anacrolix opened this issue Aug 26, 2020 · 6 comments · Fixed by #885

Comments

@anacrolix
Copy link

Does this package support eponymous-only virtual tables? I see some vtable related files that have the sqlite_vtable and vtable build tags, but I can't tell if they would allow a NULL xCreate.

@mattn
Copy link
Owner

mattn commented Aug 26, 2020

Did you try to build with -tags sqlite_vtable ?

@rittneje
Copy link
Collaborator

It doesn't support them. This repo hard-codes xCreate to a function that ultimately calls the Create method on the Module interface implementation. Consequently, there is no mechanism at present to cause it to be null.

static sqlite3_module goModule = {
0, // iVersion
cXCreate, // xCreate - create a table
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
};

@anacrolix
Copy link
Author

Thank you @rittneje

@patrickdevivo
Copy link
Contributor

Thank you @rittneje for providing context, coming across this issue when searching around for eponymous virtual table in this library and this is very helpful. Based on the current implementation, do you think it would be possible to implement a means of passing a null as the xCreate method? Unfortunately, I don't have much experience with c/cgo, but would love to experiment (ideally with some guidance!) to try adding support for eponymous virtual tables in this package. The current virtual table implementation is really cool and has been doing quite a bit of heavy lifting in a project I've been building!

@rittneje
Copy link
Collaborator

rittneje commented Dec 1, 2020

One option I can think of is to add an optional interface. Something like:

type EponymousOnlyModule interface {
    Module
    EponymousOnlyModule()
}

Then you could say that if the module implements EponymousOnlyModule(), then xCreate should be null and the Create method is ignored. Regular modules will not define the EponymousOnlyModule() method at all.

In terms of the sqlite3_module object, the simplest approach is to copy the goModule object (except set xCreate to null), and then choose one or the other in CreateModule.

patrickdevivo added a commit to patrickdevivo/go-sqlite3 that referenced this issue Dec 2, 2020
patrickdevivo added a commit to patrickdevivo/go-sqlite3 that referenced this issue Dec 2, 2020
patrickdevivo added a commit to patrickdevivo/go-sqlite3 that referenced this issue Dec 2, 2020
@patrickdevivo
Copy link
Contributor

@rittneje FYI #885 attempts to implement what you suggested above - would love any feedback if you're available! Thanks again for the help!

mattn pushed a commit that referenced this issue Dec 26, 2020
* add support for defining an "eponymous only" virtual table

As suggested here: #846 (comment)

* add an example of an eponymous only vtab module

* add a test case for an eponymous only vtab module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants