Skip to content

Commit face972

Browse files
authored
Merge pull request #27 from virattara/fix_select_semi_colon
consume semi colon at the end of select and delete queries
2 parents 70a3ae9 + 9898e99 commit face972

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/sqlparser.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,8 @@ impl Parser {
10881088
None
10891089
};
10901090

1091+
let _ = self.consume_token(&Token::SemiColon);
1092+
10911093
// parse next token
10921094
if let Some(next_token) = self.peek_token() {
10931095
parser_err!(format!(
@@ -1144,6 +1146,8 @@ impl Parser {
11441146
None
11451147
};
11461148

1149+
let _ = self.consume_token(&Token::SemiColon);
1150+
11471151
if let Some(next_token) = self.peek_token() {
11481152
parser_err!(format!(
11491153
"Unexpected token at end of SELECT: {:?}",

tests/sqlparser_generic.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,33 @@ fn parse_case_expression() {
420420
SQLValue(Value::SingleQuotedString(">=0".to_string()))],
421421
else_result: Some(Box::new(SQLValue(Value::SingleQuotedString("<0".to_string()))))
422422
},
423-
projection[0]
423+
projection[0]);
424+
}
425+
_ => assert!(false),
426+
}
427+
}
428+
429+
#[test]
430+
fn parse_select_with_semi_colon() {
431+
let sql = String::from("SELECT id, fname, lname FROM customer WHERE id = 1;");
432+
let ast = parse_sql(&sql);
433+
match ast {
434+
ASTNode::SQLSelect { projection, .. } => {
435+
assert_eq!(3, projection.len());
436+
}
437+
_ => assert!(false),
438+
}
439+
}
440+
441+
#[test]
442+
fn parse_delete_with_semi_colon() {
443+
let sql: &str = "DELETE FROM 'table';";
444+
445+
match parse_sql(&sql) {
446+
ASTNode::SQLDelete { relation, .. } => {
447+
assert_eq!(
448+
Some(Box::new(ASTNode::SQLValue(Value::SingleQuotedString("table".to_string())))),
449+
relation
424450
);
425451
}
426452
_ => assert!(false),

0 commit comments

Comments
 (0)