From a76e1a13d408f1e23d3766707639005b0115bab0 Mon Sep 17 00:00:00 2001 From: belgattitude Date: Sun, 27 Aug 2017 00:16:48 +0200 Subject: [PATCH] Remove inconsistencies in table/column escaping for mysql (might prevent future bugs with reserved keywords) --- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 5d2b6339dac..a3853a4eba8 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -163,11 +163,11 @@ public function getListTableIndexesSQL($table, $currentDatabase = null) $currentDatabase = $this->quoteStringLiteral($currentDatabase); $table = $this->quoteStringLiteral($table); - 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; + 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; } return 'SHOW INDEX FROM ' . $table; @@ -180,7 +180,7 @@ public function getListViewsSQL($database) { $database = $this->quoteStringLiteral($database); - return "SELECT * FROM information_schema.VIEWS WHERE TABLE_SCHEMA = " . $database; + return "SELECT * FROM `information_schema`.`VIEWS` WHERE `TABLE_SCHEMA` = " . $database; } /** @@ -194,17 +194,17 @@ public function getListTableForeignKeysSQL($table, $database = null) $database = $this->quoteStringLiteral($database); } - $sql = "SELECT DISTINCT k.`CONSTRAINT_NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE_NAME`, ". - "k.`REFERENCED_COLUMN_NAME` /*!50116 , c.update_rule, c.delete_rule */ ". - "FROM information_schema.key_column_usage k /*!50116 ". - "INNER JOIN information_schema.referential_constraints c ON ". - " c.constraint_name = k.constraint_name AND ". - " c.table_name = $table */ WHERE k.table_name = $table"; + $sql = "SELECT DISTINCT `k`.`CONSTRAINT_NAME`, `k`.`COLUMN_NAME`, `k`.`REFERENCED_TABLE_NAME`, ". + "`k`.`REFERENCED_COLUMN_NAME` /*!50116 , `c`.`update_rule`, `c`.`delete_rule` */ ". + "FROM `information_schema`.`key_column_usage` AS k /*!50116 ". + "INNER JOIN `information_schema`.`referential_constraints` AS `c` ON ". + " `c`.`constraint_name` = `k`.`constraint_name` AND ". + " `c`.`table_name` = $table */ WHERE `k`.`table_name` = $table"; $databaseNameSql = null === $database ? 'DATABASE()' : $database; - $sql .= " AND k.table_schema = $databaseNameSql /*!50116 AND c.constraint_schema = $databaseNameSql */"; - $sql .= " AND k.`REFERENCED_COLUMN_NAME` is not NULL"; + $sql .= " AND `k`.`table_schema` = $databaseNameSql /*!50116 AND `c`.`constraint_schema` = $databaseNameSql */"; + $sql .= " AND `k`.`REFERENCED_COLUMN_NAME` is not NULL"; return $sql; } @@ -384,10 +384,10 @@ public function getListTableColumnsSQL($table, $database = null) $database = 'DATABASE()'; } - return "SELECT COLUMN_NAME AS Field, COLUMN_TYPE AS Type, IS_NULLABLE AS `Null`, ". - "COLUMN_KEY AS `Key`, COLUMN_DEFAULT AS `Default`, EXTRA AS Extra, COLUMN_COMMENT AS Comment, " . - "CHARACTER_SET_NAME AS CharacterSet, COLLATION_NAME AS Collation ". - "FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = " . $database . " AND TABLE_NAME = " . $table; + return "SELECT `COLUMN_NAME` AS `Field`, `COLUMN_TYPE` AS `Type`, `IS_NULLABLE` AS `Null`, ". + "`COLUMN_KEY` AS `Key`, `COLUMN_DEFAULT` AS `Default`, `EXTRA` AS `Extra`, `COLUMN_COMMENT` AS `Comment`, " . + "`CHARACTER_SET_NAME` AS `CharacterSet`, `COLLATION_NAME` AS `Collation` ". + "FROM `information_schema`.`COLUMNS` WHERE `TABLE_SCHEMA` = " . $database . " AND `TABLE_NAME` = " . $table; } /**