Skip to content

Commit

Permalink
Add missing call to DatabaseInit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandreyc committed Apr 6, 2024
1 parent f0f7c8d commit 1ee7b6d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
13 changes: 9 additions & 4 deletions rust/src/driver_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ impl AdbcDriver {

check_status(status, error)?;

inner.private_driver = &self.inner.as_ref().driver;
inner.private_driver = &(self.inner.as_ref().driver);

Ok(DriverDatabaseBuilder {
inner,
Expand Down Expand Up @@ -381,11 +381,16 @@ impl DriverDatabaseBuilder {
Ok(self)
}

pub fn init(self) -> DriverDatabase {
DriverDatabase {
pub fn init(mut self) -> Result<DriverDatabase> {
let mut error = FFI_AdbcError::empty();
let database_init = driver_method!(self.driver, database_init);
let status = unsafe { database_init(&mut self.inner, &mut error) };
check_status(status, error)?;

Ok(DriverDatabase {
inner: Arc::new(RwLock::new(self.inner)),
driver: self.driver,
}
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
//!
//! # fn main() -> arrow_adbc::driver_manager::Result<()> {
//! let sqlite_driver = AdbcDriver::load("adbc_driver_sqlite", None, ADBC_VERSION_1_0_0)?;
//! let sqlite_database = sqlite_driver.new_database()?.init();
//! let sqlite_database = sqlite_driver.new_database()?.init()?;
//! let sqlite_conn = sqlite_database.new_connection()?.init()?;
//! let mut sqlite_statement = sqlite_conn.new_statement()?;
//!
Expand Down
2 changes: 1 addition & 1 deletion rust/tests/test_driver_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn get_database() -> Result<DriverDatabase> {
let driver = get_driver()?;
// By passing in "" for uri, we create a distinct temporary database for each
// test, preventing noisy neighbor issues on tests.
Ok(driver.new_database()?.set_option("uri", "")?.init())
Ok(driver.new_database()?.set_option("uri", "")?.init()?)
}

fn get_connection() -> Result<DriverConnection> {
Expand Down
12 changes: 9 additions & 3 deletions rust/tests/test_implement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,13 @@ macro_rules! set_driver_method {

fn get_connection() -> (DriverConnection, Arc<Mutex<PatchableDriver>>) {
let (builder, mock_driver) = get_database_builder();
let conn = builder.init().new_connection().unwrap().init().unwrap();
let conn = builder
.init()
.unwrap()
.new_connection()
.unwrap()
.init()
.unwrap();
(conn, mock_driver)
}

Expand All @@ -396,7 +402,7 @@ fn test_database_set_option() {
);

let builder = builder.set_option("test_key", "test value 😬").unwrap();
let database = builder.init();
let database = builder.init().unwrap();
database.set_option("test_key", "test value 😬").unwrap();

set_driver_method!(mock_driver, database_set_option, |_: &str, _: &str| {
Expand All @@ -411,7 +417,7 @@ fn test_database_set_option() {
#[test]
fn test_connection_set_option() {
let (builder, mock_driver) = get_database_builder();
let conn_builder = builder.init().new_connection().unwrap();
let conn_builder = builder.init().unwrap().new_connection().unwrap();

set_driver_method!(
mock_driver,
Expand Down

0 comments on commit 1ee7b6d

Please sign in to comment.