From d9da836feab2967dc7ae7e49cebb64e94ec66657 Mon Sep 17 00:00:00 2001 From: Markus Klein Date: Mon, 29 Jan 2024 08:22:58 +0100 Subject: [PATCH] Fix list attributes --- Cargo.lock | 4 ++-- Changelog.md | 4 ++++ odbc-api/Cargo.toml | 2 +- odbc-api/src/environment.rs | 18 ++++++++++-------- odbc-api/tests/integration.rs | 1 - odbcsv/Cargo.toml | 4 ++-- odbcsv/Changelog.md | 4 ++++ 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f22389da..97e939da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -944,7 +944,7 @@ dependencies = [ [[package]] name = "odbc-api" -version = "6.0.0" +version = "6.0.1" dependencies = [ "anyhow", "atoi", @@ -971,7 +971,7 @@ checksum = "6c219b6a4cd9eb167239d921d7348132cdff2eca05abbf1094e7f7ec9b8936b6" [[package]] name = "odbcsv" -version = "1.0.4" +version = "1.0.5" dependencies = [ "anyhow", "assert_cmd", diff --git a/Changelog.md b/Changelog.md index aa914aa7..1a5b6cc7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,9 @@ # Changelog +## 6.0.1 + +* Fixes an issue with `Environment::drivers`, which caused it to have at most one driver attribute in the `DriverInfo` attributes. + ## 6.0.0 * `ConcurrentBlockCursor::from_block_cursor` is now infalliable. diff --git a/odbc-api/Cargo.toml b/odbc-api/Cargo.toml index 8ea74c56..884c9400 100644 --- a/odbc-api/Cargo.toml +++ b/odbc-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "odbc-api" -version = "6.0.0" +version = "6.0.1" authors = ["Markus Klein"] edition = "2021" license = "MIT" diff --git a/odbc-api/src/environment.rs b/odbc-api/src/environment.rs index 08db80f0..bbcca440 100644 --- a/odbc-api/src/environment.rs +++ b/odbc-api/src/environment.rs @@ -3,7 +3,10 @@ use std::{cmp::max, collections::HashMap, ptr::null_mut, sync::Mutex}; use crate::{ connection::ConnectionOptions, error::ExtendResult, - handles::{self, log_diagnostics, OutputStringBuffer, SqlResult, SqlText, State, SzBuffer}, + handles::{ + self, log_diagnostics, slice_to_utf8, OutputStringBuffer, SqlChar, SqlResult, SqlText, + State, SzBuffer, + }, Connection, DriverCompleteOption, Error, }; use log::debug; @@ -506,19 +509,18 @@ impl Environment { // Allocate +1 character extra for terminating zero let mut desc_buf = SzBuffer::with_capacity(desc_len as usize); - let mut attr_buf = SzBuffer::with_capacity(attr_len as usize); + // Do **not** use nul terminated buffer, as nul is used to delimit key value pairs of + // attributes. + let mut attr_buf: Vec = vec![0; attr_len as usize]; while self .environment - .drivers_buffer_fill( - FetchOrientation::Next, - desc_buf.mut_buf(), - attr_buf.mut_buf(), - ) + .drivers_buffer_fill(FetchOrientation::Next, desc_buf.mut_buf(), &mut attr_buf) .into_result_bool(&self.environment)? { let description = desc_buf.to_utf8(); - let attributes = attr_buf.to_utf8(); + let attributes = + slice_to_utf8(&attr_buf).expect("Attributes must be interpretable as UTF-8"); let attributes = attributes_iter(&attributes).collect(); diff --git a/odbc-api/tests/integration.rs b/odbc-api/tests/integration.rs index f51eb34f..9e82cdd7 100644 --- a/odbc-api/tests/integration.rs +++ b/odbc-api/tests/integration.rs @@ -4317,7 +4317,6 @@ fn concurrent_fetch_skip_first_result_set(profile: &Profile) { /// ) in which we used a buffer intended for zero /// terminated strings to get the attributes. Yet the attributes use the `0` as a delimiter. #[test] -#[should_panic] // Bug not fixed yet fn list_all_driver_attributes() { // Given an ODBC environment with drivers installed let environment = &ENV; diff --git a/odbcsv/Cargo.toml b/odbcsv/Cargo.toml index d58293a5..57dcd48a 100644 --- a/odbcsv/Cargo.toml +++ b/odbcsv/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "odbcsv" -version = "1.0.4" +version = "1.0.5" authors = ["Markus Klein"] edition = "2021" license = "MIT" @@ -29,7 +29,7 @@ readme = "Readme.md" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -odbc-api = { version = "6.0.0", path = "../odbc-api" } +odbc-api = { version = "6.0.1", path = "../odbc-api" } csv = "1.3.0" anyhow = "1.0.79" stderrlog = "0.5.4" diff --git a/odbcsv/Changelog.md b/odbcsv/Changelog.md index a0fe86c5..acaf8860 100644 --- a/odbcsv/Changelog.md +++ b/odbcsv/Changelog.md @@ -1,5 +1,9 @@ # Changelog +## 1.0.5 + +* Fixes an issue causing `list-drivers` subcommand to only list one attribute. Now all attributes are listed. + ## 1.0.4 * Updated dependencies