[DBAL-34] MySql getListTableForeignKeysSQL doesn't work for 5.0.xx Created: 19/Jul/10  Updated: 15/Aug/11  Resolved: 27/Jul/10

Status: Resolved
Project: Doctrine DBAL
Component/s: Schema Managers
Affects Version/s: 2.0.0-BETA2
Fix Version/s: 2.0.0-BETA3

Type: Bug Priority: Major
Reporter: Ting Wang Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None

MySQL Server version: 5.0.51a-24+lenny4 (Debian)


The sql contains mysql specific code. And for the mysql 5.0.xxx the sql statement has syntax error.

in /Doctrine/DBAL/Platforms/MySqlPlatform.php:
public function getListTableForeignKeysSQL($table, $database = null)
"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'";

if ($database)

{ $sql .= " AND k.table_schema = '$database' AND c.constraint_schema = '$database'"; }


return $sql;

For the mysql lower as 5.1.16 the SQL could be as the following:

SELECT DISTINCT k.`CONSTRAINT_NAME`, k.`COLUMN_NAME`, k.`REFERENCED_TABLE_NAME`, k.`REFERENCED_COLUMN_NAME` FROM information_schema.key_column_usage k WHERE k.table_name = 'some_table' AND k.table_schema = 'some database' AND c.constraint_schema = 'some database' AND `REFERENCED_COLUMN_NAME` is not NULL

In this statement there is no reference of c

Comment by Benjamin Eberlei [ 27/Jul/10 ]


Comment by Aigars Gedroics [ 15/Aug/11 ]

Pity that because of this the Doctrine schema-tool update action reports incorrect change list.
It tries to drop/add foreign keys because "ON DELETE CASCADE" option isn't read from the database at all.

Comment by Benjamin Eberlei [ 15/Aug/11 ]

5.0.x has no way to export the CASCADE details. Its just not possible to get this data in 5.0

Generated at Mon Apr 27 22:28:37 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.