Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove inconsistencies in table/column escaping for mysql #2826

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

/**
Expand Down