Skip to content

Commit 8466a4e

Browse files
committed
SGA-11414 Added fixes from code review
1 parent d9bb81c commit 8466a4e

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
@@ -7422,12 +7422,15 @@ impl fmt::Display for TypedString {
74227422
write!(f, "{data_type}")?;
74237423
write!(f, " {value}")
74247424
}
7425-
true => match data_type {
7426-
DataType::Date => write!(f, "{{d {value}}}"),
7427-
DataType::Time(..) => write!(f, "{{t {value}}}"),
7428-
DataType::Timestamp(..) => write!(f, "{{ts {value}}}"),
7429-
_ => write!(f, "{{? {value}}}"),
7430-
},
7425+
true => {
7426+
let prefix = match data_type {
7427+
DataType::Date => "d",
7428+
DataType::Time(..) => "t",
7429+
DataType::Timestamp(..) => "ts",
7430+
_ => "?",
7431+
};
7432+
write!(f, "{{{prefix} {value}}}")
7433+
}
74317434
}
74327435
}
74337436
}

src/parser/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,8 +2018,12 @@ impl<'a> Parser<'a> {
20182018
})
20192019
}
20202020

2021-
// Tries to parse the body of an [ODBC escaping sequence]
2021+
/// Tries to parse the body of an [ODBC escaping sequence]
20222022
/// i.e. without the enclosing braces
2023+
/// Currently implemented:
2024+
/// Scalar Function Calls
2025+
/// Date, Time, and Timestamp Literals
2026+
/// See https://learn.microsoft.com/en-us/sql/odbc/reference/develop-app/escape-sequences-in-odbc?view=sql-server-2017
20232027
fn maybe_parse_odbc_body(&mut self) -> Result<Option<Expr>, ParserError> {
20242028
// Attempt 1: Try to parse it as a function.
20252029
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
@@ -16209,3 +16209,10 @@ fn test_odbc_time_date_timestamp_support() {
1620916209
let sql_ts = "SELECT {ts '2025-07-17 14:12:01'}, category_name FROM categories";
1621016210
let _ = all_dialects().verified_stmt(sql_ts);
1621116211
}
16212+
16213+
#[test]
16214+
#[should_panic]
16215+
fn test_invalid_odbc_literal_fails() {
16216+
let sql = "SELECT {tt '14:12:01'} FROM foo";
16217+
let _ = all_dialects().verified_stmt(sql);
16218+
}

0 commit comments

Comments
 (0)