Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1360

Reserved words escaping fails when using multiple reserved words

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.1.1
    • Fix Version/s: 2.2-BETA2, 2.2
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Linux, PostgreSQL

      Description

      Everything works fine when I use the @Table annotation like this: @Table(name="`user`"). But when the user table is in the user schema and I try to use the annotion in this way: @Table(name="`user`.`user`") — everything falls apart.

      A quick look into the code showed that it checks if the table name starts with `, and if it does, it sets the quoted parameter to true and removes the ` characters on the both sides. So, if I quote the both words like @Table(name="`user`.`user`"), the table name becomes "user`.`user" and it, of course, fails. If I quote it just like @Table(name="`user.user`"), the table name becomes "user.user", which fails too.

      If Doctrine allows to escape the reserved words, it should take into account this kind of usage as well.

        Activity

        Hide
        Elnur Abdurrakhimov added a comment -

        Now `user`.user, `user`.`user` and `user.user` get escaped properly, ending up as "user"."user". Interestingly enough, even only the beginning tick like in `user.user ends up as "user"."user".

        user.`user`, though, results in user.`user` — that is, nothing gets escaped. I don't think this is a big deal, because if I can escape both schema and table name parts, then I won't run into problems. I'm pointing this out in case it was intended to affect the escaping too.

        Good job, thanks.

        Show
        Elnur Abdurrakhimov added a comment - Now `user`.user , `user`.`user` and `user.user` get escaped properly, ending up as "user"."user" . Interestingly enough, even only the beginning tick like in `user.user ends up as "user"."user" . user.`user` , though, results in user.`user` — that is, nothing gets escaped. I don't think this is a big deal, because if I can escape both schema and table name parts, then I won't run into problems. I'm pointing this out in case it was intended to affect the escaping too. Good job, thanks.
        Hide
        Benjamin Eberlei added a comment -

        I keep trying until i fixed this, now with a commit into DBAL: https://github.com/doctrine/dbal/commit/4cb8a99b65fb08e01fbc02cf9c0e07255e3f8463

        Will be included in Beta 2

        Show
        Benjamin Eberlei added a comment - I keep trying until i fixed this, now with a commit into DBAL: https://github.com/doctrine/dbal/commit/4cb8a99b65fb08e01fbc02cf9c0e07255e3f8463 Will be included in Beta 2
        Hide
        Elnur Abdurrakhimov added a comment -

        What changed is that earlier `user`.`user` was translated to "user`.`user", while now it's translated to "user.user", but should be to "user"."user".

        I saw the commit related to this ticket (https://github.com/doctrine/doctrine2/commit/959a68694e5827a74ad5b8c8216996ffff6196ba) and I want to note that I'm getting this error not when creating a table, but when querying it. I don't use Doctrine for creating tables anyway — I do it via plain SQL.

        Show
        Elnur Abdurrakhimov added a comment - What changed is that earlier `user`.`user` was translated to "user`.`user" , while now it's translated to "user.user" , but should be to "user"."user" . I saw the commit related to this ticket ( https://github.com/doctrine/doctrine2/commit/959a68694e5827a74ad5b8c8216996ffff6196ba ) and I want to note that I'm getting this error not when creating a table, but when querying it. I don't use Doctrine for creating tables anyway — I do it via plain SQL.
        Hide
        Elnur Abdurrakhimov added a comment -

        I've just got fresh clones of doctrine-doctrine2, doctrine-dbal and doctrine-common — all on their master branches.

        My entity has this annotation:

        @ORM\Table(name="`user`.`user`")
        

        I'm getting the following exception:

        SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "user.user" 
        does not exist LINE 1: ... is_private9,
        u0_.created_at AS created_at10 FROM "user.user... 
        

        So, it's translating `user`.`user` to "user.user", while it should be "user"."user".

        Show
        Elnur Abdurrakhimov added a comment - I've just got fresh clones of doctrine-doctrine2 , doctrine-dbal and doctrine-common — all on their master branches. My entity has this annotation: @ORM\Table(name= "`user`.`user`" ) I'm getting the following exception: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "user.user" does not exist LINE 1: ... is_private9, u0_.created_at AS created_at10 FROM "user.user... So, it's translating `user`.`user` to "user.user" , while it should be "user"."user" .
        Hide
        Benjamin Eberlei added a comment -

        Fixed.

        Show
        Benjamin Eberlei added a comment - Fixed.

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Elnur Abdurrakhimov
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: