Skip Menu |

This queue is for tickets about the SQL-Translator CPAN distribution.

Report information
The Basics
Id: 62927
Status: open
Priority: 0/
Queue: SQL-Translator

People
Owner: Nobody in particular
Requestors: skzitz [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.11006
Fixed in: (no value)



Subject: Oracle parser patch to fix quoted names and triggers
The Oracle parser doesn't seem to handle quoted names (related to bug #58318: can't turn off quoted table names) and triggers. The schema handles triggers, so the patch attached adds introductory support for triggers. The patch also effectively ignores quotes around names. I didn't bother writing any .t to verify this, sorry :(
Subject: Oracle.pm.diff
--- /home/zitz/Oracle.pm 2010-11-11 12:08:33.000000000 -0600 +++ Oracle.pm 2010-11-11 12:40:02.875936002 -0600 @@ -112,7 +112,7 @@ $GRAMMAR = q` -{ 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 @@ -128,6 +128,7 @@ constraints => \%constraints, views => \%views, procedures => \%procedures, + triggers => \%triggers, }; } @@ -221,6 +222,21 @@ $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 = (); @@ -598,0 +614,0 @@ WORD : /\w+/ -NAME : /\w+/ { $item[1] } +NAME : '"' /\w+/ '"' + { $item[2] } + | + /\w+/ + { $item[1] } + TABLE : /table/i @@ -718,6 +740,16 @@ ); } + 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; }
On Thu Nov 11 13:48:09 2010, http://zitz@erf.net/ wrote: Show quoted text
> The Oracle parser doesn't seem to handle quoted names (related to bug > #58318: can't turn off quoted table names) and triggers. > The schema handles triggers, so the patch attached adds introductory > support for triggers. The patch also effectively ignores quotes around > names. > > I didn't bother writing any .t to verify this, sorry :(
Then why should we bother applying it? :) Anyway - there has been work done on the Oracle parser in recent versions - please check if the problem still persists with 0.11007. Thank you.
Here's a test for the quoted tables issue. Haven't got a test for the trigger thing just yet.
Subject: 901_oracle_parser_quotes.t
#!/usr/bin/env perl use strict; use warnings; use Test::More tests => 3; use SQL::Translator; # Test for bug #62927 - Oracle parser patch to fix quoted names and triggers # generated with ../script/sqlt -d --from=Oracle -to=Oracle --quote-table-names --quote-field-names data/oracle/create.sql # --quote-field-names and --quote-table-names not really needed until bug #58318 gets fixed... my $ddl_with_quotes = q{ -- -- Created by SQL::Translator::Producer::Oracle -- Created on Mon Jan 28 18:55:10 2013 -- -- -- Table: TABLE1 --; CREATE TABLE "TABLE1" ( "FIELD_ID" number(19,0) NOT NULL, "OTHERFIELD" number(19,0) NOT NULL ); ALTER TABLE "TABLE1" ADD CONSTRAINT "TABLE1_OTHERFIELD_fk" FOREIGN KEY ("OTHERFIELD") REFERENCES "TABLE2" ("ID") ON DELETE CASCADE ENABLE; ALTER TABLE "TABLE1" ADD CONSTRAINT "TABLE1_FIELD_ID_fk" FOREIGN KEY ("FIELD_ID") REFERENCES "TABLE3" ("ID") ON DELETE CASCADE ENABLE; / }; my $ddl_without_quotes = q{ -- -- Created by SQL::Translator::Producer::Oracle -- Created on Mon Jan 28 18:55:10 2013 -- -- -- Table: TABLE1 --; CREATE TABLE TABLE1 ( FIELD_ID number(19,0) NOT NULL, OTHERFIELD number(19,0) NOT NULL ); ALTER TABLE TABLE1 ADD CONSTRAINT TABLE1_OTHERFIELD_fk FOREIGN KEY (OTHERFIELD) REFERENCES TABLE2 (ID) ON DELETE CASCADE ENABLE; ALTER TABLE TABLE1 ADD CONSTRAINT TABLE1_FIELD_ID_fk FOREIGN KEY (FIELD_ID) REFERENCES TABLE3 (ID) ON DELETE CASCADE ENABLE; / }; my $tr = SQL::Translator->new( parser => "Oracle", producer => "Oracle", quote_identifiers => 0 ); my $out; eval { $out = $tr->translate(\$ddl_with_quotes); }; ok(!defined $@, "parsing quoted Oracle DDL didn't crash"); my ($normalized_q, $normalized_uq, $normalized_out) = map { s/^--.*$//g; s/\S+/ /g; $_ } ($ddl_with_quotes, $ddl_without_quotes, $out); ok($normalized_q eq $normalized_uq, "regexp ok"); ok($normalized_out eq $normalized_uq, "Oracle parser <-> producer roundtrip ok");