Commit a8bf19ea authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'DBAL-88' into 2.0.x

parents 2775ab9c ff2a856c
...@@ -1660,7 +1660,20 @@ abstract class AbstractPlatform ...@@ -1660,7 +1660,20 @@ abstract class AbstractPlatform
throw DBALException::notSupported(__METHOD__); throw DBALException::notSupported(__METHOD__);
} }
public function getListTableIndexesSQL($table) /**
* Get the list of indexes for the current database.
*
* The current database parameter is optional but will always be passed
* when using the SchemaManager API and is the database the given table is in.
*
* Attention: Some platforms only support currentDatabase when they
* are connected with that database. Cross-database information schema
* requests may be impossible.
*
* @param string $table
* @param string $currentDatabase
*/
public function getListTableIndexesSQL($table, $currentDatabase = null)
{ {
throw DBALException::notSupported(__METHOD__); throw DBALException::notSupported(__METHOD__);
} }
......
...@@ -234,7 +234,7 @@ class DB2Platform extends AbstractPlatform ...@@ -234,7 +234,7 @@ class DB2Platform extends AbstractPlatform
return "SELECT NAME, TEXT FROM SYSIBM.SYSVIEWS"; return "SELECT NAME, TEXT FROM SYSIBM.SYSVIEWS";
} }
public function getListTableIndexesSQL($table) public function getListTableIndexesSQL($table, $currentDatabase = null)
{ {
return "SELECT NAME, COLNAMES, UNIQUERULE FROM SYSIBM.SYSINDEXES WHERE TBNAME = UPPER('" . $table . "')"; return "SELECT NAME, COLNAMES, UNIQUERULE FROM SYSIBM.SYSINDEXES WHERE TBNAME = UPPER('" . $table . "')";
} }
......
...@@ -340,7 +340,7 @@ class MsSqlPlatform extends AbstractPlatform ...@@ -340,7 +340,7 @@ class MsSqlPlatform extends AbstractPlatform
/** /**
* @override * @override
*/ */
public function getListTableIndexesSQL($table) public function getListTableIndexesSQL($table, $currentDatabase = null)
{ {
return "exec sp_helpindex '" . $table . "'"; return "exec sp_helpindex '" . $table . "'";
} }
......
...@@ -109,10 +109,26 @@ class MySqlPlatform extends AbstractPlatform ...@@ -109,10 +109,26 @@ class MySqlPlatform extends AbstractPlatform
return 'SHOW INDEX FROM ' . $table; return 'SHOW INDEX FROM ' . $table;
} }
public function getListTableIndexesSQL($table) /**
{ * Two approaches to listing the table indexes. The information_schema is
* prefered, because it doesn't cause problems with SQL keywords such as "order" or "table".
*
* @param string $table
* @param string $currentDatabase
* @return string
*/
public function getListTableIndexesSQL($table, $currentDatabase = null)
{
if ($currentDatabase) {
return "SELECT TABLE_NAME AS `Table`, NON_UNIQUE AS Non_Unique, INDEX_NAME AS Key_name, ".
"SEQ_IN_INDEX AS Seq_in_index, COLUMN_NAME AS Column_Name, COLLATION AS Collation, ".
"CARDINALITY AS Cardinality, SUB_PART AS Sub_Part, PACKED AS Packed, " .
"NULLABLE AS `Null`, INDEX_TYPE AS Index_Type, COMMENT AS Comment " .
"FROM information_schema.STATISTICS WHERE TABLE_NAME = '" . $table . "' AND TABLE_SCHEMA = '" . $currentDatabase . "'";
} else {
return 'SHOW INDEX FROM ' . $table; return 'SHOW INDEX FROM ' . $table;
} }
}
public function getListViewsSQL($database) public function getListViewsSQL($database)
{ {
......
...@@ -296,7 +296,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -296,7 +296,7 @@ class OraclePlatform extends AbstractPlatform
* @param string $table * @param string $table
* @return string * @return string
*/ */
public function getListTableIndexesSQL($table) public function getListTableIndexesSQL($table, $currentDatabase = null)
{ {
$table = strtoupper($table); $table = strtoupper($table);
......
...@@ -217,7 +217,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -217,7 +217,7 @@ class PostgreSqlPlatform extends AbstractPlatform
* @param string $table * @param string $table
* @return string * @return string
*/ */
public function getListTableIndexesSQL($table) public function getListTableIndexesSQL($table, $currentDatabase = null)
{ {
return "SELECT relname, pg_index.indisunique, pg_index.indisprimary, return "SELECT relname, pg_index.indisunique, pg_index.indisprimary,
pg_index.indkey, pg_index.indrelid pg_index.indkey, pg_index.indrelid
......
...@@ -316,12 +316,12 @@ class SqlitePlatform extends AbstractPlatform ...@@ -316,12 +316,12 @@ class SqlitePlatform extends AbstractPlatform
return "SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name = '$table' AND sql NOT NULL ORDER BY name"; return "SELECT sql FROM sqlite_master WHERE type='index' AND tbl_name = '$table' AND sql NOT NULL ORDER BY name";
} }
public function getListTableColumnsSQL($table) public function getListTableColumnsSQL($table, $currentDatabase = null)
{ {
return "PRAGMA table_info($table)"; return "PRAGMA table_info($table)";
} }
public function getListTableIndexesSQL($table) public function getListTableIndexesSQL($table, $currentDatabase = null)
{ {
return "PRAGMA index_list($table)"; return "PRAGMA index_list($table)";
} }
......
...@@ -33,7 +33,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; ...@@ -33,7 +33,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @author Jonathan H. Wage <jonwage@gmail.com> * @author Jonathan H. Wage <jonwage@gmail.com>
* @author Benjamin Eberlei <kontakt@beberlei.de> * @author Benjamin Eberlei <kontakt@beberlei.de>
* @version $Revision$
* @since 2.0 * @since 2.0
*/ */
abstract class AbstractSchemaManager abstract class AbstractSchemaManager
...@@ -162,7 +161,7 @@ abstract class AbstractSchemaManager ...@@ -162,7 +161,7 @@ abstract class AbstractSchemaManager
*/ */
public function listTableIndexes($table) public function listTableIndexes($table)
{ {
$sql = $this->_platform->getListTableIndexesSQL($table); $sql = $this->_platform->getListTableIndexesSQL($table, $this->_conn->getDatabase());
$tableIndexes = $this->_conn->fetchAll($sql); $tableIndexes = $this->_conn->fetchAll($sql);
......
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