mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-12 11:14:59 +00:00
Support Mysql REPLACE
statement and PRIORITY
clause of INSERT
(#1072)
This commit is contained in:
parent
7ea47c71fb
commit
c62ecb1100
5 changed files with 211 additions and 2 deletions
|
@ -16,6 +16,7 @@
|
|||
|
||||
use matches::assert_matches;
|
||||
use sqlparser::ast::Expr;
|
||||
use sqlparser::ast::MysqlInsertPriority::{Delayed, HighPriority, LowPriority};
|
||||
use sqlparser::ast::Value;
|
||||
use sqlparser::ast::*;
|
||||
use sqlparser::dialect::{GenericDialect, MySqlDialect};
|
||||
|
@ -1035,6 +1036,130 @@ fn parse_ignore_insert() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_priority_insert() {
|
||||
let sql = r"INSERT HIGH_PRIORITY INTO tasks (title, priority) VALUES ('Test Some Inserts', 1)";
|
||||
|
||||
match mysql_and_generic().verified_stmt(sql) {
|
||||
Statement::Insert {
|
||||
table_name,
|
||||
columns,
|
||||
source,
|
||||
on,
|
||||
priority,
|
||||
..
|
||||
} => {
|
||||
assert_eq!(ObjectName(vec![Ident::new("tasks")]), table_name);
|
||||
assert_eq!(vec![Ident::new("title"), Ident::new("priority")], columns);
|
||||
assert!(on.is_none());
|
||||
assert_eq!(priority, Some(HighPriority));
|
||||
assert_eq!(
|
||||
Some(Box::new(Query {
|
||||
with: None,
|
||||
body: Box::new(SetExpr::Values(Values {
|
||||
explicit_row: false,
|
||||
rows: vec![vec![
|
||||
Expr::Value(Value::SingleQuotedString("Test Some Inserts".to_string())),
|
||||
Expr::Value(number("1"))
|
||||
]]
|
||||
})),
|
||||
order_by: vec![],
|
||||
limit: None,
|
||||
limit_by: vec![],
|
||||
offset: None,
|
||||
fetch: None,
|
||||
locks: vec![],
|
||||
for_clause: None,
|
||||
})),
|
||||
source
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
let sql2 = r"INSERT LOW_PRIORITY INTO tasks (title, priority) VALUES ('Test Some Inserts', 1)";
|
||||
|
||||
match mysql().verified_stmt(sql2) {
|
||||
Statement::Insert {
|
||||
table_name,
|
||||
columns,
|
||||
source,
|
||||
on,
|
||||
priority,
|
||||
..
|
||||
} => {
|
||||
assert_eq!(ObjectName(vec![Ident::new("tasks")]), table_name);
|
||||
assert_eq!(vec![Ident::new("title"), Ident::new("priority")], columns);
|
||||
assert!(on.is_none());
|
||||
assert_eq!(priority, Some(LowPriority));
|
||||
assert_eq!(
|
||||
Some(Box::new(Query {
|
||||
with: None,
|
||||
body: Box::new(SetExpr::Values(Values {
|
||||
explicit_row: false,
|
||||
rows: vec![vec![
|
||||
Expr::Value(Value::SingleQuotedString("Test Some Inserts".to_string())),
|
||||
Expr::Value(number("1"))
|
||||
]]
|
||||
})),
|
||||
order_by: vec![],
|
||||
limit: None,
|
||||
limit_by: vec![],
|
||||
offset: None,
|
||||
fetch: None,
|
||||
locks: vec![],
|
||||
for_clause: None,
|
||||
})),
|
||||
source
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_replace_insert() {
|
||||
let sql = r"REPLACE DELAYED INTO tasks (title, priority) VALUES ('Test Some Inserts', 1)";
|
||||
match mysql().verified_stmt(sql) {
|
||||
Statement::Insert {
|
||||
table_name,
|
||||
columns,
|
||||
source,
|
||||
on,
|
||||
replace_into,
|
||||
priority,
|
||||
..
|
||||
} => {
|
||||
assert_eq!(ObjectName(vec![Ident::new("tasks")]), table_name);
|
||||
assert_eq!(vec![Ident::new("title"), Ident::new("priority")], columns);
|
||||
assert!(on.is_none());
|
||||
assert!(replace_into);
|
||||
assert_eq!(priority, Some(Delayed));
|
||||
assert_eq!(
|
||||
Some(Box::new(Query {
|
||||
with: None,
|
||||
body: Box::new(SetExpr::Values(Values {
|
||||
explicit_row: false,
|
||||
rows: vec![vec![
|
||||
Expr::Value(Value::SingleQuotedString("Test Some Inserts".to_string())),
|
||||
Expr::Value(number("1"))
|
||||
]]
|
||||
})),
|
||||
order_by: vec![],
|
||||
limit: None,
|
||||
limit_by: vec![],
|
||||
offset: None,
|
||||
fetch: None,
|
||||
locks: vec![],
|
||||
for_clause: None,
|
||||
})),
|
||||
source
|
||||
);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_empty_row_insert() {
|
||||
let sql = "INSERT INTO tb () VALUES (), ()";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue