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

Override fts5? #22

Open
xuxiaocheng0201 opened this issue Apr 17, 2024 · 6 comments
Open

Override fts5? #22

xuxiaocheng0201 opened this issue Apr 17, 2024 · 6 comments

Comments

@xuxiaocheng0201
Copy link

When I was loading this extension, the fts5 function was missing.

Used sqlite3_auto_extension in rusqlite

Dependencies

anyhow = "^1.0"
rusqlite = { version = "~0.31", features = ["bundled"] }
sqlite-regex = "0.2.4-alpha.1"

Code

use std::ffi::{c_char, c_int};

use anyhow::Result;
use rusqlite::Connection;
use rusqlite::ffi::{sqlite3, sqlite3_api_routines, sqlite3_auto_extension, SQLITE_OK};

fn main() -> Result<()> {
    unsafe extern "C" fn regex(db: *mut sqlite3, pz_err_msg: *mut *const c_char, p_api: *const sqlite3_api_routines) -> c_int {
        sqlite_regex::sqlite3_regex_init(db as _, pz_err_msg as _, p_api as _) as _
    }
    unsafe {
        assert_eq!(sqlite3_auto_extension(Some(regex)), SQLITE_OK);
    };
    let connection = Connection::open_in_memory()?;
    connection.prepare("SELECT fts5(?1)")?;
    Ok(())
}

But when I comment out these lines:

    unsafe {
        assert_eq!(sqlite3_auto_extension(Some(regex)), SQLITE_OK);
    };

it works.

Is there any error in my code? I'm curious why, these should be two unrelated extensions.

@xuxiaocheng0201
Copy link
Author

Output

Error: no such function: fts5 in SELECT fts5(?1) at offset 7

Caused by:
    Error code 1: SQL error or missing database

I also tested sqlite-regex = "0.2.3", but the same error.

@asg017
Copy link
Owner

asg017 commented Apr 17, 2024

Oooh that's not good. I think this has to do with a bug from a previous version of sqlite-regex, where it would accidentally link it's own version of sqlite3 instead of what rusqlite created. I thought it was fixed in 0.2.4-alpha.1.

I'm having trouble reproducing - I ran what you have but it seemed to work fine. A few questions:

  • Did you cargo clean before running that code-snippet? Hoping it's not some lingering build artifacts in target/ that's causing the issue
  • Can you print out the result of sqlite_version() In your code-snippet, before calling fts5()? The latest published version that rusqlite has should be 3.45.1, but for some reason locally I'm getting 3.45.0

Thanks for reporting!

@xuxiaocheng0201
Copy link
Author

I just run cargo clean, but unfortunately it output the same error.

The sqlite_version() is 3.39.4. I searched the source codes, it's in sqlite3ext-sys.

I cloned your two repositories, it works. and the sqlite_version() is 3.45.0

@asg017
Copy link
Owner

asg017 commented Apr 17, 2024

Ok cool, thanks for the info! So it does appear to be the issue I alluded to earlier - the 3.39.4 version definitely comes from sqlite3ext-sys, which should not be linked to in this case. That linked sqlite3 version also probably doesn't compile in the fts5 extension, which is causing the original error you reported here.

The sqlite-loadable crate is what depends on sqlite3ext-sys. However, when the static feature is enabled, it instead links to libsqlite3-sys. So the goal should be to enable the static feature on sqlite-loadable, which avoids sqlite3ext-sys and won't overwrite the sqlite3 linking.

Could you try something like this in your Cargo.toml?

sqlite-loadable = { version = "0.0.6-alpha.6", features=["static"]}

I tried this locally but ran into some version conflicts. Might need to push a new update to sqlite-regex for a proper fix

@xuxiaocheng0201
Copy link
Author

I encountered the same version conflicts.

error: failed to select a version for `libsqlite3-sys`.
    ... required by package `sqlite-loadable v0.0.6-alpha.6`
    ... which satisfies dependency `sqlite-loadable = "^0.0.6-alpha.6"` (locked to 0.0.6-alpha.6) of package `tester v0.1.0 (D:\Projects\tester)`
versions that meet the requirements `^0.26.0` are: 0.26.0

the package `libsqlite3-sys` links to the native library `sqlite3`, but it conflicts with a previous package which links to `sqlite3` as well:
package `libsqlite3-sys v0.28.0`
    ... which satisfies dependency `libsqlite3-sys = "^0.28.0"` (locked to 0.28.0) of package `rusqlite v0.31.0`
    ... which satisfies dependency `rusqlite = "~0.31"` (locked to 0.31.0) of package `tester v0.1.0 (D:\Projects\tester)`
Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the `links = "sqlite3"` value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.

failed to select a version for `libsqlite3-sys` which could resolve this conflict

@xuxiaocheng0201
Copy link
Author

Hi, I created a PR that may fix the conflicts. I hope you can merge it.

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.

2 participants