From: Alexander Hartmaier Date: Thu, 17 Dec 2009 21:12:29 +0000 (+0000) Subject: Fix Oracle producer creating numeric precision statements that the test case expects... X-Git-Tag: v0.11008~73 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=64ac5763f7f2f0d7178ef3b57cb6108704c57b93;p=dbsrgits%2FSQL-Translator.git Fix Oracle producer creating numeric precision statements that the test case expects (no whitespace) Add Oracle producer creating drop view statements like PG producer does --- diff --git a/Changes b/Changes index 1452d27..e1a2946 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ * Fix PG producer numeric precision regression (RT#49301) * Add DB2 producer numeric/decimal precision output +* Fix Oracle producer creating numeric precision statements that the test case expects (no whitespace) +* Add Oracle producer creating drop view statements like PG producer does # ---------------------------------------------------------- # 0.11003 2009-09-28 diff --git a/lib/SQL/Translator/Producer/Oracle.pm b/lib/SQL/Translator/Producer/Oracle.pm index a1bf01d..371f121 100644 --- a/lib/SQL/Translator/Producer/Oracle.pm +++ b/lib/SQL/Translator/Producer/Oracle.pm @@ -250,7 +250,6 @@ sub produce { show_warnings => $WARN, no_comments => $no_comments, delay_constraints => $delay_constraints, - wantarray => wantarray ? 1 : 0, } ); push @table_defs, @$table_def; @@ -262,7 +261,13 @@ sub produce { my (@view_defs); foreach my $view ( $schema->get_views ) { - push @view_defs, create_view($view); + my ( $view_def ) = create_view( + $view, + { + add_drop_view => $add_drop_table, + } + ); + push @view_defs, @$view_def; } if (wantarray) { @@ -270,8 +275,12 @@ sub produce { } else { $create .= join ('', map { $_ ? "$_;\n\n" : () } @table_defs, @view_defs, @fk_defs, @index_defs, @constraint_defs); + # If wantarray is not set we have to add "/" in this statement + # DBI->do() needs them omitted # triggers may NOT end with a semicolon - $create .= join "\n\n", @trigger_defs; + $create .= join "/\n\n", @trigger_defs; + # for last trigger + $create .= "/\n\n"; return $create; } } @@ -279,7 +288,7 @@ sub produce { sub create_table { my ($table, $options) = @_; my $table_name = $table->name; - + my $item = ''; my $drop; my (@create, @field_defs, @constraint_defs, @fk_defs, @trigger_defs); @@ -693,12 +702,6 @@ sub create_field { " FROM dual;\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; } @@ -713,12 +716,6 @@ sub create_field { " SELECT sysdate INTO :new.$field_name_ur FROM dual;\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; } @@ -737,13 +734,18 @@ sub create_field { sub create_view { - my ($view) = @_; + my ($view, $options) = @_; + my $view_name = $view->name; + + my @create; + push @create, qq[DROP VIEW $view_name] + if $options->{add_drop_view}; - my $out = sprintf("CREATE VIEW %s AS\n%s", - $view->name, + push @create, sprintf("CREATE VIEW %s AS\n%s", + $view_name, $view->sql); - return $out; + return \@create; } # ------------------------------------------------------------------- diff --git a/t/51-xml-to-oracle.t b/t/51-xml-to-oracle.t index 39931ca..fbb748d 100644 --- a/t/51-xml-to-oracle.t +++ b/t/51-xml-to-oracle.t @@ -62,6 +62,7 @@ my $want = [ num number(10,2), PRIMARY KEY (id) )', +'DROP VIEW email_list', 'CREATE VIEW email_list AS SELECT email FROM Basic WHERE (email IS NOT NULL)', 'ALTER TABLE Basic ADD CONSTRAINT Basic_another_id_fk FOREIGN KEY (another_id) REFERENCES Another (id)', @@ -130,6 +131,8 @@ CREATE TABLE Another ( PRIMARY KEY (id) ); +DROP VIEW email_list; + CREATE VIEW email_list AS SELECT email FROM Basic WHERE (email IS NOT NULL); @@ -167,4 +170,6 @@ BEGIN INTO :new.id FROM dual; END; -/|); +/ + +|);