fix(sql): fix SQL keyword detection failure caused by leading parentheses
This commit is contained in:
parent
c63c9e451c
commit
c2a3f491cd
|
|
@ -1596,7 +1596,7 @@ fn first_executable_sql_token_with_options(sql: &str, options: SqlParsingOptions
|
|||
let mut i = 0;
|
||||
|
||||
while i < bytes.len() {
|
||||
while i < bytes.len() && bytes[i].is_ascii_whitespace() {
|
||||
while i < bytes.len() && (bytes[i].is_ascii_whitespace() || bytes[i] == b'(') {
|
||||
i += 1;
|
||||
}
|
||||
|
||||
|
|
@ -2123,6 +2123,16 @@ mod tests {
|
|||
assert!(starts_with_executable_sql_keyword("-- comment\nDESC users", &["DESCRIBE"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn detects_keyword_after_parentheses() {
|
||||
assert!(starts_with_executable_sql_keyword("(SELECT 1)", &["SELECT"]));
|
||||
assert!(starts_with_executable_sql_keyword(" ( SELECT 1 )", &["SELECT"]));
|
||||
assert!(starts_with_executable_sql_keyword("((SELECT 1))", &["SELECT"]));
|
||||
assert!(starts_with_executable_sql_keyword("(SELECT * FROM users)", &["SELECT"]));
|
||||
assert!(starts_with_executable_sql_keyword("(INSERT INTO users VALUES (1))", &["INSERT"]));
|
||||
assert!(starts_with_executable_sql_keyword("/* comment */(UPDATE users SET name = 'test')", &["UPDATE"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mysql_hash_comments_are_ignored_for_keyword_detection() {
|
||||
assert!(starts_with_executable_sql_keyword_for_database(
|
||||
|
|
|
|||
Loading…
Reference in New Issue