DBAL-529: databasenames including dashes not correctly supported #1735

Closed
doctrinebot opened this Issue May 24, 2013 · 3 comments

2 participants

@doctrinebot

Jira issue originally created by user rosslau@my-hammer.de:

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:
{color:red}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[...]{color}

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")
 */
@doctrinebot

Comment created by @beberlei:

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.

@doctrinebot

Issue was closed with resolution "Invalid"

@doctrinebot

Comment created by rosslau@my-hammer.de:

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.

@doctrinebot doctrinebot added the Bug label Dec 6, 2015
@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment