Skip to content

Commit a0eb9c1

Browse files
committed
SGA-11414 Added fixes from code review
1 parent 5806971 commit a0eb9c1

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/ast/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7448,12 +7448,15 @@ impl fmt::Display for TypedString {
74487448
write!(f, "{data_type}")?;
74497449
write!(f, " {value}")
74507450
}
7451-
true => match data_type {
7452-
DataType::Date => write!(f, "{{d {value}}}"),
7453-
DataType::Time(..) => write!(f, "{{t {value}}}"),
7454-
DataType::Timestamp(..) => write!(f, "{{ts {value}}}"),
7455-
_ => write!(f, "{{? {value}}}"),
7456-
},
7451+
true => {
7452+
let prefix = match data_type {
7453+
DataType::Date => "d",
7454+
DataType::Time(..) => "t",
7455+
DataType::Timestamp(..) => "ts",
7456+
_ => "?",
7457+
};
7458+
write!(f, "{{{prefix} {value}}}")
7459+
}
74577460
}
74587461
}
74597462
}

src/parser/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2025,8 +2025,12 @@ impl<'a> Parser<'a> {
20252025
})
20262026
}
20272027

2028-
// Tries to parse the body of an [ODBC escaping sequence]
2028+
/// Tries to parse the body of an [ODBC escaping sequence]
20292029
/// i.e. without the enclosing braces
2030+
/// Currently implemented:
2031+
/// Scalar Function Calls
2032+
/// Date, Time, and Timestamp Literals
2033+
/// See https://learn.microsoft.com/en-us/sql/odbc/reference/develop-app/escape-sequences-in-odbc?view=sql-server-2017
20302034
fn maybe_parse_odbc_body(&mut self) -> Result<Option<Expr>, ParserError> {
20312035
// Attempt 1: Try to parse it as a function.
20322036
if let Some(expr) = self.maybe_parse_odbc_fn_body()? {

tests/sqlparser_common.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16291,3 +16291,10 @@ fn test_odbc_time_date_timestamp_support() {
1629116291
let sql_ts = "SELECT {ts '2025-07-17 14:12:01'}, category_name FROM categories";
1629216292
let _ = all_dialects().verified_stmt(sql_ts);
1629316293
}
16294+
16295+
#[test]
16296+
#[should_panic]
16297+
fn test_invalid_odbc_literal_fails() {
16298+
let sql = "SELECT {tt '14:12:01'} FROM foo";
16299+
let _ = all_dialects().verified_stmt(sql);
16300+
}

0 commit comments

Comments
 (0)