Skip to content

Commit 069ce0e

Browse files
committed
Enable parsing comma lists without semicolons
1 parent c8436d7 commit 069ce0e

File tree

2 files changed

+126
-1
lines changed

2 files changed

+126
-1
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: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2520,7 +2520,6 @@ DECLARE @Y AS NVARCHAR(MAX)='y'
25202520
#[test]
25212521
fn test_supports_statements_without_semicolon_delimiter() {
25222522
use sqlparser::ast::Ident;
2523-
25242523
use sqlparser::tokenizer::Location;
25252524

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

0 commit comments

Comments
 (0)