[DBAL-529] databasenames including dashes not correctly supported Created: 24/May/13  Updated: 26/May/13  Resolved: 26/May/13

Status: Resolved
Project: Doctrine DBAL
Component/s: None
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Andy Rosslau Assignee: Benjamin Eberlei
Resolution: Invalid Votes: 0
Labels: annotationdriver, mapping, yml


 Description   

I'm having a legacy Database including a dash in its name:

"my-db"

which includes tables I want to work with.

The EntityMapping would be the following:

yml

My\TestBundle\Entity\Stuff:
    type: entity
    table: my-db.stuff
    fields:
        id:
...

annotation

/**
 * @ORM\Entity()
 * @ORM\Table(name="my-db.stuff")
 */

Both concludes in a Query (SELECT, INSERT etc.) which won't work:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-db.stuff t0 WHERE[...]

I found a simple fix by trial and Error. Just put a "`" in front of the databasename:

yml

My\TestBundle\Entity\Stuff:
    type: entity
    table: `my-db.stuff
    fields:
        id:
...

annotation

/**
 * @ORM\Entity()
 * @ORM\Table(name="`my-db.stuff")
 */

Although this fix works, it feels wrong.
Moreover, to prevent confusing other developers, this should be fixed to one the following styles.

annotation

/**
 * @ORM\Entity()
 * @ORM\Table(name="`my-db`.stuff")
 */

OR

annotation

/**
 * @ORM\Entity()
 * @ORM\Table(name="my-db.stuff")
 */


 Comments   
Comment by Benjamin Eberlei [ 26/May/13 ]

This is the correct behavior, autoquoting is more painful than helpful, so we don't do it.

The explicit escaping with ` is documented to be the proper fix for quoting.

Comment by Andy Rosslau [ 26/May/13 ]

So? I thougt there is any autoquoting, as I recognized a query would look like that, when I put the database name in ` (eg. `my-db`.table).

sample-query (not working)

INSERT INTO `my-db``.table ...

Thats why I reported this issue. Only a single ` would work.. Query would look like this (correct)

INSERT INTO `my-db`.table ...

So as you can see the second ` is added automatically.

Generated at Tue Sep 02 14:57:49 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.