Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-529

databasenames including dashes not correctly supported

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All

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

        Activity

        Hide
        Benjamin Eberlei added a comment -

        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.

        Show
        Benjamin Eberlei added a comment - 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.
        Hide
        Andy Rosslau added a comment -

        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.

        Show
        Andy Rosslau added a comment - 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.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Andy Rosslau
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: