Skip to content

Commit 2de0fd2

Browse files
lovasoacursoragent
andauthored
Fix odbc column name type mismatch (#42)
* Fix: Decode column names using UTF-16 Co-authored-by: contact <[email protected]> * Checkpoint before follow-up message Co-authored-by: contact <[email protected]> * Checkpoint before follow-up message Co-authored-by: contact <[email protected]> * Fix: Remove unused linter directive Co-authored-by: contact <[email protected]> * Fix: Update CI and odbc bridge path Co-authored-by: contact <[email protected]> * Enhance CI configuration for unit tests by adding OS matrix support and removing the Windows build job * Refactor: Remove redundant comment about decode_column_name in odbc_bridge.rs * Fix: Normalize SQLite test paths to use forward slashes Co-authored-by: contact <[email protected]> * Fix: Normalize error message case in prepare statement test * Fix: Correct string replacement syntax for path normalization in SQLite tests --------- Co-authored-by: Cursor Agent <[email protected]>
1 parent 7b0e3af commit 2de0fd2

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

.github/workflows/sqlx.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,19 @@ jobs:
4848
-- -D warnings
4949
5050
test:
51-
name: Unit Test
52-
runs-on: ubuntu-24.04
51+
name: Unit Test ${{ matrix.os }}
52+
strategy:
53+
matrix:
54+
os: [ubuntu-latest, windows-latest]
55+
runs-on: ${{ matrix.os }}
5356
steps:
5457
- uses: actions/checkout@v4
5558
- uses: Swatinem/rust-cache@v2
5659
with:
5760
prefix-key: v1-sqlx
5861
save-if: ${{ false }}
5962
- run: sudo apt-get update && sudo apt-get install -y libodbc2 unixodbc-dev
63+
if: ${{ matrix.os == 'ubuntu-latest' }}
6064
- run: cargo test
6165
--manifest-path sqlx-core/Cargo.toml
6266
--features offline,all-databases,all-types,runtime-tokio-rustls

sqlx-core/src/odbc/connection/mod.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,24 @@ fn create_column(stmt: &mut PreparedStatement, index: u16) -> OdbcColumn {
4040
}
4141
}
4242

43-
fn decode_column_name(name_bytes: Vec<u8>, index: u16) -> String {
44-
String::from_utf8(name_bytes).unwrap_or_else(|_| format!("col{}", index - 1))
43+
pub(super) trait ColumnNameDecode {
44+
fn decode_or_default(self, index: u16) -> String;
45+
}
46+
47+
impl ColumnNameDecode for Vec<u8> {
48+
fn decode_or_default(self, index: u16) -> String {
49+
String::from_utf8(self).unwrap_or_else(|_| format!("col{}", index - 1))
50+
}
51+
}
52+
53+
impl ColumnNameDecode for Vec<u16> {
54+
fn decode_or_default(self, index: u16) -> String {
55+
String::from_utf16(&self).unwrap_or_else(|_| format!("col{}", index - 1))
56+
}
57+
}
58+
59+
pub(super) fn decode_column_name<T: ColumnNameDecode>(name: T, index: u16) -> String {
60+
name.decode_or_default(index)
4561
}
4662

4763
/// A connection to an ODBC-accessible database.

sqlx-core/src/odbc/connection/odbc_bridge.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use super::decode_column_name;
12
use crate::error::Error;
23
use crate::odbc::{
34
connection::MaybePrepared, OdbcArgumentValue, OdbcArguments, OdbcColumn, OdbcQueryResult,
@@ -139,10 +140,6 @@ where
139140
}
140141
}
141142

142-
fn decode_column_name(name_bytes: Vec<u8>, index: u16) -> String {
143-
String::from_utf8(name_bytes).unwrap_or_else(|_| format!("col{}", index - 1))
144-
}
145-
146143
fn stream_rows<C>(cursor: &mut C, columns: &[OdbcColumn], tx: &ExecuteSender) -> Result<bool, Error>
147144
where
148145
C: Cursor,

sqlx-core/src/sqlite/testing/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ fn convert_path(test_path: &str) -> String {
6868

6969
path.set_extension("sqlite");
7070

71-
path.into_os_string()
71+
let s = path
72+
.into_os_string()
7273
.into_string()
73-
.expect("path should be UTF-8")
74+
.expect("path should be UTF-8");
75+
s.replace("\\", "/")
7476
}
7577

7678
#[test]

tests/odbc/odbc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ async fn it_handles_prepare_statement_errors() -> anyhow::Result<()> {
794794
},
795795
Err(sqlx_oldapi::Error::Database(err)) => {
796796
assert!(
797-
err.to_string().contains("idonotexist"),
797+
err.to_string().to_lowercase().contains("idonotexist"),
798798
"{:?} should contain 'idonotexist'",
799799
err
800800
);

0 commit comments

Comments
 (0)