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

Enable the load extension API #39

Merged
merged 14 commits into from
Aug 25, 2018
Merged

Enable the load extension API #39

merged 14 commits into from
Aug 25, 2018

Conversation

ksshannon
Copy link
Contributor

Allow enabling the load extension mechanism and actually loading extensions. This enables the C API only, not the SQL API.

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.
Copy link
Owner

@crawshaw crawshaw left a 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
Copy link
Owner

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

Copy link
Owner

@crawshaw crawshaw left a 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.

@ksshannon
Copy link
Contributor Author

Whoops, All snuck in somewhere, I'll send a new request.

@ksshannon
Copy link
Contributor Author

Sorry for the messy PR...

Copy link
Owner

@crawshaw crawshaw left a 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.


const (
extCode = `
/*
Copy link
Owner

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.

Copy link
Contributor Author

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;
Copy link
Owner

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?

Copy link
Contributor Author

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.

defer func() {
err := c.Close()
if err != nil {
t.Error(nil)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t.Error(err)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops...

t.Fatal(err)
}
io.Copy(fout, strings.NewReader(extCode))
fout.Close()
Copy link
Owner

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 {
...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood.

@ksshannon
Copy link
Contributor Author

Thanks for the feedback, I'll make the final changes when I get a chance.

@ksshannon
Copy link
Contributor Author

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.

@crawshaw crawshaw merged commit ac13ea4 into crawshaw:master Aug 25, 2018
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.

2 participants