diff --git a/CHANGELOG.md b/CHANGELOG.md index b508748..a41d970 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +* Implemented `Connection::get_option_string()` for `OptionConnection::AutoCommit` + (always `"true"`, as ClickHouse has no transactions) and `OptionConnection::CurrentCatalog` + (always empty, as ClickHouse has no catalog level above the database). ([#65]) + +[#65]: https://github.com/ClickHouse/adbc_clickhouse/pull/65 + ## [0.1.2] - 2026-11-06 ### Fixed diff --git a/src/lib.rs b/src/lib.rs index 26b5bed..d74e7f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -801,21 +801,39 @@ impl Optionable for ClickhouseConnection { Status::NotFound, ) }), + // ClickHouse has no transactions, so every statement commits as it runs. + // Driver managers read this back before using a connection. + OptionConnection::AutoCommit => Ok("true".into()), + // ClickHouse has no catalog level above the database (an ADBC schema), + // so the catalog is always empty rather than unsupported. + OptionConnection::CurrentCatalog => Ok(String::new()), OptionConnection::Other(s) => self.get_custom_option(&s), - other => err_unimplemented!("ClickhouseConnection::get_option_string({other:?})"), + other => Err(Error::with_message_and_status( + format!("unimplemented connection option: {:?}", other.as_ref()), + Status::NotImplemented, + )), } } fn get_option_bytes(&self, key: Self::Option) -> adbc_core::error::Result> { - err_unimplemented!("ClickhouseConnection::get_option_bytes({key:?})") + // There's no options that are specifically binary-only, so... *shrug* + self.get_option_string(key).map(String::into_bytes) } fn get_option_int(&self, key: Self::Option) -> adbc_core::error::Result { - err_unimplemented!("ClickhouseConnection::get_option_int({key:?})") + // Currently no connection options that can be integers + Err(Error::with_message_and_status( + format!("option {:?} is not an integer", key.as_ref()), + Status::InvalidArguments, + )) } fn get_option_double(&self, key: Self::Option) -> adbc_core::error::Result { - err_unimplemented!("ClickhouseConnection::get_option_double({key:?})") + // Currently no connection options that can be doubles + Err(Error::with_message_and_status( + format!("option {:?} is not a double", key.as_ref()), + Status::InvalidArguments, + )) } } diff --git a/tests/it/main.rs b/tests/it/main.rs index f990b70..9f6c5c6 100644 --- a/tests/it/main.rs +++ b/tests/it/main.rs @@ -1,5 +1,6 @@ use adbc_clickhouse::options; -use adbc_core::options::{OptionDatabase, OptionStatement}; +use adbc_core::error::Status; +use adbc_core::options::{OptionConnection, OptionDatabase, OptionStatement}; use adbc_core::{Connection, Database, Driver, Optionable, Statement}; use arrow_array::cast::AsArray; use arrow_array::types::Int32Type; @@ -327,6 +328,45 @@ fn execute_handles_no_result_set_statements() { assert_eq!(joined, expected); } +#[test] +fn connection_option_getters() { + let db = test_database(); + let conn = db.new_connection().unwrap(); + + assert_eq!( + conn.get_option_string(OptionConnection::AutoCommit) + .unwrap(), + "true" + ); + assert_eq!( + conn.get_option_string(OptionConnection::CurrentCatalog) + .unwrap(), + "" + ); + + for option in [OptionConnection::IsolationLevel, OptionConnection::ReadOnly] { + let err = conn.get_option_string(option).unwrap_err(); + assert_eq!(err.status, Status::NotImplemented); + } + + assert_eq!( + conn.get_option_bytes(OptionConnection::AutoCommit).unwrap(), + b"true" + ); + assert_eq!( + conn.get_option_int(OptionConnection::AutoCommit) + .unwrap_err() + .status, + Status::InvalidArguments + ); + assert_eq!( + conn.get_option_double(OptionConnection::AutoCommit) + .unwrap_err() + .status, + Status::InvalidArguments + ); +} + #[test] fn query_with_product_info() { // Note: may be `ManagedStatement` if using the `ffi` feature.