hi, sqlfairy developers. I seems Producer::MySQL has a problem.
Following SQL is a valid sql, but Producer::MySQL reject this :( >|| CREATE TABLE foo ( id int unsigned primary key ) ENGINE='innodb'; -- sqlfairy rejects quoted table_option :( ||< Following is a patch for this problem. regards. Index: t/02mysql-parser.t =================================================================== --- t/02mysql-parser.t (revision 1464) +++ t/02mysql-parser.t (working copy) @@ -11,7 +11,7 @@ use Test::SQL::Translator qw(maybe_plan); BEGIN { - maybe_plan(265, "SQL::Translator::Parser::MySQL"); + maybe_plan(274, "SQL::Translator::Parser::MySQL"); SQL::Translator::Parser::MySQL->import('parse'); } @@ -726,3 +726,39 @@ is( $c->type, PRIMARY_KEY, 'Constraint is a PK' ); is( join(',', $c->fields), 'id', 'Constraint is on "id"' ); } + +{ + my $tr = SQL::Translator->new; + my $data = q|create table quote ( + id int(11) NOT NULL auto_increment, + PRIMARY KEY (id), + ) ENGINE='innodb';|; + + my $val = parse($tr, $data); + 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 $table = shift @tables; + is( $table->name, 'quote', 'Found "quote" table' ); + + my $tableTypeFound = 0; + for my $t_option_ref ( $table->options ) { + my($key, $value) = %{$t_option_ref}; + if ( $key eq 'ENGINE' ) { + is($value, 'innodb', 'Table has right table engine option' ); + $tableTypeFound = 1; + } + } + + fail('Table did not have a type option') unless $tableTypeFound; + + my @fields = $table->get_fields; + my $f1 = shift @fields; + is( $f1->name, 'id', 'First field name is "id"' ); + is( $f1->data_type, 'int', 'Type is "int"' ); + is( $f1->size, 11, 'Size is "11"' ); + is( $f1->is_nullable, 0, 'Field cannot be null' ); + is( $f1->is_primary_key, 1, 'Field is PK' ); +} + Index: lib/SQL/Translator/Parser/MySQL.pm =================================================================== --- lib/SQL/Translator/Parser/MySQL.pm (revision 1464) +++ lib/SQL/Translator/Parser/MySQL.pm (working copy) @@ -715,11 +715,17 @@ { $return = { $item[1] => $item[4] }; } - | WORD /\s*=\s*/ WORD - { + | WORD /\s*=\s*/ MAYBE_QUOTED_WORD + { $return = { $item[1] => $item[3] }; } - + +MAYBE_QUOTED_WORD: /\w+/ + | /'(\w+)'/ + { $return = $1 } + | /"\w+"/ + { $return = $1 } + default : /default/i ADD : /add/i ||<
sqlfairy-mysql-table_option-quote.diff
Description: Binary data
------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H
-- sqlfairy-developers mailing list sqlfairy-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlfairy-developers