X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F38-mysql-producer.t;h=0660697e42ff3658f7f7975f213390a64efc5673;hb=b307a0db18f6d0a82ecfc4c0ab71ca62353c69bb;hp=ae2c64d52a63e2ae202f053c27eb98fd795a0ea4;hpb=8d693a858511dc5ff4c19ded853954f909b8bd77;p=dbsrgits%2FSQL-Translator.git diff --git a/t/38-mysql-producer.t b/t/38-mysql-producer.t index ae2c64d..0660697 100644 --- a/t/38-mysql-producer.t +++ b/t/38-mysql-producer.t @@ -19,7 +19,7 @@ use FindBin qw/$Bin/; #============================================================================= BEGIN { - maybe_plan(32, + maybe_plan(40, 'YAML', 'SQL::Translator::Producer::MySQL', 'Test::Differences', @@ -148,8 +148,8 @@ my @stmts = ( `foo` integer, `foo2` integer, `bar_set` set('foo', 'bar', 'baz'), - INDEX index_1 (`id`), - INDEX really_long_name_bigger_than_64_chars_aaaaaaaaaaaaaaaaa_aed44c47 (`id`), + INDEX `index_1` (`id`), + INDEX `really_long_name_bigger_than_64_chars_aaaaaaaaaaaaaaaaa_aed44c47` (`id`), INDEX (`foo`), INDEX (`foo2`), PRIMARY KEY (`id`, `foo`), @@ -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,9 +396,55 @@ 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, + { + 'mysql_algorithm' => 'MERGE', + 'mysql_definer' => 'CURRENT_USER', + 'mysql_security' => 'DEFINER' + }, + 'Extra attributes'; + } + + $view1->remove_extra(qw/mysql_definer mysql_security/); + { + my %extra = $view1->extra; + is_deeply \%extra, { 'mysql_algorithm' => 'MERGE', }, 'Extra attributes after first reset_extra call'; + } + + $view1->remove_extra(); + { + my %extra = $view1->extra; + is_deeply \%extra, {}, 'Extra attributes completely removed'; + } +} + +{ + + # certain types do not support a size, see also: + # http://dev.mysql.com/doc/refman/5.1/de/create-table.html + for my $type (qw/date time timestamp datetime year/) { + my $field = SQL::Translator::Schema::Field->new( + name => "my$type", + table => $table, + data_type => $type, + size => 10, + default_value => undef, + is_auto_increment => 0, + is_nullable => 1, + is_foreign_key => 0, + is_unique => 0 + ); + my $sql = SQL::Translator::Producer::MySQL::create_field($field); + is($sql, "my$type $type", "Skip length param for type $type"); + } }