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

How can I access to the underlying sqlite3 handle? #21

Closed
trlim opened this issue Feb 22, 2015 · 9 comments · Fixed by #22
Closed

How can I access to the underlying sqlite3 handle? #21

trlim opened this issue Feb 22, 2015 · 9 comments · Fixed by #22

Comments

@trlim
Copy link

trlim commented Feb 22, 2015

I want to make some ffi calls after opening a connection but accessing db fails because it is private.
I think there should be a function for that purpose but couldn't find.

@marcusklaas
Copy link
Contributor

I'm not sure if that is within the scope of this project. Ideally, you'd interact with the connection through native rust calls. If there is functionality only accessible through ffi calls, that should be added to the library.

@jgallagher
Copy link
Contributor

I'm not necessarily opposed to adding an unsafe escape hatch to grab the database handle, but I agree with @marcusklaas - if there's functionality for which you need the handle, we should probably wrap it in the library. What ffi calls do you need to make?

@trlim
Copy link
Author

trlim commented Feb 22, 2015

To enable extension loading with sqlite3_enable_load_extension().

let mut conn = ...;
unsafe {
  ffi.sqlite3_enable_load_extension(conn.sqlite(), 1);
}
try!(conn.execute("SELECT load_extension('spatialite');", &[]));
unsafe {
  // Disable further loading of extension
  ffi.sqlite3_enable_load_extension(conn.sqlite(), 0);
}

@jgallagher
Copy link
Contributor

Gotcha. I will add that to the library - look for a new version later today. (Will ping here too.)

@jgallagher
Copy link
Contributor

@trlim : Version 0.0.10 should now enable you to do this:

fn load_my_extension(conn: &SqliteConnection) -> SqliteResult<()> {
     let _guard = try!(SqliteLoadExtensionGuard::new(conn));

     // or use the SELECT version, that's fine too
     conn.load_extension(Path::new("spatialite"), None)
}

but you'll need to add the load_extension feature to the rusqlite dependency in Cargo.toml. Please let me know (reopen this issue or open a new one) if this doesn't work for you.

@trlim
Copy link
Author

trlim commented Feb 24, 2015

It works! Thank you.

@dckc
Copy link

dckc commented Jan 23, 2016

In my bindings, I included an unsafe expose method so that clients can use it with the ffi bindings.

I bring this up because my bindings are in most ways subsumed by yours and I'd just as soon get rid of mine if they're not novel.

Is it worth re-opening this issue? (Does github even support that?)

@jgallagher jgallagher reopened this Feb 1, 2016
@jgallagher
Copy link
Contributor

@dckc I'm not necessarily opposed to an expose method, but I'd view any uses of it as an indication that rusqlite's coverage of SQLite is insufficient. (I suppose we could put a "please open an issue if you need to use this" in the docs for it.) Are there any client uses of it that you know of that aren't possible with the lib?

@dckc
Copy link

dckc commented Feb 1, 2016

No, I'm not aware of any actual use of the expose method.

Yes, I agree that use of it indicates that this library should be enhanced.

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