X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FProducer%2FMySQL.pm;h=ff756060f0303e199f4e1bccb1e102aebaea6d0e;hb=c0ec0e22d3f0e3852c00daac5ef5763010b410c3;hp=904b294c3b1efd05e7bced91003712064c734ca2;hpb=1868ddbee17731eb23de17472c429c6bbf13a037;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Producer/MySQL.pm b/lib/SQL/Translator/Producer/MySQL.pm index 904b294..ff75606 100644 --- a/lib/SQL/Translator/Producer/MySQL.pm +++ b/lib/SQL/Translator/Producer/MySQL.pm @@ -356,11 +356,14 @@ sub create_trigger { } 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, ); @@ -938,12 +941,13 @@ sub batch_alter_table { 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 {