From: Chris Hilton Date: Tue, 6 Mar 2007 21:09:32 +0000 (+0000) Subject: Corrected index parsing on Oracle so every index is not a unique constraint X-Git-Tag: v0.11008~379 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ae8a4ce3177240e56805ff4829b7a7b190bf9d6c;p=dbsrgits%2FSQL-Translator.git Corrected index parsing on Oracle so every index is not a unique constraint --- diff --git a/lib/SQL/Translator/Parser/Oracle.pm b/lib/SQL/Translator/Parser/Oracle.pm index 150489a..b561431 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.26 2006-06-29 19:24:14 kycl4rk Exp $ +# $Id: Oracle.pm,v 1.27 2007-03-06 21:09:32 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.26 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.27 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -226,7 +226,7 @@ create : ...!create_table ...!create_index /create/i WORD /[^;]+/ ';' { @table_comments = () } create_index : /create/i UNIQUE(?) /index/i - { $return = $item[2] } + { $return = @{$item[2]} } index_name : NAME '.' NAME { $item[3] } @@ -624,6 +624,8 @@ sub parse { @{ $constraints->{ $table_name } || [] }; for my $idata ( @{ $tdata->{'indices'} || [] } ) { +open(OUT, ">>ACK"); +print OUT $idata->{name}, "\n"; my $index = $table->add_index( name => $idata->{'name'}, type => uc $idata->{'type'}, diff --git a/t/15oracle-parser.t b/t/15oracle-parser.t index 533ac72..4a90eb7 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(85, 'SQL::Translator::Parser::Oracle'); +maybe_plan(89, 'SQL::Translator::Parser::Oracle'); SQL::Translator::Parser::Oracle->import('parse'); my $t = SQL::Translator->new( trace => 0 ); @@ -55,6 +55,7 @@ my $sql = q[ CREATE UNIQUE INDEX qtl_accession ON qtl ( qtl_accession_id ); CREATE UNIQUE INDEX qtl_accession_upper ON qtl ( UPPER(qtl_accession_id) ); + CREATE INDEX qtl_index ON qtl ( qtl_accession_id ); CREATE TABLE qtl_trait_synonym ( @@ -222,6 +223,14 @@ my $t3_f2 = shift @t3_fields; is( $t3_f2->comments, 'accession comment', 'Comment "accession comment" exists' ); +my @t3_indices = $t3->get_indices; +is( scalar @t3_indices, 1, '1 index on table' ); + +my $t3_i1 = shift @t3_indices; +is( $t3_i1->type, 'NORMAL', 'First index is normal' ); +is( $t3_i1->name, 'qtl_index', 'Name is "qtl_index"' ); +is( join(',', $t3_i1->fields), 'qtl_accession_id', 'Fields = "qtl_accession_id"' ); + # # qtl_trait_synonym #