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

        Elnur Abdurrakhimov created issue -
        Hide
        Guilherme Blanco added a comment -

        By now, it's currently impossible to do cross database joins in an easy way.
        We have planned it through the schema support in @Table.

        I'll be working on this support for 2.2, but until there, my only recommendation is to not use a keyword as a table name.

        Cheers,

        Show
        Guilherme Blanco added a comment - By now, it's currently impossible to do cross database joins in an easy way. We have planned it through the schema support in @Table. I'll be working on this support for 2.2, but until there, my only recommendation is to not use a keyword as a table name. Cheers,
        Hide
        Elnur Abdurrakhimov added a comment -

        It's not cross database; it's just schema.table in PostgreSQL. It works when not using reserved words, but fails with them.

        Show
        Elnur Abdurrakhimov added a comment - It's not cross database; it's just schema.table in PostgreSQL. It works when not using reserved words, but fails with them.
        Hide
        Benjamin Eberlei added a comment -

        How much of this ticket does your commit from some weeks ago cover guilherme?

        Show
        Benjamin Eberlei added a comment - How much of this ticket does your commit from some weeks ago cover guilherme?
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Assignee Benjamin Eberlei [ beberlei ] Guilherme Blanco [ guilhermeblanco ]
        Hide
        Benjamin Eberlei added a comment -

        Fixed for 2.2

        Show
        Benjamin Eberlei added a comment - Fixed for 2.2
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.2-DEV [ 10157 ]
        Resolution Fixed [ 1 ]
        Hide
        Elnur Abdurrakhimov added a comment -

        It still doesn't work. Tried on master.

        Show
        Elnur Abdurrakhimov added a comment - It still doesn't work. Tried on master .
        Elnur Abdurrakhimov made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Hide
        Benjamin Eberlei added a comment -

        what kind of error do you get?

        Show
        Benjamin Eberlei added a comment - what kind of error do you get?
        Hide
        Benjamin Eberlei added a comment -

        could reproduce the problem with table names and sequence names.

        Show
        Benjamin Eberlei added a comment - could reproduce the problem with table names and sequence names.
        Hide
        Benjamin Eberlei added a comment -

        Fixed.

        Show
        Benjamin Eberlei added a comment - Fixed.
        Benjamin Eberlei made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        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" .
        Elnur Abdurrakhimov made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        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
        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
        Benjamin Eberlei made changes -
        Status Reopened [ 4 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        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.
        Benjamin Eberlei made changes -
        Fix Version/s 2.2-BETA2 [ 10188 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 12994 ] jira-feedback [ 15016 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15016 ] jira-feedback2 [ 16880 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 16880 ] jira-feedback3 [ 19133 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-1360, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

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

            Dates

            • Created:
              Updated:
              Resolved: