From: Peter Rabbitson Date: Tue, 23 Feb 2010 11:14:20 +0000 (+0000) Subject: Cleanup tabs/whitespace X-Git-Tag: v0.11008~65 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7769504d1e8d1b08134b38c721448001029b3579;p=dbsrgits%2FSQL-Translator.git Cleanup tabs/whitespace --- diff --git a/lib/SQL/Translator/Producer/Oracle.pm b/lib/SQL/Translator/Producer/Oracle.pm index 29ed316..67e672c 100644 --- a/lib/SQL/Translator/Producer/Oracle.pm +++ b/lib/SQL/Translator/Producer/Oracle.pm @@ -213,8 +213,8 @@ sub produce { my ($output, $create, @table_defs, @fk_defs, @trigger_defs, @index_defs, @constraint_defs); $create .= header_comment unless ($no_comments); - my $qt = 1 if $translator->quote_table_names; - my $qf = 1 if $translator->quote_field_names; + my $qt = 1 if $translator->quote_table_names; + my $qf = 1 if $translator->quote_field_names; if ( $translator->parser_type =~ /mysql/i ) { $create .= @@ -234,8 +234,8 @@ sub produce { show_warnings => $WARN, no_comments => $no_comments, delay_constraints => $delay_constraints, - quote_table_names => $qt, - quote_field_names => $qf, + quote_table_names => $qt, + quote_field_names => $qf, } ); push @table_defs, @$table_def; @@ -251,7 +251,7 @@ sub produce { $view, { add_drop_view => $add_drop_table, - quote_table_names => $qt, + quote_table_names => $qt, } ); push @view_defs, @$view_def; @@ -262,7 +262,7 @@ sub produce { } else { $create .= join (";\n\n", @table_defs, @view_defs, @fk_defs, @index_defs, @constraint_defs); - $create .= ";\n\n"; + $create .= ";\n\n"; # If wantarray is not set we have to add "/" in this statement # DBI->do() needs them omitted # triggers may NOT end with a semicolon @@ -275,10 +275,10 @@ sub produce { sub create_table { my ($table, $options) = @_; - my $qt = $options->{quote_table_names}; - my $qf = $options->{quote_field_names}; + my $qt = $options->{quote_table_names}; + my $qf = $options->{quote_field_names}; my $table_name = $table->name; - my $table_name_q = quote($table_name,$qt); + my $table_name_q = quote($table_name,$qt); my $item = ''; my $drop; @@ -333,25 +333,28 @@ sub create_table { # create a name if delay_constraints $name ||= mk_name( $table_name, 'pk' ) if $options->{delay_constraints}; - $name = quote($name,$qf); + $name = quote($name,$qf); push @constraint_defs, ($name ? "CONSTRAINT $name " : '') . - 'PRIMARY KEY (' . join( ', ', @fields ) . ')'; + 'PRIMARY KEY (' . join( ', ', @fields ) . ')'; } elsif ( $c->type eq UNIQUE ) { - # Don't create UNIQUE constraints identical to the primary key - if ( my $pk = $table->primary_key ) { - my $u_fields = join(":", @fields); - my $pk_fields = join(":", $pk->fields); - next if $u_fields eq $pk_fields; - } - if ($name) { - # Force prepend of table_name as ORACLE doesn't allow duplicate - # CONSTRAINT names even for different tables (ORA-02264) - $name = "${table_name}_$name" unless $name =~ /^$table_name/; - } else { + # Don't create UNIQUE constraints identical to the primary key + if ( my $pk = $table->primary_key ) { + my $u_fields = join(":", @fields); + my $pk_fields = join(":", $pk->fields); + next if $u_fields eq $pk_fields; + } + + if ($name) { + # Force prepend of table_name as ORACLE doesn't allow duplicate + # CONSTRAINT names even for different tables (ORA-02264) + $name = "${table_name}_$name" unless $name =~ /^$table_name/; + } + else { $name = mk_name( $table_name, 'u' ); - } - $name = quote($name, $qf); + } + + $name = quote($name, $qf); for my $f ( $c->fields ) { my $field_def = $table->get_field( $f ) or next; @@ -368,13 +371,13 @@ sub create_table { } elsif ( $c->type eq CHECK_C ) { $name ||= mk_name( $name || $table_name, 'ck' ); - $name = quote($name, $qf); + $name = quote($name, $qf); my $expression = $c->expression || ''; push @constraint_defs, "CONSTRAINT $name CHECK ($expression)"; } elsif ( $c->type eq FOREIGN_KEY ) { $name = mk_name( join('_', $table_name, $c->fields). '_fk' ); - $name = quote($name, $qf); + $name = quote($name, $qf); my $def = "CONSTRAINT $name FOREIGN KEY "; if ( @fields ) { @@ -442,14 +445,14 @@ sub create_table { if ( $index_type eq PRIMARY_KEY ) { $index_name = $index_name ? mk_name( $index_name ) : mk_name( $table_name, 'pk' ); - $index_name = quote($index_name, $qf); + $index_name = quote($index_name, $qf); push @field_defs, 'CONSTRAINT '.$index_name.' PRIMARY KEY '. '(' . join( ', ', @fields ) . ')'; } elsif ( $index_type eq NORMAL ) { $index_name = $index_name ? mk_name( $index_name ) : mk_name( $table_name, $index_name || 'i' ); - $index_name = quote($index_name, $qf); + $index_name = quote($index_name, $qf); push @index_defs, "CREATE INDEX $index_name on $table_name_q (". join( ', ', @fields ). @@ -458,7 +461,7 @@ sub create_table { elsif ( $index_type eq UNIQUE ) { $index_name = $index_name ? mk_name( $index_name ) : mk_name( $table_name, $index_name || 'i' ); - $index_name = quote($index_name, $qf); + $index_name = quote($index_name, $qf); push @index_defs, "CREATE UNIQUE INDEX $index_name on $table_name_q (". join( ', ', @fields ). @@ -503,7 +506,7 @@ sub create_table { sub alter_field { my ($from_field, $to_field, $options) = @_; - my $qt = $options->{quote_table_names}; + my $qt = $options->{quote_table_names}; my ($field_create, $field_defs, $trigger_defs, $field_comments) = create_field($to_field, $options, {}); @@ -522,7 +525,7 @@ sub alter_field { sub add_field { my ($new_field, $options) = @_; - my $qt = $options->{quote_table_names}; + my $qt = $options->{quote_table_names}; my ($field_create, $field_defs, $trigger_defs, $field_comments) = create_field($new_field, $options, {}); @@ -536,8 +539,8 @@ sub add_field { sub create_field { my ($field, $options, $field_name_scope) = @_; - my $qf = $options->{quote_field_names}; - my $qt = $options->{quote_table_names}; + my $qf = $options->{quote_field_names}; + my $qt = $options->{quote_table_names}; my (@create, @field_defs, @trigger_defs, @field_comments); @@ -550,7 +553,7 @@ sub create_field { my $field_name = mk_name( $field->name, '', $field_name_scope, 1 ); - my $field_name_q = quote($field_name, $qf); + my $field_name_q = quote($field_name, $qf); my $field_def = quote($field_name, $qf); $field->name( $field_name ); @@ -575,16 +578,16 @@ sub create_field { $data_type = 'varchar2'; } else { - if (defined $translate{ $data_type }) { - if (ref $translate{ $data_type } eq "ARRAY") { - ($data_type,$size[0]) = @{$translate{ $data_type }}; - } else { - $data_type = $translate{ $data_type }; - } - } + if (defined $translate{ $data_type }) { + if (ref $translate{ $data_type } eq "ARRAY") { + ($data_type,$size[0]) = @{$translate{ $data_type }}; + } else { + $data_type = $translate{ $data_type }; + } + } $data_type ||= 'varchar2'; } - + # ensure size is not bigger than max size oracle allows for data type if ( defined $max_size{$data_type} ) { for ( my $i = 0 ; $i < scalar @size ; $i++ ) { @@ -699,7 +702,7 @@ sub create_field { " INTO :new." . $field_name_q."\n" . " FROM dual;\n" . "END;\n"; - + push @trigger_defs, $trigger; } @@ -733,7 +736,7 @@ sub create_field { sub create_view { my ($view, $options) = @_; - my $qt = $options->{quote_table_names}; + my $qt = $options->{quote_table_names}; my $view_name = quote($view->name,$qt); my @create; @@ -791,7 +794,7 @@ sub mk_name { # ------------------------------------------------------------------- sub quote { my ($name, $q) = @_; - $q && $name ? "$quote_char$name$quote_char" : $name; + $q && $name ? "$quote_char$name$quote_char" : $name; } diff --git a/t/03mysql-to-oracle.t b/t/03mysql-to-oracle.t index 885ab7a..664d4e9 100644 --- a/t/03mysql-to-oracle.t +++ b/t/03mysql-to-oracle.t @@ -26,8 +26,8 @@ BEGIN { my $tr = SQL::Translator->new( parser => "MySQL", producer => "Oracle", - quote_table_names => 0, - quote_field_names => 0, + quote_table_names => 0, + quote_field_names => 0, ); my $output = $tr->translate(\$create); diff --git a/t/51-xml-to-oracle.t b/t/51-xml-to-oracle.t index c00261d..8b5e02c 100644 --- a/t/51-xml-to-oracle.t +++ b/t/51-xml-to-oracle.t @@ -19,8 +19,8 @@ my $xmlfile = "$Bin/data/xml/schema.xml"; my $sqlt; $sqlt = SQL::Translator->new( no_comments => 1, - quote_table_names => 0, - quote_field_names => 0, + quote_table_names => 0, + quote_field_names => 0, show_warnings => 0, add_drop_table => 1, ); diff --git a/t/63-xml-to-oracle-quotes.t b/t/51-xml-to-oracle_quoted.t similarity index 98% rename from t/63-xml-to-oracle-quotes.t rename to t/51-xml-to-oracle_quoted.t index 1357304..2e82dd1 100644 --- a/t/63-xml-to-oracle-quotes.t +++ b/t/51-xml-to-oracle_quoted.t @@ -19,8 +19,8 @@ my $xmlfile = "$Bin/data/xml/schema.xml"; my $sqlt; $sqlt = SQL::Translator->new( no_comments => 1, - quote_table_names => 1, - quote_field_names => 1, + quote_table_names => 1, + quote_field_names => 1, show_warnings => 0, add_drop_table => 1, ); diff --git a/t/53-oracle-delay-constraints.t b/t/53-oracle-delay-constraints.t index abe21b8..bdc3362 100644 --- a/t/53-oracle-delay-constraints.t +++ b/t/53-oracle-delay-constraints.t @@ -21,8 +21,8 @@ $sqlt = SQL::Translator->new( show_warnings => 0, add_drop_table => 0, producer_args => { 'delay_constraints' => 1 }, - quote_table_names => 0, - quote_field_names => 0, + quote_table_names => 0, + quote_field_names => 0, ); my $sql_string = $sqlt->translate( diff --git a/t/64-oracle-delay-constraints-quotes.t b/t/53-oracle-delay-constraints_quoted.t similarity index 93% rename from t/64-oracle-delay-constraints-quotes.t rename to t/53-oracle-delay-constraints_quoted.t index e656433..1d3299b 100644 --- a/t/64-oracle-delay-constraints-quotes.t +++ b/t/53-oracle-delay-constraints_quoted.t @@ -21,8 +21,8 @@ $sqlt = SQL::Translator->new( show_warnings => 0, add_drop_table => 0, producer_args => { 'delay_constraints' => 1 }, - quote_table_names => 1, - quote_field_names => 1, + quote_table_names => 1, + quote_field_names => 1, ); my $sql_string = $sqlt->translate(