Skip to content

Commit bf3a5b7

Browse files
cursoragentlovasoa
andcommitted
Checkpoint before follow-up message
Co-authored-by: contact <[email protected]>
1 parent 1c64adb commit bf3a5b7

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

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

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

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),
43+
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))
4750
}
4851
}
4952

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+
fn decode_column_name<T: ColumnNameDecode>(name: T, index: u16) -> String {
60+
name.decode_or_default(index)
61+
}
62+
5063
/// A connection to an ODBC-accessible database.
5164
///
5265
/// ODBC uses a blocking C API, so we offload blocking calls to the runtime's blocking

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,26 @@ where
139139
}
140140
}
141141

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),
142+
trait ColumnNameDecode {
143+
fn decode_or_default(self, index: u16) -> String;
144+
}
145+
146+
impl ColumnNameDecode for Vec<u8> {
147+
fn decode_or_default(self, index: u16) -> String {
148+
String::from_utf8(self).unwrap_or_else(|_| format!("col{}", index - 1))
146149
}
147150
}
148151

152+
impl ColumnNameDecode for Vec<u16> {
153+
fn decode_or_default(self, index: u16) -> String {
154+
String::from_utf16(&self).unwrap_or_else(|_| format!("col{}", index - 1))
155+
}
156+
}
157+
158+
fn decode_column_name<T: ColumnNameDecode>(name: T, index: u16) -> String {
159+
name.decode_or_default(index)
160+
}
161+
149162
fn stream_rows<C>(cursor: &mut C, columns: &[OdbcColumn], tx: &ExecuteSender) -> Result<bool, Error>
150163
where
151164
C: Cursor,

0 commit comments

Comments
 (0)