diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Components/Key.php | 41 | ||||
-rw-r--r-- | src/Utils/Table.php | 7 |
2 files changed, 44 insertions, 4 deletions
diff --git a/src/Components/Key.php b/src/Components/Key.php index 89371fa..70b2b93 100644 --- a/src/Components/Key.php +++ b/src/Components/Key.php @@ -96,6 +96,13 @@ class Key extends Component $ret = new Key(); /** + * Last parsed column. + * + * @var array + */ + $lastColumn = array(); + + /** * The state of the parser. * * Below are the states 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/src/Utils/Table.php b/src/Utils/Table.php index 81699ad..5f0858d 100644 --- a/src/Utils/Table.php +++ b/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)) { |