Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Index support

  • Loading branch information...
commit 05b483523666c4b703fe435f8ab2b5787c84156b 1 parent 0541b30
Kim Hemsø Rasmussen authored
46 lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php
@@ -167,7 +167,16 @@ public function getListTableForeignKeysSQL($table, $database = null)
167 167
168 168 public function getListTableIndexesSQL($table, $database = null)
169 169 {
170   - return "SELECT * FROM DATA_DICTIONARY.INDEXES WHERE FALSE";
  170 + if ($database) {
  171 + $database = "'" . $database . "'";
  172 + } else {
  173 + $database = 'DATABASE()';
  174 + }
  175 +
  176 + // INDEX_NAME AS 'key_name', COLUMN_NAME AS 'column_name', IS_USED_IN_PRIMARY AS 'primary', IS_UNIQUE=0 AS 'non_unique'
  177 + return "SELECT INDEX_NAME AS 'key_name', COLUMN_NAME AS 'column_name', IS_USED_IN_PRIMARY AS 'primary', IS_UNIQUE=0 AS 'non_unique'" .
  178 + " FROM DATA_DICTIONARY.INDEX_PARTS" .
  179 + " WHERE TABLE_SCHEMA=" . $database . " AND TABLE_NAME='" . $table . "'";
171 180 }
172 181
173 182 public function prefersIdentityColumns()
@@ -184,4 +193,39 @@ public function supportsInlineColumnComments()
184 193 {
185 194 return true;
186 195 }
  196 +
  197 + public function getDropIndexSQL($index, $table=null)
  198 + {
  199 + if($index instanceof Index) {
  200 + $indexName = $index->getQuotedName($this);
  201 + } else if(is_string($index)) {
  202 + $indexName = $index;
  203 + } else {
  204 + throw new \InvalidArgumentException('DrizzlePlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
  205 + }
  206 +
  207 + if($table instanceof Table) {
  208 + $table = $table->getQuotedName($this);
  209 + } else if(!is_string($table)) {
  210 + throw new \InvalidArgumentException('DrizzlePlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
  211 + }
  212 +
  213 + if ($index instanceof Index && $index->isPrimary()) {
  214 + // drizzle primary keys are always named "PRIMARY",
  215 + // so we cannot use them in statements because of them being keyword.
  216 + return $this->getDropPrimaryKeySQL($table);
  217 + }
  218 +
  219 + return 'DROP INDEX ' . $indexName . ' ON ' . $table;
  220 + }
  221 +
  222 + /**
  223 + * @param Index $index
  224 + * @param Table $table
  225 + */
  226 + protected function getDropPrimaryKeySQL($table)
  227 + {
  228 + return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
  229 + }
  230 +
187 231 }
17 lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php
@@ -22,6 +22,7 @@
22 22 /**
23 23 * Schema manager for the Drizzle RDBMS.
24 24 *
  25 + * @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
25 26 */
26 27 class DrizzleSchemaManager extends AbstractSchemaManager
27 28 {
@@ -54,14 +55,12 @@ protected function _getPortableTableDefinition($table)
54 55 public function _getPortableTableForeignKeyDefinition($tableForeignKey)
55 56 {
56 57 $columns = array();
57   - foreach (explode(',', $tableForeignKey['CONSTRAINT_COLUMNS']) as $value)
58   - {
  58 + foreach (explode(',', $tableForeignKey['CONSTRAINT_COLUMNS']) as $value) {
59 59 $columns[] = trim($value, '`');
60 60 }
61 61
62 62 $ref_columns = array();
63   - foreach (explode(',', $tableForeignKey['REFERENCED_TABLE_COLUMNS']) as $value)
64   - {
  63 + foreach (explode(',', $tableForeignKey['REFERENCED_TABLE_COLUMNS']) as $value) {
65 64 $ref_columns[] = trim($value, '`');
66 65 }
67 66
@@ -75,7 +74,17 @@ public function _getPortableTableForeignKeyDefinition($tableForeignKey)
75 74 'onDelete' => $tableForeignKey['DELETE_RULE'],
76 75 )
77 76 );
  77 + }
  78 +
  79 + protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
  80 + {
  81 + $indexes = array();
  82 + foreach ($tableIndexes as $k) {
  83 + $k['primary'] = (boolean)$k['primary'];
  84 + $indexes[] = $k;
  85 + }
78 86
  87 + return parent::_getPortableTableIndexesList($indexes, $tableName);
79 88 }
80 89 }
81 90

0 comments on commit 05b4835

Please sign in to comment.
Something went wrong with that request. Please try again.