From: Jaime Soriano Pastor Date: Wed, 28 Dec 2011 19:08:16 +0000 (+0100) Subject: Workaround for quoted index fields with length X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f69418350a20440ea8fa15051fae69a83668929c;p=dbsrgits%2FSQL-Translator.git Workaround for quoted index fields with length --- diff --git a/lib/SQL/Translator/Producer/MySQL.pm b/lib/SQL/Translator/Producer/MySQL.pm index bd53796..0705221 100644 --- a/lib/SQL/Translator/Producer/MySQL.pm +++ b/lib/SQL/Translator/Producer/MySQL.pm @@ -465,7 +465,6 @@ sub create_table # $create .= "\n)"; $create .= generate_table_options($table, $options) || ''; -# $create .= ";\n\n"; return $drop ? ($drop,$create) : $create; } @@ -654,6 +653,13 @@ sub create_index my $qf = $options->{quote_field_names} || ''; + my $fields = '(' . $qf . join( "$qf, $qf", $index->fields ) . $qf . ')'; + # Workaround for quoted index fields, as they are stored with the length + # postfixed to the name, they are quoted as `foo(length)` when they should + # be quoted as `foo`(length), the good fix would be to store the information + # in the parser and propagate it till here + $fields =~ s/\((\d+)\)$qf/$qf($1)/g; + return join( ' ', map { $_ || () } @@ -663,8 +669,7 @@ sub create_index $index->name, $options->{max_id_length} || $DEFAULT_MAX_ID_LENGTH ) . $qf - : '', - '(' . $qf . join( "$qf, $qf", $index->fields ) . $qf . ')' + : '', $fields ); }