Skip to content

Commit 08b44b3

Browse files
committed
SGA-11414 Added fixes from code review
1 parent d391aab commit 08b44b3

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
@@ -7465,12 +7465,15 @@ impl fmt::Display for TypedString {
74657465
write!(f, "{data_type}")?;
74667466
write!(f, " {value}")
74677467
}
7468-
true => match data_type {
7469-
DataType::Date => write!(f, "{{d {value}}}"),
7470-
DataType::Time(..) => write!(f, "{{t {value}}}"),
7471-
DataType::Timestamp(..) => write!(f, "{{ts {value}}}"),
7472-
_ => write!(f, "{{? {value}}}"),
7473-
},
7468+
true => {
7469+
let prefix = match data_type {
7470+
DataType::Date => "d",
7471+
DataType::Time(..) => "t",
7472+
DataType::Timestamp(..) => "ts",
7473+
_ => "?",
7474+
};
7475+
write!(f, "{{{prefix} {value}}}")
7476+
}
74747477
}
74757478
}
74767479
}

src/parser/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2030,8 +2030,12 @@ impl<'a> Parser<'a> {
20302030
})
20312031
}
20322032

2033-
// Tries to parse the body of an [ODBC escaping sequence]
2033+
/// Tries to parse the body of an [ODBC escaping sequence]
20342034
/// i.e. without the enclosing braces
2035+
/// Currently implemented:
2036+
/// Scalar Function Calls
2037+
/// Date, Time, and Timestamp Literals
2038+
/// See https://learn.microsoft.com/en-us/sql/odbc/reference/develop-app/escape-sequences-in-odbc?view=sql-server-2017
20352039
fn maybe_parse_odbc_body(&mut self) -> Result<Option<Expr>, ParserError> {
20362040
// Attempt 1: Try to parse it as a function.
20372041
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
@@ -16326,6 +16326,13 @@ fn test_odbc_time_date_timestamp_support() {
1632616326
let _ = all_dialects().verified_stmt(sql_ts);
1632716327
}
1632816328

16329+
#[test]
16330+
#[should_panic]
16331+
fn test_invalid_odbc_literal_fails() {
16332+
let sql = "SELECT {tt '14:12:01'} FROM foo";
16333+
let _ = all_dialects().verified_stmt(sql);
16334+
}
16335+
1632916336
#[test]
1633016337
fn parse_create_user() {
1633116338
let create = verified_stmt("CREATE USER u1");

0 commit comments

Comments
 (0)