From: Ash Berlin Date: Wed, 6 Feb 2008 13:07:14 +0000 (+0000) Subject: Add support for COLLATE table option to MySQL parser X-Git-Tag: v0.11008~341 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a7f49dfb01295ee511d1af5e2451840585c2f38b;hp=11bebd6e1142d51aab716e38d66c9c122247c4bb;p=dbsrgits%2FSQL-Translator.git Add support for COLLATE table option to MySQL parser --- diff --git a/Changes b/Changes index cb8fb97..80ad77a 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,6 @@ +* Add support for COLLATE table option to MySQL parser + # ----------------------------------------------------------- # 0.0899_02 2008-01-29 # ---------------------------------------------------------- diff --git a/lib/SQL/Translator/Parser/MySQL.pm b/lib/SQL/Translator/Parser/MySQL.pm index 6d444d9..6ed40a7 100644 --- a/lib/SQL/Translator/Parser/MySQL.pm +++ b/lib/SQL/Translator/Parser/MySQL.pm @@ -101,9 +101,12 @@ Here's the word from the MySQL site table_options: TYPE = {BDB | HEAP | ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM } + or ENGINE = {BDB | HEAP | ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM } or AUTO_INCREMENT = # or AVG_ROW_LENGTH = # + or [ DEFAULT ] CHARACTER SET charset_name or CHECKSUM = {0 | 1} + or COLLATE collation_name or COMMENT = "string" or MAX_ROWS = # or MIN_ROWS = # @@ -117,6 +120,7 @@ Here's the word from the MySQL site or DATA DIRECTORY="absolute path to directory" or INDEX DIRECTORY="absolute path to directory" + A subset of the ALTER TABLE syntax that allows addition of foreign keys: ALTER [IGNORE] TABLE tbl_name alter_specification [, alter_specification] ... @@ -681,6 +685,10 @@ table_option : /comment/i /=/ /'.*?'/ { $return = { 'CHARACTER SET' => $item[3] }; } + | /collate/i WORD + { + $return = { 'COLLATE' => $item[2] } + } | WORD /\s*=\s*/ WORD { $return = { $item[1] => $item[3] }; @@ -704,7 +712,9 @@ DIGITS : /\d+/ COMMA : ',' -NAME : "`" /\w+/ "`" +BACKTICK : '`' + +NAME : BACKTICK /\w+/ BACKTICK { $item[2] } | /\w+/ { $item[1] } diff --git a/t/02mysql-parser.t b/t/02mysql-parser.t index 553f02d..47d1e69 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(228, "SQL::Translator::Parser::MySQL"); + maybe_plan(232, "SQL::Translator::Parser::MySQL"); SQL::Translator::Parser::MySQL->import('parse'); } @@ -601,4 +601,29 @@ BEGIN { like($proc2->sql, qr/CREATE PROCEDURE sp_update_security_acl/, "Detected procedure sp_update_security_acl"); } +# Tests for collate table option +{ + my $tr = SQL::Translator->new(parser_args => {mysql_parser_version => 50003}); + my $data = parse($tr, + q[ + CREATE TABLE test ( id int ) COLLATE latin1_bin; + ] ); + my $schema = $tr->schema; + is( $schema->is_valid, 1, 'Schema is valid' ); + my @tables = $schema->get_tables; + is( scalar @tables, 1, 'Right number of tables (1)' ); + my $table1 = shift @tables; + is( $table1->name, 'test', 'Found "test" table' ); + + + my $collate = "Not found!"; + for my $t1_option_ref ( $table1->options ) { + my($key, $value) = %{$t1_option_ref}; + if ($key eq 'COLLATE') { + $collate = $value; + last; + } + } + is($collate, 'latin1_bin', "Collate found"); +}