-
Notifications
You must be signed in to change notification settings - Fork 67
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
Enable the load extension API #39
Conversation
Expose the C API version of the enable load extension functionality. The SQL version is not enabled when calling EnableLoadExtension().
Add a function that attempts to visit all connections in a Pool. Allows for a timeout, same as Get() and others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, is it possible to write a test?
extension.go
Outdated
cext := C.CString(ext) | ||
defer C.free(unsafe.Pointer(cext)) | ||
var centry *C.char | ||
centry = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line doesn't do anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this All method into another PR. I'm not sure about it and it's unrelated to extensions.
Whoops, All snuck in somewhere, I'll send a new request. |
Sorry for the messy PR... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks! Few minor comments.
extension_test.go
Outdated
|
||
const ( | ||
extCode = ` | ||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can skip the copyright notice in a temporary file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, of course...
sqlite3_context *context, | ||
int argc, | ||
sqlite3_value **argv){ | ||
(void)argc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting style. is there a particular linter or guide you are working to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I started from the example on https://www.sqlite.org/loadext.html#write, and went from there. SQLite's style is similar, I substituted tabs for spaces.
extension_test.go
Outdated
defer func() { | ||
err := c.Close() | ||
if err != nil { | ||
t.Error(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.Error(err)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoops...
extension_test.go
Outdated
t.Fatal(err) | ||
} | ||
io.Copy(fout, strings.NewReader(extCode)) | ||
fout.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as you are writing a file, check the error here and on the copy.
as that gets tedious, use ioutile:
if err := ioutile.WriteFile(file path.Join(tmpdir, "ext.c")), []byte(extCode), 0666); err != nil {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood.
Thanks for the feedback, I'll make the final changes when I get a chance. |
As a side note, I added this so I could load the spatialite extension, but it seems Dr. Hipp is added base functionality as a new extension: https://sqlite.org/src/timeline?r=rtree-geopoly&nd&c=2018-08-23+14%3A54%3A45&n=200 I'm always amazed at the quality of SQLite. |
Allow enabling the load extension mechanism and actually loading extensions. This enables the C API only, not the SQL API.