diff --git a/.github/workflows/sqlx.yml b/.github/workflows/sqlx.yml index 9bfd80d6aa..4f0094d74c 100644 --- a/.github/workflows/sqlx.yml +++ b/.github/workflows/sqlx.yml @@ -48,8 +48,11 @@ jobs: -- -D warnings test: - name: Unit Test - runs-on: ubuntu-24.04 + name: Unit Test ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - uses: Swatinem/rust-cache@v2 @@ -57,6 +60,7 @@ jobs: prefix-key: v1-sqlx save-if: ${{ false }} - run: sudo apt-get update && sudo apt-get install -y libodbc2 unixodbc-dev + if: ${{ matrix.os == 'ubuntu-latest' }} - run: cargo test --manifest-path sqlx-core/Cargo.toml --features offline,all-databases,all-types,runtime-tokio-rustls diff --git a/sqlx-core/src/odbc/connection/mod.rs b/sqlx-core/src/odbc/connection/mod.rs index 391f118351..8622de15cc 100644 --- a/sqlx-core/src/odbc/connection/mod.rs +++ b/sqlx-core/src/odbc/connection/mod.rs @@ -40,8 +40,24 @@ fn create_column(stmt: &mut PreparedStatement, index: u16) -> OdbcColumn { } } -fn decode_column_name(name_bytes: Vec, index: u16) -> String { - String::from_utf8(name_bytes).unwrap_or_else(|_| format!("col{}", index - 1)) +pub(super) trait ColumnNameDecode { + fn decode_or_default(self, index: u16) -> String; +} + +impl ColumnNameDecode for Vec { + fn decode_or_default(self, index: u16) -> String { + String::from_utf8(self).unwrap_or_else(|_| format!("col{}", index - 1)) + } +} + +impl ColumnNameDecode for Vec { + fn decode_or_default(self, index: u16) -> String { + String::from_utf16(&self).unwrap_or_else(|_| format!("col{}", index - 1)) + } +} + +pub(super) fn decode_column_name(name: T, index: u16) -> String { + name.decode_or_default(index) } /// A connection to an ODBC-accessible database. diff --git a/sqlx-core/src/odbc/connection/odbc_bridge.rs b/sqlx-core/src/odbc/connection/odbc_bridge.rs index d0e20262e3..01291ea2e9 100644 --- a/sqlx-core/src/odbc/connection/odbc_bridge.rs +++ b/sqlx-core/src/odbc/connection/odbc_bridge.rs @@ -1,3 +1,4 @@ +use super::decode_column_name; use crate::error::Error; use crate::odbc::{ connection::MaybePrepared, OdbcArgumentValue, OdbcArguments, OdbcColumn, OdbcQueryResult, @@ -139,10 +140,6 @@ where } } -fn decode_column_name(name_bytes: Vec, index: u16) -> String { - String::from_utf8(name_bytes).unwrap_or_else(|_| format!("col{}", index - 1)) -} - fn stream_rows(cursor: &mut C, columns: &[OdbcColumn], tx: &ExecuteSender) -> Result where C: Cursor, diff --git a/sqlx-core/src/sqlite/testing/mod.rs b/sqlx-core/src/sqlite/testing/mod.rs index f3e48e6b7c..74560f2818 100644 --- a/sqlx-core/src/sqlite/testing/mod.rs +++ b/sqlx-core/src/sqlite/testing/mod.rs @@ -68,9 +68,11 @@ fn convert_path(test_path: &str) -> String { path.set_extension("sqlite"); - path.into_os_string() + let s = path + .into_os_string() .into_string() - .expect("path should be UTF-8") + .expect("path should be UTF-8"); + s.replace("\\", "/") } #[test] diff --git a/tests/odbc/odbc.rs b/tests/odbc/odbc.rs index c22dbc054e..6ef7323085 100644 --- a/tests/odbc/odbc.rs +++ b/tests/odbc/odbc.rs @@ -794,7 +794,7 @@ async fn it_handles_prepare_statement_errors() -> anyhow::Result<()> { }, Err(sqlx_oldapi::Error::Database(err)) => { assert!( - err.to_string().contains("idonotexist"), + err.to_string().to_lowercase().contains("idonotexist"), "{:?} should contain 'idonotexist'", err );