Improve MySQL CREATE TRIGGER parsing (#1998)
Some checks are pending
license / Release Audit Tool (RAT) (push) Waiting to run
Rust / codestyle (push) Waiting to run
Rust / lint (push) Waiting to run
Rust / benchmark-lint (push) Waiting to run
Rust / compile (push) Waiting to run
Rust / docs (push) Waiting to run
Rust / compile-no-std (push) Waiting to run
Rust / test (beta) (push) Waiting to run
Rust / test (nightly) (push) Waiting to run
Rust / test (stable) (push) Waiting to run

This commit is contained in:
Michael Victor Zink 2025-08-07 22:02:59 -07:00 committed by GitHub
parent 698154d0e0
commit 183bc7c5ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 62 additions and 19 deletions

View file

@ -3914,11 +3914,8 @@ fn parse_looks_like_single_line_comment() {
#[test]
fn parse_create_trigger() {
let sql_create_trigger = r#"
CREATE TRIGGER emp_stamp BEFORE INSERT ON emp
FOR EACH ROW EXECUTE FUNCTION emp_stamp();
"#;
let create_stmt = mysql().one_statement_parses_to(sql_create_trigger, "");
let sql_create_trigger = r#"CREATE TRIGGER emp_stamp BEFORE INSERT ON emp FOR EACH ROW EXECUTE FUNCTION emp_stamp()"#;
let create_stmt = mysql().verified_stmt(sql_create_trigger);
assert_eq!(
create_stmt,
Statement::CreateTrigger {
@ -3927,6 +3924,7 @@ fn parse_create_trigger() {
is_constraint: false,
name: ObjectName::from(vec![Ident::new("emp_stamp")]),
period: TriggerPeriod::Before,
period_before_table: true,
events: vec![TriggerEvent::Insert],
table_name: ObjectName::from(vec![Ident::new("emp")]),
referenced_table_name: None,
@ -3938,15 +3936,22 @@ fn parse_create_trigger() {
exec_type: TriggerExecBodyType::Function,
func_desc: FunctionDesc {
name: ObjectName::from(vec![Ident::new("emp_stamp")]),
args: None,
args: Some(vec![]),
}
}),
statements_as: false,
statements: None,
characteristics: None,
}
);
}
#[test]
fn parse_create_trigger_compound_statement() {
mysql_and_generic().verified_stmt("CREATE TRIGGER mytrigger BEFORE INSERT ON mytable FOR EACH ROW BEGIN SET NEW.a = 1; SET NEW.b = 2; END");
mysql_and_generic().verified_stmt("CREATE TRIGGER tr AFTER INSERT ON t1 FOR EACH ROW BEGIN INSERT INTO t2 VALUES (NEW.id); END");
}
#[test]
fn parse_drop_trigger() {
let sql_drop_trigger = "DROP TRIGGER emp_stamp;";