From: Johannes Plunien Date: Sat, 1 Nov 2008 20:37:56 +0000 (+0000) Subject: ensure to not exceed max allowed size for oracle data types X-Git-Tag: v0.11008~286 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e3aac687ba2633584ce0265998b3c17c8a42d63a;p=dbsrgits%2FSQL-Translator.git ensure to not exceed max allowed size for oracle data types --- diff --git a/lib/SQL/Translator/Producer/Oracle.pm b/lib/SQL/Translator/Producer/Oracle.pm index b02d50a..4a3a8e0 100644 --- a/lib/SQL/Translator/Producer/Oracle.pm +++ b/lib/SQL/Translator/Producer/Oracle.pm @@ -151,6 +151,20 @@ my %ora_reserved = map { $_, 1 } qw( WHENEVER WHERE WITH ); +# +# Oracle 8/9 max size of data types from: +# http://www.ss64.com/orasyntax/datatypes.html +# +my %max_size = ( + char => 2000, + nchar => 2000, + nvarchar2 => 4000, + number => [ 38, 127 ], + raw => 2000, + varchar => 4000, # only synonym for varchar2 + varchar2 => 4000, +); + my $max_id_length = 30; my %used_identifiers = (); my %global_names; @@ -506,6 +520,17 @@ sub create_field { $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++ ) { + my $max = + ref( $max_size{$data_type} ) eq 'ARRAY' + ? $max_size{$data_type}->[$i] + : $max_size{$data_type}; + $size[$i] = $max if $size[$i] > $max; + } + } # # Fixes ORA-02329: column of datatype LOB cannot be