From: Dagfinn Ilmari Mannsåker Date: Sat, 20 Sep 2014 16:20:12 +0000 (+0100) Subject: Add support for triggers in Parser::Oracle X-Git-Tag: v0.11021~15^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7368f0eed552365be601c4cfe45fe8f7f71396d8;p=dbsrgits%2FSQL-Translator.git Add support for triggers in Parser::Oracle --- diff --git a/Changes b/Changes index 1a6b2b5..74d9fd8 100644 --- a/Changes +++ b/Changes @@ -8,6 +8,7 @@ Changes for SQL::Translator quoting and escaping for SQLite, MySQL, PostgreSQL, SQLServer and Oracle (RT#90700, RT#31034) * Add support for ALTER TABLE ... ADD CONSTRAINT to Oracle parser + * Add trigger support to Oracle parser (RT#62927) 0.11020 2014-09-02 diff --git a/lib/SQL/Translator/Parser/Oracle.pm b/lib/SQL/Translator/Parser/Oracle.pm index d5c1b29..7a3bb23 100644 --- a/lib/SQL/Translator/Parser/Oracle.pm +++ b/lib/SQL/Translator/Parser/Oracle.pm @@ -91,7 +91,7 @@ our @EXPORT_OK = qw(parse); our $GRAMMAR = <<'END_OF_GRAMMAR'; -{ my ( %tables, %indices, %constraints, $table_order, @table_comments, %views, $view_order, %procedures, $proc_order ) } +{ my ( %tables, %indices, %constraints, $table_order, @table_comments, %views, $view_order, %procedures, $proc_order, %triggers, $trigger_order ) } # # The "eofile" rule makes the parser fail if any "statement" rule @@ -107,6 +107,7 @@ startrule : statement(s) eofile constraints => \%constraints, views => \%views, procedures => \%procedures, + triggers => \%triggers, }; } @@ -205,6 +206,21 @@ index_expr: parens_name_list $return = "$item[2]($arg_list)"; } +create : /create/i /or replace/i /trigger/i table_name not_end m#^/$#im + { + @table_comments = (); + my $trigger_name = $item[4]; + # Hack to strip owner from trigger name + $trigger_name =~ s#.*\.##; + my $owner = ''; + my $action = "$item[1] $item[2] $item[3] $item[4] $item[5]"; + + $triggers{ $trigger_name }{'order'} = ++$trigger_order; + $triggers{ $trigger_name }{'name'} = $trigger_name; + $triggers{ $trigger_name }{'owner'} = $owner; + $triggers{ $trigger_name }{'action'} = $action; + } + create : /create/i /or replace/i /procedure/i table_name not_end m#^/$#im { @table_comments = (); @@ -709,6 +725,16 @@ sub parse { ); } + my @triggers = sort { + $result->{triggers}->{ $a }->{'order'} <=> $result->{triggers}->{ $b }->{'order'} + } keys %{ $result->{triggers} }; + foreach my $trigger_name (@triggers) { + $schema->add_trigger( + name => $trigger_name, + action => $result->{triggers}->{$trigger_name}->{action}, + ); + } + return 1; }