Skip to content

Commit 1c64adb

Browse files
cursoragentlovasoa
andcommitted
Fix: Decode column names using UTF-16
Co-authored-by: contact <[email protected]>
1 parent 7b0e3af commit 1c64adb

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ 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+
fn decode_column_name(name_words: Vec<u16>, index: u16) -> String {
44+
match String::from_utf16(&name_words) {
45+
Ok(s) => s,
46+
Err(_) => format!("col{}", index - 1),
47+
}
4548
}
4649

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

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,11 @@ where
139139
}
140140
}
141141

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))
142+
fn decode_column_name(name_words: Vec<u16>, index: u16) -> String {
143+
match String::from_utf16(&name_words) {
144+
Ok(s) => s,
145+
Err(_) => format!("col{}", index - 1),
146+
}
144147
}
145148

146149
fn stream_rows<C>(cursor: &mut C, columns: &[OdbcColumn], tx: &ExecuteSender) -> Result<bool, Error>

0 commit comments

Comments
 (0)