From: Chris Hilton Date: Fri, 5 May 2006 16:42:17 +0000 (+0000) Subject: Fixed up ON DELETE parsing for FKs X-Git-Tag: v0.11008~444 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=188a97b5bbaa40bb28826389d368a39d719c4a83;p=dbsrgits%2FSQL-Translator.git Fixed up ON DELETE parsing for FKs --- diff --git a/lib/SQL/Translator/Parser/Oracle.pm b/lib/SQL/Translator/Parser/Oracle.pm index 45aa5e0..8ed34e9 100644 --- a/lib/SQL/Translator/Parser/Oracle.pm +++ b/lib/SQL/Translator/Parser/Oracle.pm @@ -1,7 +1,7 @@ package SQL::Translator::Parser::Oracle; # ------------------------------------------------------------------- -# $Id: Oracle.pm,v 1.23 2006-05-03 21:46:06 duality72 Exp $ +# $Id: Oracle.pm,v 1.24 2006-05-05 16:42:17 duality72 Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -97,7 +97,7 @@ was altered to better handle the syntax created by DDL::Oracle. use strict; use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.23 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.24 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -532,14 +532,14 @@ table_constraint_type : /primary key/i '(' NAME(s /,/) ')' fields => $item[3], reference_table => $item[6], reference_fields => $item[7][0], - match_type => $item[8][0], - on_delete => $item[9][0], - on_update => $item[10][0], +# match_type => $item[8][0], + on_delete => $item[8][0], +# on_update => $item[9][0], } } on_delete : /on delete/i WORD(s) - { $item[2] } + { join(' ', @{$item[2]}) } UNIQUE : /unique/i { $return = 1 } diff --git a/t/15oracle-parser.t b/t/15oracle-parser.t index 07db30e..533ac72 100644 --- a/t/15oracle-parser.t +++ b/t/15oracle-parser.t @@ -7,7 +7,7 @@ use SQL::Translator; use SQL::Translator::Schema::Constants; use Test::SQL::Translator qw(maybe_plan); -maybe_plan(79, 'SQL::Translator::Parser::Oracle'); +maybe_plan(85, 'SQL::Translator::Parser::Oracle'); SQL::Translator::Parser::Oracle->import('parse'); my $t = SQL::Translator->new( trace => 0 ); @@ -63,7 +63,7 @@ my $sql = q[ trait_synonym VARCHAR2(200) NOT NULL, qtl_trait_id NUMBER(11) NOT NULL, UNIQUE( qtl_trait_id, trait_synonym ), - FOREIGN KEY ( qtl_trait_id ) REFERENCES qtl_trait + FOREIGN KEY ( qtl_trait_id ) REFERENCES qtl_trait ON DELETE SET NULL ); ]; @@ -233,3 +233,14 @@ is( scalar @t4_fields, 3, '3 fields in table' ); my @t4_constraints = $t4->get_constraints; is( scalar @t4_constraints, 3, '3 constraints on table' ); +my $t4_c3 = $t4_constraints[2]; +is( $t4_c3->type, FOREIGN_KEY, 'Third constraint is FK' ); +is( $t4_c3->name, '', 'No name' ); +is( join(',', $t4_c3->fields), 'qtl_trait_id', + 'Fields = "qtl_trait_id"' ); +is( $t4_c3->reference_table, 'qtl_trait', + 'Reference table = "qtl_trait"' ); +is( join(',', $t4_c3->reference_fields), 'qtl_trait_id', + 'Reference fields = "qtl_trait_id"' ); +is( $t4_c3->on_delete, 'SET NULL', + 'on_delete = "SET NULL"' );