Skip to content

Commit

Permalink
Add support for triggers in Parser::Oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmari committed Sep 20, 2014
1 parent b77deb7 commit 51b3907
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/SQL/Translator/Parser/Oracle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -107,6 +107,7 @@ startrule : statement(s) eofile
constraints => \%constraints,
views => \%views,
procedures => \%procedures,
triggers => \%triggers,
};
}
Expand Down Expand Up @@ -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 = ();
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 51b3907

Please sign in to comment.