Skip to content

Commit

Permalink
provide one more required argument for SQLITE_DBCONFIG_ENABLE_LOAD_EX…
Browse files Browse the repository at this point in the history
…TENSION config command

- see tursodatabase#1473
  • Loading branch information
sivukhin committed Jun 15, 2024
1 parent fbce426 commit de4c5b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libsql/src/local/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ impl Connection {
}

pub fn enable_load_extension(&self, onoff: bool) -> Result<()> {
let err = unsafe { ffi::sqlite3_db_config(self.raw, ffi::SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, onoff as i32) };
// SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION configration verb accepts 2 additional parameters: an on/off flag and a pointer to an c_int where new state of the parameter will be written (or NULL if reporting back the setting is not needed)
// See: https://sqlite.org/c3ref/c_dbconfig_defensive.html#sqlitedbconfigenableloadextension
let err = unsafe { ffi::sqlite3_db_config(self.raw, ffi::SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, onoff as i32, std::ptr::null::<c_int>()) };
match err {
ffi::SQLITE_OK => Ok(()),
_ => Err(errors::Error::SqliteFailure(err, errors::error_from_code(err))),
Expand Down
8 changes: 8 additions & 0 deletions libsql/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ async fn setup() -> Connection {
conn
}

#[tokio::test]
async fn enable_disable_extension() {
let db = Database::open(":memory:").unwrap();
let conn = db.connect().unwrap();
conn.load_extension_enable().unwrap();
conn.load_extension_disable().unwrap();
}

#[tokio::test]
async fn connection_drops_before_statements() {
let db = Database::open(":memory:").unwrap();
Expand Down

0 comments on commit de4c5b4

Please sign in to comment.