From: Daniel Ruoso Date: Mon, 14 Apr 2008 14:02:59 +0000 (+0000) Subject: waiting for patch to be applied X-Git-Tag: v0.11008~328 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=041e659f8750a36d182143f6009f99fe0a8bc698;p=dbsrgits%2FSQL-Translator.git waiting for patch to be applied --- diff --git a/lib/SQL/Translator/Parser/MySQL.pm b/lib/SQL/Translator/Parser/MySQL.pm index 967176a..6890eab 100644 --- a/lib/SQL/Translator/Parser/MySQL.pm +++ b/lib/SQL/Translator/Parser/MySQL.pm @@ -300,7 +300,7 @@ create : CREATE UNIQUE(?) /(index|key)/i index_name /on/i table_name '(' field_n push @{ $tables{ $item{'table_name'} }{'indices'} }, { name => $item[4], - type => $item[2] ? 'unique' : 'normal', + type => $item[2][0] ? 'unique' : 'normal', fields => $item[8], } ; @@ -670,7 +670,7 @@ fulltext_index : /fulltext/i KEY(?) index_name(?) '(' name_with_opt_paren(s /,/) name_with_opt_paren : NAME parens_value_list(s?) { $item[2][0] ? "$item[1]($item[2][0][0])" : $item[1] } -UNIQUE : /unique/i { 1 } +UNIQUE : /unique/i KEY : /key/i | /index/i diff --git a/lib/SQL/Translator/Producer/Oracle.pm b/lib/SQL/Translator/Producer/Oracle.pm index 8986ef3..285ee12 100644 --- a/lib/SQL/Translator/Producer/Oracle.pm +++ b/lib/SQL/Translator/Producer/Oracle.pm @@ -154,7 +154,7 @@ sub produce { my $no_comments = $translator->no_comments; my $add_drop_table = $translator->add_drop_table; my $schema = $translator->schema; - my ($output, $create, @table_defs, @fk_defs, @trigger_defs); + my ($output, $create, @table_defs, @fk_defs, @trigger_defs, @index_defs); $create .= header_comment unless ($no_comments); @@ -169,7 +169,7 @@ sub produce { } for my $table ( $schema->get_tables ) { - my ( $table_def, $fk_def, $trigger_def ) = create_table( + my ( $table_def, $fk_def, $trigger_def, $index_def) = create_table( $table, { add_drop_table => $add_drop_table, @@ -180,6 +180,7 @@ sub produce { push @table_defs, @$table_def; push @fk_defs, @$fk_def; push @trigger_defs, @$trigger_def; + push @index_defs, @$index_def; } my (@view_defs); @@ -187,7 +188,7 @@ sub produce { push @view_defs, create_view($view); } - return wantarray ? (defined $create ? $create : (), @table_defs, @view_defs, @fk_defs, @trigger_defs) : $create . join ("\n\n", @table_defs, @view_defs, @fk_defs, @trigger_defs); + return wantarray ? (defined $create ? $create : (), @table_defs, @view_defs, @fk_defs, @trigger_defs, @index_defs) : $create . join ("\n\n", @table_defs, @view_defs, @fk_defs, @trigger_defs, @index_defs, ''); } sub create_table { @@ -495,6 +496,14 @@ sub create_table { join( ', ', @fields ). ");"; } + elsif ( $index_type eq UNIQUE ) { + $index_name = $index_name ? mk_name( $index_name ) + : mk_name( $table_name, $index_name || 'i' ); + push @index_defs, + "CREATE UNIQUE INDEX $index_name on $table_name_ur (". + join( ', ', @fields ). + ");"; + } else { warn "Unknown index type ($index_type) on table $table_name.\n" if $WARN; @@ -530,7 +539,7 @@ sub create_table { } } - return \@create, \@fk_defs, \@trigger_defs; + return \@create, \@fk_defs, \@trigger_defs, \@index_defs; } sub create_view { diff --git a/t/03mysql-to-oracle.t b/t/03mysql-to-oracle.t index a257552..7fbe09b 100644 --- a/t/03mysql-to-oracle.t +++ b/t/03mysql-to-oracle.t @@ -12,10 +12,13 @@ CREATE TABLE random ( foo varchar(255) not null default '', updated timestamp ); +CREATE UNIQUE INDEX random_foo_update ON random(foo,updated); +CREATE INDEX random_foo ON random(foo); + |; BEGIN { - maybe_plan(1, + maybe_plan(3, 'SQL::Translator::Parser::MySQL', 'SQL::Translator::Producer::Oracle'); } @@ -25,5 +28,8 @@ my $tr = SQL::Translator->new( producer => "Oracle" ); -ok( $tr->translate(\$create), 'Translate MySQL to Oracle' ); +my $output = $tr->translate(\$create); +ok( $output, 'Translate MySQL to Oracle' ); +ok( $output =~ /CREATE INDEX random_foo /, 'Normal index definition translated.'); +ok( $output =~ /CREATE UNIQUE INDEX random_foo_update /, 'Unique index definition translated.');