From: Jaime Soriano Pastor Date: Tue, 20 Dec 2011 15:57:26 +0000 (+0100) Subject: Names accepted (and ignored) as types of primary keys in create tables X-Git-Tag: v0.11011~58 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1687dad4f05e3fde92e9d978f6cec31d23d58de3;p=dbsrgits%2FSQL-Translator.git Names accepted (and ignored) as types of primary keys in create tables --- diff --git a/Changes b/Changes index da96e37..a4d69d4 100644 --- a/Changes +++ b/Changes @@ -13,6 +13,7 @@ * Support for double quoted and bit strings as default values in MySQL parser * Check in MySQL parser to avoid trying to parse a table defined twice in the same file as indices (and probably other things) get messed up +* Workaround for some MySQL quirks on primary key definitions # ---------------------------------------------------------- # 0.11010 2011-10-05 diff --git a/lib/SQL/Translator/Parser/MySQL.pm b/lib/SQL/Translator/Parser/MySQL.pm index f7f2a45..da2b6f6 100644 --- a/lib/SQL/Translator/Parser/MySQL.pm +++ b/lib/SQL/Translator/Parser/MySQL.pm @@ -642,14 +642,24 @@ foreign_key_def_begin : /constraint/i /foreign key/i WORD /foreign key/i { $return = '' } -primary_key_def : primary_key index_name_not_using(?) index_type(?) '(' name_with_opt_paren(s /,/) ')' index_type(?) +primary_key_def : primary_key index_type(?) '(' name_with_opt_paren(s /,/) ')' index_type(?) { $return = { supertype => 'constraint', - name => $item[2][0], type => 'primary_key', - fields => $item[5], - options => $item[3][0] || $item[7][0], + fields => $item[4], + options => $item[2][0] || $item[6][0], + }; + } + # In theory, and according to the doc, names should not be allowed here, but + # MySQL accept (and ignores) them, so we are not going to be less :) + | primary_key index_name_not_using(?) '(' name_with_opt_paren(s /,/) ')' index_type(?) + { + $return = { + supertype => 'constraint', + type => 'primary_key', + fields => $item[4], + options => $item[6][0], }; }