From 1ee7b6deef24be50be0ef9e4c1815f78e6643e7a Mon Sep 17 00:00:00 2001 From: alexandreyc Date: Wed, 21 Feb 2024 17:59:19 +0100 Subject: [PATCH] Add missing call to DatabaseInit --- rust/src/driver_manager.rs | 13 +++++++++---- rust/src/lib.rs | 2 +- rust/tests/test_driver_manager.rs | 2 +- rust/tests/test_implement.rs | 12 +++++++++--- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/rust/src/driver_manager.rs b/rust/src/driver_manager.rs index 2e815cb46e..93cb8e8462 100644 --- a/rust/src/driver_manager.rs +++ b/rust/src/driver_manager.rs @@ -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, @@ -381,11 +381,16 @@ impl DriverDatabaseBuilder { Ok(self) } - pub fn init(self) -> DriverDatabase { - DriverDatabase { + pub fn init(mut self) -> Result { + 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, - } + }) } } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index c46da3aeeb..19a6b140f5 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -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()?; //! diff --git a/rust/tests/test_driver_manager.rs b/rust/tests/test_driver_manager.rs index f88144c95d..3d28e91147 100644 --- a/rust/tests/test_driver_manager.rs +++ b/rust/tests/test_driver_manager.rs @@ -45,7 +45,7 @@ fn get_database() -> Result { 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 { diff --git a/rust/tests/test_implement.rs b/rust/tests/test_implement.rs index 04905b15f3..033ec410f8 100644 --- a/rust/tests/test_implement.rs +++ b/rust/tests/test_implement.rs @@ -377,7 +377,13 @@ macro_rules! set_driver_method { fn get_connection() -> (DriverConnection, Arc>) { 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) } @@ -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| { @@ -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,