From: Ash Berlin Date: Wed, 6 Feb 2008 13:22:27 +0000 (+0000) Subject: Allow DEFAULT CHARACTER SET without '=' (as produced by mysqldump) X-Git-Tag: v0.11008~340 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bb4c66d1b6c76b02227f963a1d801d52d53eaf3e;p=dbsrgits%2FSQL-Translator.git Allow DEFAULT CHARACTER SET without '=' (as produced by mysqldump) --- diff --git a/Changes b/Changes index 80ad77a..0245911 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ * Add support for COLLATE table option to MySQL parser +* Allow DEFAULT CHARACTER SET without '=' (as produced by mysqldump) # ----------------------------------------------------------- # 0.0899_02 2008-01-29 diff --git a/lib/SQL/Translator/Parser/MySQL.pm b/lib/SQL/Translator/Parser/MySQL.pm index 6ed40a7..967176a 100644 --- a/lib/SQL/Translator/Parser/MySQL.pm +++ b/lib/SQL/Translator/Parser/MySQL.pm @@ -681,7 +681,7 @@ table_option : /comment/i /=/ /'.*?'/ $comment =~ s/'$//; $return = { comment => $comment }; } - | /(default )?(charset|character set)/i /\s*=\s*/ WORD + | /(default )?(charset|character set)/i /\s*=?\s*/ WORD { $return = { 'CHARACTER SET' => $item[3] }; } diff --git a/t/02mysql-parser.t b/t/02mysql-parser.t index 47d1e69..ae42ae5 100644 --- a/t/02mysql-parser.t +++ b/t/02mysql-parser.t @@ -10,7 +10,7 @@ use SQL::Translator::Schema::Constants; use Test::SQL::Translator qw(maybe_plan); BEGIN { - maybe_plan(232, "SQL::Translator::Parser::MySQL"); + maybe_plan(233, "SQL::Translator::Parser::MySQL"); SQL::Translator::Parser::MySQL->import('parse'); } @@ -606,7 +606,7 @@ BEGIN { my $tr = SQL::Translator->new(parser_args => {mysql_parser_version => 50003}); my $data = parse($tr, q[ - CREATE TABLE test ( id int ) COLLATE latin1_bin; + CREATE TABLE test ( id int ) DEFAULT CHARACTER SET latin1 COLLATE latin1_bin; ] ); my $schema = $tr->schema; @@ -618,12 +618,13 @@ BEGIN { my $collate = "Not found!"; + my $charset = "Not found!"; for my $t1_option_ref ( $table1->options ) { + $DB::single = 1; my($key, $value) = %{$t1_option_ref}; - if ($key eq 'COLLATE') { - $collate = $value; - last; - } + $collate = $value if $key eq 'COLLATE'; + $charset = $value if $key eq 'CHARACTER SET'; } is($collate, 'latin1_bin', "Collate found"); + is($charset, 'latin1', "Character set found"); }