diff --git a/ChangeLog b/ChangeLog index 8050581c9e..6398cc6499 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,9 @@ phpMyAdmin - ChangeLog - issue #11495 'PMA_Microhistory' is undefined - issue #11496 Incorrect definition for getTablesWhenOpen() +4.5.0.2 (2015-09-25) +- issue #11497 Incorrect indexes when exporting + 4.5.0.1 (2015-09-24) - issue #11492 AUTO_INCREMENT statements are partly missing from exports diff --git a/libraries/plugins/export/ExportSql.class.php b/libraries/plugins/export/ExportSql.class.php index 51ed21dac8..f8661a6806 100644 --- a/libraries/plugins/export/ExportSql.class.php +++ b/libraries/plugins/export/ExportSql.class.php @@ -2574,9 +2574,9 @@ class ExportSql extends ExportPlugin // Key's columns. if (!empty($field->key)) { foreach ($field->key->columns as $key => $column) { - if (!empty($aliases[$old_database]['tables'][$old_table]['columns'][$column])) { - $field->key->columns[$key] = $aliases[$old_database] - ['tables'][$old_table]['columns'][$column]; + if (!empty($aliases[$old_database]['tables'][$old_table]['columns'][$column['name']])) { + $field->key->columns[$key]['name'] = $aliases[$old_database] + ['tables'][$old_table]['columns'][$column['name']]; $flag = true; } } diff --git a/libraries/sql-parser/src/Components/Key.php b/libraries/sql-parser/src/Components/Key.php index 89371fa9f5..70b2b937e3 100644 --- a/libraries/sql-parser/src/Components/Key.php +++ b/libraries/sql-parser/src/Components/Key.php @@ -95,6 +95,13 @@ class Key extends Component { $ret = new Key(); + /** + * Last parsed column. + * + * @var array + */ + $lastColumn = array(); + /** * The state of the parser. * @@ -135,12 +142,31 @@ class Key extends Component $state = 1; } elseif ($state === 1) { if (($token->type === Token::TYPE_OPERATOR) && ($token->value === '(')) { - $ret->columns = ArrayObj::parse($parser, $list)->values; $state = 2; } else { $ret->name = $token->value; } } elseif ($state === 2) { + if ($token->type === Token::TYPE_OPERATOR) { + if ($token->value === '(') { + $state = 3; + } elseif (($token->value === ',') || ($token->value === ')')) { + $state = ($token->value === ',') ? 2 : 4; + if (!empty($lastColumn)) { + $ret->columns[] = $lastColumn; + $lastColumn = array(); + } + } + } else { + $lastColumn['name'] = $token->value; + } + } elseif ($state === 3) { + if (($token->type === Token::TYPE_OPERATOR) && ($token->value === ')')) { + $state = 2; + } else { + $lastColumn['length'] = $token->value; + } + } elseif ($state === 4) { $ret->options = OptionsArray::parse($parser, $list, static::$KEY_OPTIONS); ++$list->idx; break; @@ -163,8 +189,17 @@ class Key extends Component if (!empty($component->name)) { $ret .= Context::escape($component->name) . ' '; } - $ret .= '(' . implode(',', Context::escape($component->columns)) . ') ' - . $component->options; + + $columns = array(); + foreach ($component->columns as $column) { + $tmp = Context::escape($column['name']); + if (isset($column['length'])) { + $tmp .= '(' . $column['length'] . ')'; + } + $columns[] = $tmp; + } + + $ret .= '(' . implode(',', $columns) . ') ' . $component->options; return trim($ret); } } diff --git a/libraries/sql-parser/src/Utils/Table.php b/libraries/sql-parser/src/Utils/Table.php index 81699ad6d0..5f0858d4a3 100644 --- a/libraries/sql-parser/src/Utils/Table.php +++ b/libraries/sql-parser/src/Utils/Table.php @@ -45,9 +45,14 @@ class Table continue; } + $columns = array(); + foreach ($field->key->columns as $column) { + $columns[] = $column['name']; + } + $tmp = array( 'constraint' => $field->name, - 'index_list' => $field->key->columns, + 'index_list' => $columns, ); if (!empty($field->references)) {