Skip to content

Escape primary field name in create table sql query #222

Closed
wants to merge 1 commit into from

4 participants

@Genokilller

Fixes primary fields name in CreateTableSQL for Abstract Platform

@Genokilller Genokilller Update lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Fixes primary fields name in CreateTableSQL for Abstract Platform
061d556
@doctrinebot

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DBAL-374

@stof
Doctrine member
stof commented Oct 30, 2012

What are you trying to fix ? I don't see any testcase showing that a bug has been fixed and no reference to an existing ticket

@Genokilller

This fixe is for a bug that a see when i want to create a new table with MySQL Driver.
I define a primary key named 'key'. The column name was correctly escape, but not the primary key definition.

Exemple :
Without fix: PRIMARY KEY(key)
With fix: PRIMARY KEY(`key`)

This is a reserved keyword for MySQL.

I don't have the time for writting some unit tests about that.

Thanks a lot.

@stof
Doctrine member
stof commented Oct 30, 2012

it should be escaped only when the column is marked as needing quotes IMO, as quoting column names introduces issues

@Genokilller

The name is escape only if it's a reserved keyword.

You hope i listen this sentence and apply it instead of apply quoting ?
"Let me answer with another question: why on earth do you use a reserved keyword as identifier? ;-) "

So, why the columns name should be quoted and not the index ?

@beberlei
Doctrine member

Verified, i am working on a fix thtas different than this one though.

@beberlei
Doctrine member

Fixed in master and 2.3

@beberlei beberlei closed this Nov 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.