[DDC-1360] Reserved words escaping fails when using multiple reserved words Created: 03/Sep/11  Updated: 03/Jan/12  Resolved: 31/Dec/11

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.1.1
Fix Version/s: 2.2-BETA2, 2.2
Security Level: All

Type: Bug Priority: Blocker
Reporter: Elnur Abdurrakhimov Assignee: Guilherme Blanco
Resolution: Fixed Votes: 0
Labels: None

Linux, PostgreSQL


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.

Comment by Guilherme Blanco [ 05/Sep/11 ]

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.


Comment by Elnur Abdurrakhimov [ 05/Sep/11 ]

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

Comment by Benjamin Eberlei [ 28/Oct/11 ]

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

Comment by Benjamin Eberlei [ 16/Nov/11 ]

Fixed for 2.2

Comment by Elnur Abdurrakhimov [ 21/Dec/11 ]

It still doesn't work. Tried on master.

Comment by Benjamin Eberlei [ 21/Dec/11 ]

what kind of error do you get?

Comment by Benjamin Eberlei [ 28/Dec/11 ]

could reproduce the problem with table names and sequence names.

Comment by Benjamin Eberlei [ 28/Dec/11 ]


Comment by Elnur Abdurrakhimov [ 29/Dec/11 ]

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

My entity has this annotation:


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".

Comment by Elnur Abdurrakhimov [ 29/Dec/11 ]

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.

Comment by Benjamin Eberlei [ 31/Dec/11 ]

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

Comment by Elnur Abdurrakhimov [ 31/Dec/11 ]

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.

Generated at Wed Oct 07 00:23:10 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.