Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added support of key length for text indexes #241

Closed
wants to merge 1 commit into from

5 participants

@maxlun86

Now, support is added only for schema export.

@doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DBAL-405

@beberlei
Owner

I don't like this patch very much, it feels so generic and uses wordings thats are not really from the SQL language.

Also the flags feature is actually meant to add additional information for indexes.

@beberlei beberlei closed this
@maxlun86

It means, that this pull request is disposed?

@Ocramius
Owner

@maxlun86 as you currently implemented it, yes.

@beberlei
Owner

you should be able to get the same functionality with the "flags"feature of indexes that already exists.

@jrobeson

where was that documented? i must have missed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 29, 2012
  1. @maxlun86
This page is out of date. Refresh to see the latest.
View
24 lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
@@ -1396,6 +1396,7 @@ public function getCreateIndexSQL(Index $index, $table)
}
$name = $index->getQuotedName($this);
$columns = $index->getColumns();
+ $subParts = $index->getSubParts();
if (count($columns) == 0) {
throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
@@ -1406,7 +1407,7 @@ public function getCreateIndexSQL(Index $index, $table)
}
$query = 'CREATE ' . $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' ON ' . $table;
- $query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')';
+ $query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns, $subParts) . ')';
return $query;
}
@@ -1433,7 +1434,7 @@ protected function getCreateIndexSQLFlags(Index $index)
*/
public function getCreatePrimaryKeySQL(Index $index, $table)
{
- return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY (' . $this->getIndexFieldDeclarationListSQL($index->getColumns()) . ')';
+ return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY (' . $this->getIndexFieldDeclarationListSQL($index->getColumns(), $index->getSubParts()) . ')';
}
/**
@@ -1890,7 +1891,7 @@ public function getUniqueConstraintDeclarationSQL($name, Index $index)
}
return 'CONSTRAINT ' . $name . ' UNIQUE ('
- . $this->getIndexFieldDeclarationListSQL($index->getColumns())
+ . $this->getIndexFieldDeclarationListSQL($index->getColumns(), $index->getSubParts())
. ')';
}
@@ -1916,7 +1917,7 @@ public function getIndexDeclarationSQL($name, Index $index)
}
return $type . 'INDEX ' . $name . ' ('
- . $this->getIndexFieldDeclarationListSQL($index->getColumns())
+ . $this->getIndexFieldDeclarationListSQL($index->getColumns(), $index->getSubParts())
. ')';
}
@@ -1941,19 +1942,28 @@ public function getCustomTypeDeclarationSQL(array $columnDef)
* declaration to be used in statements like CREATE TABLE.
*
* @param array $fields
+ * @param array $subParts
*
* @return string
*/
- public function getIndexFieldDeclarationListSQL(array $fields)
+ public function getIndexFieldDeclarationListSQL(array $fields, array $subParts = array())
{
$ret = array();
+ $i = 0;
foreach ($fields as $field => $definition) {
if (is_array($definition)) {
- $ret[] = $field;
+ $oneRet = $field;
} else {
- $ret[] = $definition;
+ $oneRet = $definition;
}
+
+ if (isset($subParts[$i])) {
+ $oneRet .= " (".$subParts[$i].")";
+ }
+
+ $ret[] = $oneRet;
+ $i++;
}
return implode(', ', $ret);
View
4 lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
@@ -484,6 +484,8 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
if ($remIndex->getColumns() == $addIndex->getColumns()) {
$columns = $addIndex->getColumns();
+ $subParts = $addIndex->getSubParts();
+
$type = '';
if ($addIndex->isUnique()) {
$type = 'UNIQUE ';
@@ -491,7 +493,7 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff)
$query = 'ALTER TABLE ' . $table . ' DROP INDEX ' . $remIndex->getName() . ', ';
$query .= 'ADD ' . $type . 'INDEX ' . $addIndex->getName();
- $query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')';
+ $query .= ' (' . $this->getIndexFieldDeclarationListSQL($columns, $subParts) . ')';
$sql[] = $query;
View
2  lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
@@ -234,7 +234,7 @@ public function getCreatePrimaryKeySQL(Index $index, $table)
if ($index->hasFlag('nonclustered')) {
$flags = ' NONCLUSTERED';
}
- return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY' . $flags . ' (' . $this->getIndexFieldDeclarationListSQL($index->getColumns()) . ')';
+ return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY' . $flags . ' (' . $this->getIndexFieldDeclarationListSQL($index->getColumns(), $index->getSubParts()) . ')';
}
/**
View
6 lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
@@ -705,6 +705,8 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null
}
$keyName = strtolower($keyName);
+ $columnSubPart = isset($tableIndex['sub_part']) ? $tableIndex['sub_part'] : null;
+
if(!isset($result[$keyName])) {
$result[$keyName] = array(
'name' => $indexName,
@@ -712,9 +714,11 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null
'unique' => $tableIndex['non_unique'] ? false : true,
'primary' => $tableIndex['primary'],
'flags' => isset($tableIndex['flags']) ? $tableIndex['flags'] : array(),
+ 'sub_parts' => array($columnSubPart),
);
} else {
$result[$keyName]['columns'][] = $tableIndex['column_name'];
+ $result[$keyName]['sub_parts'][] = $columnSubPart;
}
}
@@ -734,7 +738,7 @@ protected function _getPortableTableIndexesList($tableIndexRows, $tableName=null
}
if ( ! $defaultPrevented) {
- $index = new Index($data['name'], $data['columns'], $data['unique'], $data['primary'], $data['flags']);
+ $index = new Index($data['name'], $data['columns'], $data['unique'], $data['primary'], $data['flags'], $data['sub_parts']);
}
if ($index) {
View
16 lib/Doctrine/DBAL/Schema/Index.php
@@ -46,18 +46,24 @@ class Index extends AbstractAsset implements Constraint
protected $_flags = array();
/**
+ * @var array
+ */
+ protected $_subParts = array();
+
+ /**
* @param string $indexName
* @param array $column
* @param bool $isUnique
* @param bool $isPrimary
*/
- public function __construct($indexName, array $columns, $isUnique = false, $isPrimary = false, array $flags = array())
+ public function __construct($indexName, array $columns, $isUnique = false, $isPrimary = false, array $flags = array(), array $subParts = array())
{
$isUnique = ($isPrimary)?true:$isUnique;
$this->_setName($indexName);
$this->_isUnique = $isUnique;
$this->_isPrimary = $isPrimary;
+ $this->_subParts = $subParts;
foreach ($columns as $column) {
$this->_addColumn($column);
@@ -248,5 +254,13 @@ public function removeFlag($flag)
{
unset($this->flags[strtolower($flag)]);
}
+
+ /**
+ * @return array
+ */
+ public function getSubParts()
+ {
+ return $this->_subParts;
+ }
}
Something went wrong with that request. Please try again.