Skip to content

Commit e306752

Browse files
committed
Enable parsing comma lists without semicolons
1 parent 0d18dfc commit e306752

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

src/parser/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4536,6 +4536,18 @@ impl<'a> Parser<'a> {
45364536
return Ok(vec![]);
45374537
}
45384538

4539+
if end_token == Token::SemiColon
4540+
&& self
4541+
.dialect
4542+
.supports_statements_without_semicolon_delimiter()
4543+
{
4544+
if let Token::Word(ref kw) = self.peek_token().token {
4545+
if kw.keyword != Keyword::NoKeyword {
4546+
return Ok(vec![]);
4547+
}
4548+
}
4549+
}
4550+
45394551
if self.options.trailing_commas && self.peek_tokens() == [Token::Comma, end_token] {
45404552
let _ = self.consume_token(&Token::Comma);
45414553
return Ok(vec![]);

tests/sqlparser_mssql.rs

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,4 +2830,109 @@ fn test_supports_statements_without_semicolon_delimiter() {
28302830
},
28312831
}
28322832
);
2833+
2834+
let exec_then_update = "\
2835+
EXEC my_sp \
2836+
UPDATE my_table SET col = 1 \
2837+
";
2838+
assert_eq!(
2839+
parse_n_statements(2, exec_then_update),
2840+
vec![
2841+
Statement::Execute {
2842+
name: Some(ObjectName::from(vec![Ident::new("my_sp")])),
2843+
parameters: vec![],
2844+
has_parentheses: false,
2845+
immediate: false,
2846+
into: vec![],
2847+
using: vec![],
2848+
output: false,
2849+
default: false,
2850+
},
2851+
Statement::Update {
2852+
table: TableWithJoins {
2853+
relation: TableFactor::Table {
2854+
name: ObjectName::from(vec![Ident::new("my_table")]),
2855+
alias: None,
2856+
with_hints: vec![],
2857+
args: None,
2858+
version: None,
2859+
with_ordinality: false,
2860+
partitions: vec![],
2861+
json_path: None,
2862+
sample: None,
2863+
index_hints: vec![]
2864+
},
2865+
joins: vec![],
2866+
},
2867+
assignments: vec![Assignment {
2868+
value: Expr::Value(
2869+
number("1")
2870+
.with_span(Span::new(Location::new(3, 16), Location::new(3, 17)))
2871+
),
2872+
target: AssignmentTarget::ColumnName(ObjectName::from(vec![Ident::new("col")])),
2873+
},],
2874+
selection: None,
2875+
returning: None,
2876+
from: None,
2877+
or: None
2878+
},
2879+
]
2880+
);
2881+
2882+
let exec_params_then_update = "\
2883+
EXEC my_sp 1, 2 \
2884+
UPDATE my_table SET col = 1 \
2885+
";
2886+
assert_eq!(
2887+
parse_n_statements(2, exec_params_then_update),
2888+
vec![
2889+
Statement::Execute {
2890+
name: Some(ObjectName::from(vec![Ident::with_span(
2891+
Span::new(Location::new(1, 6), Location::new(1, 11)),
2892+
"my_sp"
2893+
)])),
2894+
parameters: vec![],
2895+
has_parentheses: false,
2896+
immediate: false,
2897+
into: vec![],
2898+
using: vec![],
2899+
output: false,
2900+
default: false,
2901+
},
2902+
Statement::Update {
2903+
table: TableWithJoins {
2904+
relation: TableFactor::Table {
2905+
name: ObjectName::from(vec![Ident::with_span(
2906+
Span::new(Location::new(1, 24), Location::new(1, 32)),
2907+
"my_table"
2908+
)]),
2909+
alias: None,
2910+
with_hints: vec![],
2911+
args: None,
2912+
version: None,
2913+
with_ordinality: false,
2914+
partitions: vec![],
2915+
json_path: None,
2916+
sample: None,
2917+
index_hints: vec![]
2918+
},
2919+
joins: vec![],
2920+
},
2921+
assignments: vec![Assignment {
2922+
value: Expr::Value(
2923+
number("1")
2924+
.with_span(Span::new(Location::new(3, 16), Location::new(3, 17)))
2925+
),
2926+
target: AssignmentTarget::ColumnName(ObjectName::from(vec![Ident::with_span(
2927+
Span::new(Location::new(1, 37), Location::new(1, 40)),
2928+
"col"
2929+
)])),
2930+
},],
2931+
selection: None,
2932+
returning: None,
2933+
from: None,
2934+
or: None
2935+
},
2936+
]
2937+
);
28332938
}

0 commit comments

Comments
 (0)