Skip to content

Conversation

@gwd
Copy link

@gwd gwd commented Oct 21, 2025

This is necessary, for instance, to allow users of the package to make
their own CGo callbacks, and have the underlying sqlite3 library call
those C functions directly.

Note that the intention from the sqlite3 library seems to be that
there should be a measure of binary compatibility between versions:
even extensions compiled against an older different version of sqlite3
should be able to call sqlite3_create_function with no problems. So
this should work even if users of the package have a slightly
different version of the sqlite3.h header.

Note that the code itself was written by @rittneje. I tested it and
wrote the comments.

Signed-off-by: George Dunlap [email protected]

v2:
Just copy @rittneje's code exactly:

  • Grab the lock while the function is running
  • Replace the error code with our own if it's of type ErrNo

gwd added 2 commits October 21, 2025 17:00
…text structure

This is necessary, for instance, to allow users of the package to make
their own CGo callbacks, and have the underlying sqlite3 library call
those C functions directly.

Note that the intention from the sqlite3 library seems to be that
there should be a measure of binary compatibility between versions:
even extensions compiled against an older different version of sqlite3
should be able to call sqlite3_create_function with no problems. So
this should work even if users of the package have a slightly
different version of the sqlite3.h header.

Note that the code itself was written by @rittneje.  I tested it and
wrote the comments.

Signed-off-by: George Dunlap <[email protected]>

v2:
Just copy @rittneje's code exactly:
- Grab the lock while the function is running
- Replace the error code with our own if it's of type ErrNo
Note that you can't call cgo from within a test file; so in order to
test the functionality, create new package, .../internal/sqlite3test,
to define the callback.  Then in the main sqlite3 package, add a test
file which includes this package and calls the callback.

As with the previous commit, the idea and the basic code was written
by @rittneje; I massaged it so that it compiled and passed with Go
1.9, and wrote this commit message and the comments.

NB that Golang 1.9 doesn't have sql.OpenDB, so we have to register a
new database driver.

Signed-off-by: George Dunlap <[email protected]>

v4:
- Refactor to get rid of sql.OpenDB call, which only appeared in Go
  1.10

v3:
- New
@gwd
Copy link
Author

gwd commented Oct 21, 2025

This is a rebased / re-opened version of #784, which got closed when I accidentally deleted the backing branch from github.

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 this pull request may close these issues.

1 participant