Skip to content

Commit b284fdf

Browse files
jjbayerJoris Bayer
andauthored
Fix panic for REPLACE (apache#1140)
Co-authored-by: Joris Bayer <[email protected]>
1 parent 92781c1 commit b284fdf

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/parser/mod.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7894,7 +7894,7 @@ impl<'a> Parser<'a> {
78947894
return parser_err!("Unsupported statement REPLACE", self.peek_token().location);
78957895
}
78967896

7897-
let insert = &mut self.parse_insert().unwrap();
7897+
let insert = &mut self.parse_insert()?;
78987898
if let Statement::Insert { replace_into, .. } = insert {
78997899
*replace_into = true;
79007900
}
@@ -9662,4 +9662,42 @@ mod tests {
96629662
panic!("fail to parse mysql partition selection");
96639663
}
96649664
}
9665+
9666+
#[test]
9667+
fn test_replace_into_placeholders() {
9668+
let sql = "REPLACE INTO t (a) VALUES (&a)";
9669+
9670+
assert!(Parser::parse_sql(&GenericDialect {}, sql).is_err());
9671+
}
9672+
9673+
#[test]
9674+
fn test_replace_into_set() {
9675+
// NOTE: This is actually valid MySQL syntax, REPLACE and INSERT,
9676+
// but the parser does not yet support it.
9677+
// https://dev.mysql.com/doc/refman/8.3/en/insert.html
9678+
let sql = "REPLACE INTO t SET a='1'";
9679+
9680+
assert!(Parser::parse_sql(&MySqlDialect {}, sql).is_err());
9681+
}
9682+
9683+
#[test]
9684+
fn test_replace_into_set_placeholder() {
9685+
let sql = "REPLACE INTO t SET ?";
9686+
9687+
assert!(Parser::parse_sql(&GenericDialect {}, sql).is_err());
9688+
}
9689+
9690+
#[test]
9691+
fn test_replace_into_select() {
9692+
let sql = r#"REPLACE INTO t1 (a, b, c) (SELECT * FROM t2)"#;
9693+
9694+
assert!(Parser::parse_sql(&GenericDialect {}, sql).is_err());
9695+
}
9696+
9697+
#[test]
9698+
fn test_replace_incomplete() {
9699+
let sql = r#"REPLACE"#;
9700+
9701+
assert!(Parser::parse_sql(&MySqlDialect {}, sql).is_err());
9702+
}
96659703
}

0 commit comments

Comments
 (0)