From: Peter Rabbitson Date: Thu, 3 Jun 2010 09:08:31 +0000 (+0000) Subject: Adjust view production for stupid mysql X-Git-Tag: v0.11008~42 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1c8ec56e310980f823b2ea35fab59d7a139fa96a;p=dbsrgits%2FSQL-Translator.git Adjust view production for stupid mysql --- diff --git a/Changes b/Changes index c7a1e64..31a0d6e 100644 --- a/Changes +++ b/Changes @@ -5,6 +5,7 @@ * Fix Producer::Oracle generation of too long unique constraint names * Fix Producer::SQLite when generating VIEWs with add_drop_table => 1 * Fix Producer::MySQL not quoting index names when requested (RT#56173) +* Fix Producer::MySQL wrapping extra ()s around VIEW SELECT-ors (RT#56419) * Fix Field::default_value to behave like a real accessor (allow undef as an unsetting argument) * Producer::Oracle tests now use Test::Differences diff --git a/lib/SQL/Translator/Producer/MySQL.pm b/lib/SQL/Translator/Producer/MySQL.pm index 2214e8a..f261a9f 100644 --- a/lib/SQL/Translator/Producer/MySQL.pm +++ b/lib/SQL/Translator/Producer/MySQL.pm @@ -364,7 +364,9 @@ sub create_view { $create .= " ( ${list} )"; } if( my $sql = $view->sql ){ - $create .= " AS (\n ${sql}\n )"; + # do not wrap parenthesis around the selector, mysql doesn't like this + # http://bugs.mysql.com/bug.php?id=9198 + $create .= " AS\n ${sql}\n"; } # $create .= ""; return $create; diff --git a/t/38-mysql-producer.t b/t/38-mysql-producer.t index 61d2289..0660697 100644 --- a/t/38-mysql-producer.t +++ b/t/38-mysql-producer.t @@ -379,13 +379,15 @@ is ( my $create_opts = { add_replace_view => 1, no_comments => 1 }; my $view1_sql1 = SQL::Translator::Producer::MySQL::create_view($view1, $create_opts); - my $view_sql_replace = "CREATE OR REPLACE + my $view_sql_replace = <<'EOV'; +CREATE OR REPLACE ALGORITHM = MERGE DEFINER = CURRENT_USER SQL SECURITY DEFINER - VIEW view_foo ( id, name ) AS ( + VIEW view_foo ( id, name ) AS SELECT id, name FROM thing - )"; +EOV + is($view1_sql1, $view_sql_replace, 'correct "CREATE OR REPLACE VIEW" SQL'); @@ -394,12 +396,14 @@ is ( sql => 'SELECT id, name FROM thing',); my $create2_opts = { add_replace_view => 0, no_comments => 1 }; my $view1_sql2 = SQL::Translator::Producer::MySQL::create_view($view2, $create2_opts); - my $view_sql_noreplace = "CREATE - VIEW view_foo ( id, name ) AS ( + my $view_sql_noreplace = <<'EOV'; +CREATE + VIEW view_foo ( id, name ) AS SELECT id, name FROM thing - )"; +EOV + is($view1_sql2, $view_sql_noreplace, 'correct "CREATE VIEW" SQL'); - + { my %extra = $view1->extra; is_deeply \%extra,