From: Ben Faga Date: Wed, 25 May 2005 15:17:49 +0000 (+0000) Subject: Applied Eric Just's changes to the Oracle producer. His comments follow: X-Git-Tag: v0.11008~557 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ef373e643ad49168703f9dda6e4f1ff266cff511;p=dbsrgits%2FSQL-Translator.git Applied Eric Just's changes to the Oracle producer. His comments follow: I have made a couple of more changes which you MIGHT want to incorporate into Oracle Producer so that the translation for CHADO works 'out of the box' . I am attaching a new diff against the new version. Change 1: Change the field 'name' property to the unreserved name, that way whenever field-name is called the proper unreserved name is returned. Change 2: Using a CLOB in a unique key is illegal in Oracle. Convert a column to a varchar(4000) if it is a CLOB and is part of a unique key, warn about this change. Change 3: Create the sequence name based on the unreserved name of the table. Since the table gets created with the unreserved name, this keeps the sequence naming consistently based on the table name. Change 4: Similar to change 3 except for naming triggers. Change 5: remove line that didn't get removed from last merge. (want to append name with number only after the string has been truncated to max_length -2) --- diff --git a/lib/SQL/Translator/Producer/Oracle.pm b/lib/SQL/Translator/Producer/Oracle.pm index c16db61..56f658f 100644 --- a/lib/SQL/Translator/Producer/Oracle.pm +++ b/lib/SQL/Translator/Producer/Oracle.pm @@ -1,7 +1,7 @@ package SQL::Translator::Producer::Oracle; # ------------------------------------------------------------------- -# $Id: Oracle.pm,v 1.32 2004-12-20 17:18:42 kycl4rk Exp $ +# $Id: Oracle.pm,v 1.33 2005-05-25 15:17:49 mwz444 Exp $ # ------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -39,7 +39,7 @@ Creates an SQL DDL suitable for Oracle. use strict; use vars qw[ $VERSION $DEBUG $WARN ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.32 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.33 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use SQL::Translator::Schema::Constants; @@ -190,6 +190,7 @@ sub produce { ); my $field_name_ur = unreserve( $field_name, $table_name ); my $field_def = $field_name_ur; + $field->name( $field_name_ur ); # # Datatype @@ -229,6 +230,15 @@ sub produce { if $WARN; } + if ( $data_type eq 'clob' && $field->is_unique ) { + $data_type = 'varchar2'; + $size[0] = 4000; + warn "CLOB cannot be a unique key, changing to VARCHAR2\n" + if $WARN; + } + + + # # Fixes ORA-00907: missing right parenthesis # @@ -296,7 +306,7 @@ sub produce { # Auto_increment # if ( $field->is_auto_increment ) { - my $base_name = $table_name . "_". $field_name; + my $base_name = $table_name_ur . "_". $field_name; my $seq_name = mk_name( $base_name, 'sq' ); my $trigger_name = mk_name( $base_name, 'ai' ); @@ -317,7 +327,7 @@ sub produce { } if ( lc $field->data_type eq 'timestamp' ) { - my $base_name = $table_name . "_". $field_name_ur; + my $base_name = $table_name_ur . "_". $field_name_ur; my $trig_name = mk_name( $base_name, 'ts' ); push @trigger_defs, "CREATE OR REPLACE TRIGGER $trig_name\n". @@ -532,7 +542,6 @@ sub mk_name { $scope ||= \%global_names; if ( my $prev = $scope->{ $name } ) { my $name_orig = $name; - $name .= sprintf( "%02d", ++$prev ); substr($name, $max_id_length - 2) = "" if length( $name ) >= $max_id_length - 1; $name .= sprintf( "%02d", $prev++ );