From: Johannes Plunien Date: Sat, 1 Nov 2008 20:40:22 +0000 (+0000) Subject: If wantarray is set we have to omit the last "/" in this statement so it can be execu... X-Git-Tag: v0.11008~281 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=535e5c952020869d22e846acc7f55fe955f528a0;p=dbsrgits%2FSQL-Translator.git If wantarray is set we have to omit the last "/" in this statement so it can be executed by DBI->do() directly. --- diff --git a/lib/SQL/Translator/Producer/Oracle.pm b/lib/SQL/Translator/Producer/Oracle.pm index 63e55ec..dd08bfa 100644 --- a/lib/SQL/Translator/Producer/Oracle.pm +++ b/lib/SQL/Translator/Producer/Oracle.pm @@ -195,13 +195,14 @@ sub produce { } for my $table ( $schema->get_tables ) { - my ( $table_def, $fk_def, $trigger_def, $index_def, $constraint_def) = create_table( + my ( $table_def, $fk_def, $trigger_def, $index_def, $constraint_def ) = create_table( $table, { - add_drop_table => $add_drop_table, - show_warnings => $WARN, - no_comments => $no_comments, - delay_constraints => $delay_constraints + add_drop_table => $add_drop_table, + show_warnings => $WARN, + no_comments => $no_comments, + delay_constraints => $delay_constraints, + wantarray => wantarray ? 1 : 0, } ); push @table_defs, @$table_def; @@ -631,7 +632,7 @@ sub create_field { push @create, qq[DROP SEQUENCE $seq_name] if $options->{add_drop_table}; push @create, "CREATE SEQUENCE $seq_name"; - push @trigger_defs, + my $trigger = "CREATE OR REPLACE TRIGGER $trigger_name\n" . "BEFORE INSERT ON $table_name_ur\n" . "FOR EACH ROW WHEN (\n" . @@ -642,20 +643,35 @@ sub create_field { " SELECT $seq_name.nextval\n" . " INTO :new." . $field->name."\n" . " FROM dual;\n" . - "END;\n/"; - ; + "END;\n"; + + # + # If wantarray is set we have to omit the last "/" in this statement so it + # can be executed by DBI->do() directly. + # + $trigger .= "/" unless $options->{wantarray}; + + push @trigger_defs, $trigger; } if ( lc $field->data_type eq 'timestamp' ) { my $base_name = $table_name_ur . "_". $field_name_ur; my $trig_name = mk_name( $base_name, 'ts' ); - push @trigger_defs, + my $trigger = "CREATE OR REPLACE TRIGGER $trig_name\n". "BEFORE INSERT OR UPDATE ON $table_name_ur\n". "FOR EACH ROW WHEN (new.$field_name_ur IS NULL)\n". "BEGIN \n". " SELECT sysdate INTO :new.$field_name_ur FROM dual;\n". - "END;\n/"; + "END;\n"; + + # + # If wantarray is set we have to omit the last "/" in this statement so it + # can be executed by DBI->do() directly. + # + $trigger .= "/" unless $options->{wantarray}; + + push @trigger_defs, $trigger; } push @field_defs, $field_def;