mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-26 15:39:12 +00:00
Fix panic for REPLACE (#1140)
Co-authored-by: Joris Bayer <joris.bayer@protonmail.com>
This commit is contained in:
parent
92781c1c05
commit
b284fdfb7e
1 changed files with 39 additions and 1 deletions
|
@ -7894,7 +7894,7 @@ impl<'a> Parser<'a> {
|
||||||
return parser_err!("Unsupported statement REPLACE", self.peek_token().location);
|
return parser_err!("Unsupported statement REPLACE", self.peek_token().location);
|
||||||
}
|
}
|
||||||
|
|
||||||
let insert = &mut self.parse_insert().unwrap();
|
let insert = &mut self.parse_insert()?;
|
||||||
if let Statement::Insert { replace_into, .. } = insert {
|
if let Statement::Insert { replace_into, .. } = insert {
|
||||||
*replace_into = true;
|
*replace_into = true;
|
||||||
}
|
}
|
||||||
|
@ -9662,4 +9662,42 @@ mod tests {
|
||||||
panic!("fail to parse mysql partition selection");
|
panic!("fail to parse mysql partition selection");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_replace_into_placeholders() {
|
||||||
|
let sql = "REPLACE INTO t (a) VALUES (&a)";
|
||||||
|
|
||||||
|
assert!(Parser::parse_sql(&GenericDialect {}, sql).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_replace_into_set() {
|
||||||
|
// NOTE: This is actually valid MySQL syntax, REPLACE and INSERT,
|
||||||
|
// but the parser does not yet support it.
|
||||||
|
// https://dev.mysql.com/doc/refman/8.3/en/insert.html
|
||||||
|
let sql = "REPLACE INTO t SET a='1'";
|
||||||
|
|
||||||
|
assert!(Parser::parse_sql(&MySqlDialect {}, sql).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_replace_into_set_placeholder() {
|
||||||
|
let sql = "REPLACE INTO t SET ?";
|
||||||
|
|
||||||
|
assert!(Parser::parse_sql(&GenericDialect {}, sql).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_replace_into_select() {
|
||||||
|
let sql = r#"REPLACE INTO t1 (a, b, c) (SELECT * FROM t2)"#;
|
||||||
|
|
||||||
|
assert!(Parser::parse_sql(&GenericDialect {}, sql).is_err());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_replace_incomplete() {
|
||||||
|
let sql = r#"REPLACE"#;
|
||||||
|
|
||||||
|
assert!(Parser::parse_sql(&MySqlDialect {}, sql).is_err());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue