}
my $action = $trigger->action;
- $action .= ";" unless $action =~ /;\s*\z/;
+ if($action !~ /^ \s* BEGIN [\s\;] .*? [\s\;] END [\s\;]* $/six) {
+ $action .= ";" unless $action =~ /;\s*\z/;
+ $action = "BEGIN $action END";
+ }
push @statements, "DROP TRIGGER IF EXISTS " . $generator->quote($name) if $options->{add_drop_trigger};
push @statements, sprintf(
- "CREATE TRIGGER %s %s %s ON %s\n FOR EACH ROW BEGIN %s END",
+ "CREATE TRIGGER %s %s %s ON %s\n FOR EACH ROW %s",
$generator->quote($name), $trigger->perform_action_when, $event,
$generator->quote($trigger->on_table), $action,
);
sub drop_table {
my ($table, $options) = @_;
- # Drop (foreign key) constraints so table drops cleanly
- my @sql = batch_alter_table($table, { alter_drop_constraint => [ grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints ] }, $options);
-
- my $table_name = _generator($options)->quote($table);
- return (@sql, "DROP TABLE $table");
-
+ return (
+ # Drop (foreign key) constraints so table drops cleanly
+ batch_alter_table(
+ $table, { alter_drop_constraint => [ grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints ] }, $options
+ ),
+ 'DROP TABLE ' . _generator($options)->quote($table),
+ );
}
sub rename_table {