Skip to content
Merged
8 changes: 6 additions & 2 deletions .github/workflows/sqlx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,19 @@ 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
with:
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
Expand Down
20 changes: 18 additions & 2 deletions sqlx-core/src/odbc/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,24 @@ fn create_column(stmt: &mut PreparedStatement, index: u16) -> OdbcColumn {
}
}

fn decode_column_name(name_bytes: Vec<u8>, 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<u8> {
fn decode_or_default(self, index: u16) -> String {
String::from_utf8(self).unwrap_or_else(|_| format!("col{}", index - 1))
}
}

impl ColumnNameDecode for Vec<u16> {
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<T: ColumnNameDecode>(name: T, index: u16) -> String {
name.decode_or_default(index)
}

/// A connection to an ODBC-accessible database.
Expand Down
5 changes: 1 addition & 4 deletions sqlx-core/src/odbc/connection/odbc_bridge.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::decode_column_name;
use crate::error::Error;
use crate::odbc::{
connection::MaybePrepared, OdbcArgumentValue, OdbcArguments, OdbcColumn, OdbcQueryResult,
Expand Down Expand Up @@ -139,10 +140,6 @@ where
}
}

fn decode_column_name(name_bytes: Vec<u8>, index: u16) -> String {
String::from_utf8(name_bytes).unwrap_or_else(|_| format!("col{}", index - 1))
}

fn stream_rows<C>(cursor: &mut C, columns: &[OdbcColumn], tx: &ExecuteSender) -> Result<bool, Error>
where
C: Cursor,
Expand Down
6 changes: 4 additions & 2 deletions sqlx-core/src/sqlite/testing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/odbc/odbc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
Loading