Skip to content

Commit d41b69e

Browse files
cursoragentlovasoa
andcommitted
feat: Improve ODBC connection string parsing
Co-authored-by: contact <[email protected]>
1 parent 4ec590f commit d41b69e

File tree

1 file changed

+17
-5
lines changed
  • sqlx-core/src/odbc/options

1 file changed

+17
-5
lines changed

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,23 @@ impl FromStr for OdbcConnectOptions {
3232
type Err = Error;
3333

3434
fn from_str(s: &str) -> Result<Self, Self::Err> {
35-
// Use full string as ODBC connection string or DSN
36-
Ok(Self {
37-
conn_str: s.to_owned(),
38-
log_settings: LogSettings::default(),
39-
})
35+
// Accept forms:
36+
// - "odbc:DSN=Name;..." -> strip scheme
37+
// - "odbc:Name" -> interpret as DSN
38+
// - "DSN=Name;..." or full ODBC connection string
39+
let mut t = s.trim();
40+
if let Some(rest) = t.strip_prefix("odbc:") {
41+
t = rest;
42+
}
43+
let conn_str = if t.contains('=') {
44+
// Looks like an ODBC key=value connection string
45+
t.to_string()
46+
} else {
47+
// Bare DSN name
48+
format!("DSN={}", t)
49+
};
50+
51+
Ok(Self { conn_str, log_settings: LogSettings::default() })
4052
}
4153
}
4254

0 commit comments

Comments
 (0)