[DBAL-88] MySqlPlatform not escaping table names Created: 10/Feb/11  Updated: 26/Feb/11  Resolved: 26/Feb/11

Status: Resolved
Project: Doctrine DBAL
Component/s: Platforms
Affects Version/s: 2.0
Fix Version/s: 2.0.2, 2.1

Type: Bug Priority: Major
Reporter: James Reed Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None

Attachments: File MySqlPlatform.php    
Issue Links:
Duplicate
duplicates DBAL-91 orm:convert-mapping SchemaException o... Resolved

 Description   

Methods in the MySql Platform that use the table name are not escaping the table name. This causes problems when your table name is the same as a reserved word in MySql. Example:

public function getListTableConstraintsSQL($table)

{ return 'SHOW INDEX FROM ' . $table; }

If my table name is User this method will fail and cause a SQL error because the word User is a reserved word in MySql. You need to escape the table name with backticks to prevent these errors. Example:

public function getListTableConstraintsSQL($table)

{ return 'SHOW INDEX FROM `' . $table . '`'; }

I encountered this problem while reverse engineering my existing MySql database. I've attached a fixed version that solved my reverse engineering problems.



 Comments   
Comment by Benjamin Eberlei [ 11/Feb/11 ]

Duplicate of DDC-976

Comment by Benjamin Eberlei [ 12/Feb/11 ]

This issue is not a duplicate, only related to DBAL-91.

Comment by Benjamin Eberlei [ 26/Feb/11 ]

Fixed

Generated at Tue Jul 29 23:16:37 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.