Skip to content

Commit 6da1728

Browse files
committed
Enable parsing comma lists without semicolons
1 parent 0b92e92 commit 6da1728

2 files changed

Lines changed: 128 additions & 1 deletion

File tree

src/parser/mod.rs

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

4993+
if end_token == Token::SemiColon
4994+
&& self
4995+
.dialect
4996+
.supports_statements_without_semicolon_delimiter()
4997+
{
4998+
if let Token::Word(ref kw) = self.peek_token().token {
4999+
if kw.keyword != Keyword::NoKeyword {
5000+
return Ok(vec![]);
5001+
}
5002+
}
5003+
}
5004+
49935005
if self.options.trailing_commas && self.peek_tokens() == [Token::Comma, end_token] {
49945006
let _ = self.consume_token(&Token::Comma);
49955007
return Ok(vec![]);

tests/sqlparser_mssql.rs

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2868,7 +2868,6 @@ fn parse_mssql_update_with_output_into() {
28682868
#[test]
28692869
fn test_supports_statements_without_semicolon_delimiter() {
28702870
use sqlparser::ast::Ident;
2871-
28722871
use sqlparser::tokenizer::Location;
28732872

28742873
fn parse_n_statements(n: usize, sql: &str) -> Vec<Statement> {
@@ -3178,4 +3177,120 @@ fn test_supports_statements_without_semicolon_delimiter() {
31783177
},
31793178
}
31803179
);
3180+
3181+
let exec_then_update = "\
3182+
EXEC my_sp \
3183+
UPDATE my_table SET col = 1 \
3184+
";
3185+
assert_eq!(
3186+
parse_n_statements(2, exec_then_update),
3187+
vec![
3188+
Statement::Execute {
3189+
name: Some(ObjectName::from(vec![Ident::new("my_sp")])),
3190+
parameters: vec![],
3191+
has_parentheses: false,
3192+
immediate: false,
3193+
into: vec![],
3194+
using: vec![],
3195+
output: false,
3196+
default: false,
3197+
},
3198+
Statement::Update {
3199+
table: TableWithJoins {
3200+
relation: TableFactor::Table {
3201+
name: ObjectName::from(vec![Ident::new("my_table")]),
3202+
alias: None,
3203+
with_hints: vec![],
3204+
args: None,
3205+
version: None,
3206+
with_ordinality: false,
3207+
partitions: vec![],
3208+
json_path: None,
3209+
sample: None,
3210+
index_hints: vec![]
3211+
},
3212+
joins: vec![],
3213+
},
3214+
assignments: vec![Assignment {
3215+
value: Expr::Value(
3216+
number("1")
3217+
.with_span(Span::new(Location::new(3, 16), Location::new(3, 17)))
3218+
),
3219+
target: AssignmentTarget::ColumnName(ObjectName::from(vec![Ident::new("col")])),
3220+
},],
3221+
selection: None,
3222+
returning: None,
3223+
from: None,
3224+
or: None,
3225+
limit: None,
3226+
},
3227+
]
3228+
);
3229+
3230+
let exec_params_then_update = "\
3231+
EXEC my_sp 1, 2 \
3232+
UPDATE my_table SET col = 1 \
3233+
";
3234+
assert_eq!(
3235+
parse_n_statements(2, exec_params_then_update),
3236+
vec![
3237+
Statement::Execute {
3238+
name: Some(ObjectName::from(vec![Ident::with_span(
3239+
Span::new(Location::new(1, 6), Location::new(1, 11)),
3240+
"my_sp"
3241+
)])),
3242+
parameters: vec![
3243+
Expr::Value(
3244+
number("1")
3245+
.with_span(Span::new(Location::new(1, 12), Location::new(1, 13)))
3246+
),
3247+
Expr::Value(
3248+
number("2")
3249+
.with_span(Span::new(Location::new(1, 15), Location::new(1, 17)))
3250+
),
3251+
],
3252+
has_parentheses: false,
3253+
immediate: false,
3254+
into: vec![],
3255+
using: vec![],
3256+
output: false,
3257+
default: false,
3258+
},
3259+
Statement::Update {
3260+
table: TableWithJoins {
3261+
relation: TableFactor::Table {
3262+
name: ObjectName::from(vec![Ident::with_span(
3263+
Span::new(Location::new(1, 24), Location::new(1, 32)),
3264+
"my_table"
3265+
)]),
3266+
alias: None,
3267+
with_hints: vec![],
3268+
args: None,
3269+
version: None,
3270+
with_ordinality: false,
3271+
partitions: vec![],
3272+
json_path: None,
3273+
sample: None,
3274+
index_hints: vec![]
3275+
},
3276+
joins: vec![],
3277+
},
3278+
assignments: vec![Assignment {
3279+
value: Expr::Value(
3280+
number("1")
3281+
.with_span(Span::new(Location::new(3, 16), Location::new(3, 17)))
3282+
),
3283+
target: AssignmentTarget::ColumnName(ObjectName::from(vec![Ident::with_span(
3284+
Span::new(Location::new(1, 37), Location::new(1, 40)),
3285+
"col"
3286+
)])),
3287+
},],
3288+
selection: None,
3289+
returning: None,
3290+
from: None,
3291+
or: None,
3292+
limit: None,
3293+
},
3294+
]
3295+
);
31813296
}

0 commit comments

Comments
 (0)