Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Index support

  • Loading branch information...
commit 05b483523666c4b703fe435f8ab2b5787c84156b 1 parent 0541b30
@kimhemsoe authored
View
46 lib/Doctrine/DBAL/Platforms/DrizzlePlatform.php
@@ -167,7 +167,16 @@ public function getListTableForeignKeysSQL($table, $database = null)
public function getListTableIndexesSQL($table, $database = null)
{
- return "SELECT * FROM DATA_DICTIONARY.INDEXES WHERE FALSE";
+ if ($database) {
+ $database = "'" . $database . "'";
+ } else {
+ $database = 'DATABASE()';
+ }
+
+ // INDEX_NAME AS 'key_name', COLUMN_NAME AS 'column_name', IS_USED_IN_PRIMARY AS 'primary', IS_UNIQUE=0 AS 'non_unique'
+ return "SELECT INDEX_NAME AS 'key_name', COLUMN_NAME AS 'column_name', IS_USED_IN_PRIMARY AS 'primary', IS_UNIQUE=0 AS 'non_unique'" .
+ " FROM DATA_DICTIONARY.INDEX_PARTS" .
+ " WHERE TABLE_SCHEMA=" . $database . " AND TABLE_NAME='" . $table . "'";
}
public function prefersIdentityColumns()
@@ -184,4 +193,39 @@ public function supportsInlineColumnComments()
{
return true;
}
+
+ public function getDropIndexSQL($index, $table=null)
+ {
+ if($index instanceof Index) {
+ $indexName = $index->getQuotedName($this);
+ } else if(is_string($index)) {
+ $indexName = $index;
+ } else {
+ throw new \InvalidArgumentException('DrizzlePlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.');
+ }
+
+ if($table instanceof Table) {
+ $table = $table->getQuotedName($this);
+ } else if(!is_string($table)) {
+ throw new \InvalidArgumentException('DrizzlePlatform::getDropIndexSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.');
+ }
+
+ if ($index instanceof Index && $index->isPrimary()) {
+ // drizzle primary keys are always named "PRIMARY",
+ // so we cannot use them in statements because of them being keyword.
+ return $this->getDropPrimaryKeySQL($table);
+ }
+
+ return 'DROP INDEX ' . $indexName . ' ON ' . $table;
+ }
+
+ /**
+ * @param Index $index
+ * @param Table $table
+ */
+ protected function getDropPrimaryKeySQL($table)
+ {
+ return 'ALTER TABLE ' . $table . ' DROP PRIMARY KEY';
+ }
+
}
View
17 lib/Doctrine/DBAL/Schema/DrizzleSchemaManager.php
@@ -22,6 +22,7 @@
/**
* Schema manager for the Drizzle RDBMS.
*
+ * @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/
class DrizzleSchemaManager extends AbstractSchemaManager
{
@@ -54,14 +55,12 @@ protected function _getPortableTableDefinition($table)
public function _getPortableTableForeignKeyDefinition($tableForeignKey)
{
$columns = array();
- foreach (explode(',', $tableForeignKey['CONSTRAINT_COLUMNS']) as $value)
- {
+ foreach (explode(',', $tableForeignKey['CONSTRAINT_COLUMNS']) as $value) {
$columns[] = trim($value, '`');
}
$ref_columns = array();
- foreach (explode(',', $tableForeignKey['REFERENCED_TABLE_COLUMNS']) as $value)
- {
+ foreach (explode(',', $tableForeignKey['REFERENCED_TABLE_COLUMNS']) as $value) {
$ref_columns[] = trim($value, '`');
}
@@ -75,7 +74,17 @@ public function _getPortableTableForeignKeyDefinition($tableForeignKey)
'onDelete' => $tableForeignKey['DELETE_RULE'],
)
);
+ }
+
+ protected function _getPortableTableIndexesList($tableIndexes, $tableName=null)
+ {
+ $indexes = array();
+ foreach ($tableIndexes as $k) {
+ $k['primary'] = (boolean)$k['primary'];
+ $indexes[] = $k;
+ }
+ return parent::_getPortableTableIndexesList($indexes, $tableName);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.