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

        Andy Rosslau created issue -
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Invalid [ 6 ]

          People

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

            Dates

            • Created:
              Updated:
              Resolved: