diff --git a/src/Metadata/Object/ColumnObject.php b/src/Metadata/Object/ColumnObject.php index 4dbe2b80..9cc6f6f4 100644 --- a/src/Metadata/Object/ColumnObject.php +++ b/src/Metadata/Object/ColumnObject.php @@ -82,6 +82,18 @@ class ColumnObject */ protected $errata = []; + /** + * + * @var string + */ + protected $column_key = null; + + /** + * + * @var string + */ + protected $extra = null; + /** * Constructor * @@ -378,4 +390,40 @@ public function setErrata($errataName, $errataValue) $this->errata[$errataName] = $errataValue; return $this; } + + /** + * @return null|string the $columnKey + */ + public function getColumnKey() + { + return $this->column_key; + } + + /** + * @param string $columnKey the $columnKey to set + * @return self Provides a fluent interface + */ + public function setColumnKey($columnKey) + { + $this->column_key = $columnKey; + return $this; + } + + /** + * @return null|string the $extra + */ + public function getExtra() + { + return $this->extra; + } + + /** + * @param string $extra the $extra to set + * @return self Provides a fluent interface + */ + public function setExtra($extra) + { + $this->extra = $extra; + return $this; + } } diff --git a/src/Metadata/Source/AbstractSource.php b/src/Metadata/Source/AbstractSource.php index 252dcc45..85c606a3 100644 --- a/src/Metadata/Source/AbstractSource.php +++ b/src/Metadata/Source/AbstractSource.php @@ -243,7 +243,7 @@ public function getColumn($columnName, $table, $schema = null) 'ordinal_position', 'column_default', 'is_nullable', 'data_type', 'character_maximum_length', 'character_octet_length', 'numeric_precision', 'numeric_scale', 'numeric_unsigned', - 'erratas' + 'erratas', 'column_key', 'extra' ]; foreach ($props as $prop) { if (isset($info[$prop])) { @@ -261,6 +261,8 @@ public function getColumn($columnName, $table, $schema = null) $column->setNumericScale($info['numeric_scale']); $column->setNumericUnsigned($info['numeric_unsigned']); $column->setErratas($info['erratas']); + $column->setColumnKey($info['column_key']); + $column->setExtra($info['extra']); return $column; } diff --git a/src/Metadata/Source/MysqlMetadata.php b/src/Metadata/Source/MysqlMetadata.php index 3f9e8692..54f0a107 100644 --- a/src/Metadata/Source/MysqlMetadata.php +++ b/src/Metadata/Source/MysqlMetadata.php @@ -105,9 +105,11 @@ protected function loadColumnData($table, $schema) ['C', 'NUMERIC_SCALE'], ['C', 'COLUMN_NAME'], ['C', 'COLUMN_TYPE'], + ['C', 'COLUMN_KEY'], + ['C', 'EXTRA'], ]; - array_walk($isColumns, function (&$c) use ($p) { + array_walk($isColumns, static function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); @@ -154,7 +156,7 @@ protected function loadColumnData($table, $schema) $columns[$row['COLUMN_NAME']] = [ 'ordinal_position' => $row['ORDINAL_POSITION'], 'column_default' => $row['COLUMN_DEFAULT'], - 'is_nullable' => ('YES' == $row['IS_NULLABLE']), + 'is_nullable' => ('YES' === $row['IS_NULLABLE']), 'data_type' => $row['DATA_TYPE'], 'character_maximum_length' => $row['CHARACTER_MAXIMUM_LENGTH'], 'character_octet_length' => $row['CHARACTER_OCTET_LENGTH'], @@ -162,6 +164,8 @@ protected function loadColumnData($table, $schema) 'numeric_scale' => $row['NUMERIC_SCALE'], 'numeric_unsigned' => (false !== strpos($row['COLUMN_TYPE'], 'unsigned')), 'erratas' => $erratas, + 'column_key' => $row['COLUMN_KEY'], + 'extra' => $row['EXTRA'], ]; } @@ -191,7 +195,7 @@ protected function loadConstraintData($table, $schema) $p = $this->adapter->getPlatform(); - array_walk($isColumns, function (&$c) use ($p) { + array_walk($isColumns, static function (&$c) use ($p) { $c = $p->quoteIdentifierChain($c); }); @@ -223,7 +227,7 @@ protected function loadConstraintData($table, $schema) . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_TYPE']) . ' IN (\'BASE TABLE\', \'VIEW\')'; - if ($schema != self::DEFAULT_SCHEMA) { + if ($schema !== self::DEFAULT_SCHEMA) { $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) . ' = ' . $p->quoteTrustedValue($schema); } else { @@ -244,36 +248,33 @@ protected function loadConstraintData($table, $schema) $realName = null; $constraints = []; - foreach ($results->toArray() as $row) { - if ($row['CONSTRAINT_NAME'] !== $realName) { - $realName = $row['CONSTRAINT_NAME']; - $isFK = ('FOREIGN KEY' == $row['CONSTRAINT_TYPE']); - if ($isFK) { + if ($results !== null) { + foreach ($results->toArray() as $row) { + if ($row['CONSTRAINT_NAME'] !== $realName) { + $realName = $row['CONSTRAINT_NAME']; + $isFK = ('FOREIGN KEY' === $row['CONSTRAINT_TYPE']); $name = $realName; - } else { - $name = '_laminas_' . $row['TABLE_NAME'] . '_' . $realName; + $constraints[$name] = [ + 'constraint_name' => $name, + 'constraint_type' => $row['CONSTRAINT_TYPE'], + 'table_name' => $row['TABLE_NAME'], + 'columns' => [], + ]; + if ($isFK) { + $constraints[$name]['referenced_table_schema'] = $row['REFERENCED_TABLE_SCHEMA']; + $constraints[$name]['referenced_table_name'] = $row['REFERENCED_TABLE_NAME']; + $constraints[$name]['referenced_columns'] = []; + $constraints[$name]['match_option'] = $row['MATCH_OPTION']; + $constraints[$name]['update_rule'] = $row['UPDATE_RULE']; + $constraints[$name]['delete_rule'] = $row['DELETE_RULE']; + } } - $constraints[$name] = [ - 'constraint_name' => $name, - 'constraint_type' => $row['CONSTRAINT_TYPE'], - 'table_name' => $row['TABLE_NAME'], - 'columns' => [], - ]; + $constraints[$name]['columns'][] = $row['COLUMN_NAME']; if ($isFK) { - $constraints[$name]['referenced_table_schema'] = $row['REFERENCED_TABLE_SCHEMA']; - $constraints[$name]['referenced_table_name'] = $row['REFERENCED_TABLE_NAME']; - $constraints[$name]['referenced_columns'] = []; - $constraints[$name]['match_option'] = $row['MATCH_OPTION']; - $constraints[$name]['update_rule'] = $row['UPDATE_RULE']; - $constraints[$name]['delete_rule'] = $row['DELETE_RULE']; + $constraints[$name]['referenced_columns'][] = $row['REFERENCED_COLUMN_NAME']; } } - $constraints[$name]['columns'][] = $row['COLUMN_NAME']; - if ($isFK) { - $constraints[$name]['referenced_columns'][] = $row['REFERENCED_COLUMN_NAME']; - } } - $this->data['constraints'][$schema][$table] = $constraints; }