Unverified Commit 75bf53d7 authored by Jonathan H. Wage's avatar Jonathan H. Wage Committed by Sergei Morozov

Merge pull request #3583 from morozov/event-types-cleanup

Getting rid of the column name index
parents d04026ff 81c9d601
# Upgrade to 3.0 # Upgrade to 3.0
## BC BREAK: Changes in `Doctrine\DBAL\Event\SchemaCreateTableEventArgs`
Table columns are no longer indexed by column name. Use the `name` attribute of the column instead.
## BC BREAK: Changes in the `Doctrine\DBAL\Schema` API ## BC BREAK: Changes in the `Doctrine\DBAL\Schema` API
- Column precision no longer defaults to 10. The default value is NULL. - Column precision no longer defaults to 10. The default value is NULL.
......
...@@ -9,14 +9,15 @@ use Doctrine\DBAL\Schema\Table; ...@@ -9,14 +9,15 @@ use Doctrine\DBAL\Schema\Table;
use function array_merge; use function array_merge;
/** /**
* Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\AbstractPlatform. * Event Arguments used when SQL queries for creating tables are generated
* inside Doctrine\DBAL\Platform\AbstractPlatform.
*/ */
class SchemaCreateTableEventArgs extends SchemaEventArgs class SchemaCreateTableEventArgs extends SchemaEventArgs
{ {
/** @var Table */ /** @var Table */
private $table; private $table;
/** @var array<string, array<string, mixed>> */ /** @var array<int, array<string, mixed>> */
private $columns; private $columns;
/** @var array<string, mixed> */ /** @var array<string, mixed> */
...@@ -29,8 +30,8 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs ...@@ -29,8 +30,8 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
private $sql = []; private $sql = [];
/** /**
* @param array<string, array<string, mixed>> $columns * @param array<int, array<string, mixed>> $columns
* @param array<string, mixed> $options * @param array<string, mixed> $options
*/ */
public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform) public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform)
{ {
...@@ -46,7 +47,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs ...@@ -46,7 +47,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
} }
/** /**
* @return array<string, array<string, mixed>> * @return array<int, array<string, mixed>>
*/ */
public function getColumns() : array public function getColumns() : array
{ {
......
...@@ -1345,10 +1345,7 @@ abstract class AbstractPlatform ...@@ -1345,10 +1345,7 @@ abstract class AbstractPlatform
$columnData['primary'] = true; $columnData['primary'] = true;
} }
$columnName = $columnData['name']; $columns[] = $columnData;
assert(is_string($columnName));
$columns[$columnName] = $columnData;
} }
if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) { if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) {
...@@ -1875,9 +1872,9 @@ abstract class AbstractPlatform ...@@ -1875,9 +1872,9 @@ abstract class AbstractPlatform
/** /**
* Gets declaration of a number of fields in bulk. * Gets declaration of a number of fields in bulk.
* *
* @param mixed[][] $fields A multidimensional associative array. * @param mixed[][] $fields A multidimensional array.
* The first dimension determines the field name, while the second * The first dimension determines the ordinal position of the field,
* dimension is keyed with the name of the properties * while the second dimension is keyed with the name of the properties
* of the field being declared as array indexes. Currently, the types * of the field being declared as array indexes. Currently, the types
* of supported field properties are as follows: * of supported field properties are as follows:
* *
...@@ -1903,8 +1900,8 @@ abstract class AbstractPlatform ...@@ -1903,8 +1900,8 @@ abstract class AbstractPlatform
{ {
$queryFields = []; $queryFields = [];
foreach ($fields as $fieldName => $field) { foreach ($fields as $field) {
$queryFields[] = $this->getColumnDeclarationSQL($fieldName, $field); $queryFields[] = $this->getColumnDeclarationSQL($field['name'], $field);
} }
return implode(', ', $queryFields); return implode(', ', $queryFields);
...@@ -2050,19 +2047,19 @@ abstract class AbstractPlatform ...@@ -2050,19 +2047,19 @@ abstract class AbstractPlatform
public function getCheckDeclarationSQL(array $definition) : string public function getCheckDeclarationSQL(array $definition) : string
{ {
$constraints = []; $constraints = [];
foreach ($definition as $field => $def) { foreach ($definition as $def) {
if (is_string($def)) { if (is_string($def)) {
$constraints[] = 'CHECK (' . $def . ')'; $constraints[] = 'CHECK (' . $def . ')';
} else { } else {
if (isset($def['min'])) { if (isset($def['min'])) {
$constraints[] = 'CHECK (' . $field . ' >= ' . $def['min'] . ')'; $constraints[] = 'CHECK (' . $def['name'] . ' >= ' . $def['min'] . ')';
} }
if (! isset($def['max'])) { if (! isset($def['max'])) {
continue; continue;
} }
$constraints[] = 'CHECK (' . $field . ' <= ' . $def['max'] . ')'; $constraints[] = 'CHECK (' . $def['name'] . ' <= ' . $def['max'] . ')';
} }
} }
......
...@@ -367,17 +367,16 @@ class OraclePlatform extends AbstractPlatform ...@@ -367,17 +367,16 @@ class OraclePlatform extends AbstractPlatform
$options['indexes'] = []; $options['indexes'] = [];
$sql = parent::_getCreateTableSQL($tableName, $columns, $options); $sql = parent::_getCreateTableSQL($tableName, $columns, $options);
foreach ($columns as $name => $column) { foreach ($columns as $column) {
if (isset($column['sequence'])) { if (isset($column['sequence'])) {
$sql[] = $this->getCreateSequenceSQL($column['sequence']); $sql[] = $this->getCreateSequenceSQL($column['sequence']);
} }
if (! isset($column['autoincrement']) || ! $column['autoincrement'] && if (empty($column['autoincrement'])) {
(! isset($column['autoinc']) || ! $column['autoinc'])) {
continue; continue;
} }
$sql = array_merge($sql, $this->getCreateAutoincrementSql($name, $tableName)); $sql = array_merge($sql, $this->getCreateAutoincrementSql($column['name'], $tableName));
} }
if (isset($indexes) && ! empty($indexes)) { if (isset($indexes) && ! empty($indexes)) {
......
...@@ -368,8 +368,10 @@ class SqlitePlatform extends AbstractPlatform ...@@ -368,8 +368,10 @@ class SqlitePlatform extends AbstractPlatform
$keyColumns = array_unique(array_values($options['primary'])); $keyColumns = array_unique(array_values($options['primary']));
foreach ($keyColumns as $keyColumn) { foreach ($keyColumns as $keyColumn) {
if (! empty($columns[$keyColumn]['autoincrement'])) { foreach ($columns as $column) {
return ''; if ($column['name'] === $keyColumn && ! empty($column['autoincrement'])) {
return '';
}
} }
} }
......
...@@ -44,8 +44,15 @@ class TemporaryTableTest extends DbalFunctionalTestCase ...@@ -44,8 +44,15 @@ class TemporaryTableTest extends DbalFunctionalTestCase
} }
$platform = $this->connection->getDatabasePlatform(); $platform = $this->connection->getDatabasePlatform();
$columnDefinitions = ['id' => ['type' => Type::getType('integer'), 'notnull' => true]]; $columnDefinitions = [
$tempTable = $platform->getTemporaryTableName('my_temporary'); [
'name' => 'id',
'type' => Type::getType('integer'),
'notnull' => true,
],
];
$tempTable = $platform->getTemporaryTableName('my_temporary');
$createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
. $platform->getColumnDeclarationListSQL($columnDefinitions) . ')'; . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
...@@ -79,8 +86,15 @@ class TemporaryTableTest extends DbalFunctionalTestCase ...@@ -79,8 +86,15 @@ class TemporaryTableTest extends DbalFunctionalTestCase
} }
$platform = $this->connection->getDatabasePlatform(); $platform = $this->connection->getDatabasePlatform();
$columnDefinitions = ['id' => ['type' => Type::getType('integer'), 'notnull' => true]]; $columnDefinitions = [
$tempTable = $platform->getTemporaryTableName('my_temporary'); [
'name' => 'id',
'type' => Type::getType('integer'),
'notnull' => true,
],
];
$tempTable = $platform->getTemporaryTableName('my_temporary');
$createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' $createTempTableSQL = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' ('
. $platform->getColumnDeclarationListSQL($columnDefinitions) . ')'; . $platform->getColumnDeclarationListSQL($columnDefinitions) . ')';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment