From: Dagfinn Ilmari Mannsåker Date: Tue, 8 Sep 2015 16:19:50 +0000 (+0100) Subject: Fix parsing of MySQL column comments (RT#83380) X-Git-Tag: v0.11022~24 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=13e41152ed92d297343c9f86ae1a8652c4370b0a;p=dbsrgits%2FSQL-Translator.git Fix parsing of MySQL column comments (RT#83380) --- diff --git a/Changes b/Changes index d7b98a5..0e43239 100644 --- a/Changes +++ b/Changes @@ -13,6 +13,7 @@ Changes for SQL::Translator * Remove dependency on List::MoreUtils ( http://is.gd/lmu_cac_debacle ) * Fix parsing of strings with leading whitespace for MySQL, Oracle, PostgreSQL, SQLServer and SQLite + * Fix parsing of MySQL column comments (RT#83380) 0.11021 2015-01-29 diff --git a/lib/SQL/Translator/Parser/MySQL.pm b/lib/SQL/Translator/Parser/MySQL.pm index 8cdd794..c915af5 100644 --- a/lib/SQL/Translator/Parser/MySQL.pm +++ b/lib/SQL/Translator/Parser/MySQL.pm @@ -476,12 +476,9 @@ field_comment : /^\s*(?:#|-{2}).*\n/ } -field_comment2 : /comment/i SQSTRING - { $return = $item[2] } - blank : /\s*/ -field : field_comment(s?) field_name data_type field_qualifier(s?) field_comment2(?) reference_definition(?) on_update(?) field_comment(s?) +field : field_comment(s?) field_name data_type field_qualifier(s?) reference_definition(?) on_update(?) field_comment(s?) { my %qualifiers = map { %$_ } @{ $item{'field_qualifier(s?)'} || [] }; if ( my @type_quals = @{ $item{'data_type'}{'qualifiers'} || [] } ) { @@ -492,7 +489,7 @@ field : field_comment(s?) field_name data_type field_qualifier(s?) field_comment ? $qualifiers{'not_null'} : 1; delete $qualifiers{'not_null'}; - my @comments = ( @{ $item[1] }, @{ $item[5] }, @{ $item[8] } ); + my @comments = ( @{ $item[1] }, (exists $qualifiers{comment} ? delete $qualifiers{comment} : ()) , @{ $item[7] } ); $return = { supertype => 'field', @@ -578,6 +575,13 @@ field_qualifier : KEY } } +field_qualifier : /comment/i string + { + $return = { + comment => $item[2], + } + } + reference_definition : /references/i table_name parens_field_list(?) match_type(?) on_delete(?) on_update(?) { $return = { diff --git a/t/02mysql-parser.t b/t/02mysql-parser.t index 4b96835..d521b9d 100644 --- a/t/02mysql-parser.t +++ b/t/02mysql-parser.t @@ -252,7 +252,7 @@ BEGIN { my $data = parse($tr, q[ CREATE TABLE orders ( - order_id integer NOT NULL auto_increment, + order_id integer NOT NULL comment ' ' auto_increment, member_id varchar(255) comment 'fk to ''member''', billing_address_id int, shipping_address_id int, @@ -306,6 +306,7 @@ BEGIN { is( $f1->default_value, undef, 'Default value is undefined' ); is( $f1->is_primary_key, 1, 'Field is PK' ); is( $f1->is_auto_increment, 1, 'Field is auto inc' ); + is_deeply( [$f1->comments],[' '], 'Field comment OK' ); my $f2 = shift @fields; is( $f2->name, 'member_id', 'Second field name is "member_id"' );