Skip to content

Loading…

DDC-1360: Reserved words escaping fails when using multiple reserved words #1979

Closed
doctrinebot opened this Issue · 13 comments

2 participants

@doctrinebot

Jira issue originally created by user elnur:

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.

@doctrinebot

Comment created by @guilhermeblanco:

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,

@doctrinebot

Comment created by elnur:

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

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Comment created by @beberlei:

Fixed for 2.2

@doctrinebot

Comment created by elnur:

It still doesn't work. Tried on master.

@doctrinebot

Comment created by @beberlei:

what kind of error do you get?

@doctrinebot

Comment created by @beberlei:

could reproduce the problem with table names and sequence names.

@doctrinebot

Comment created by @beberlei:

Fixed.

@doctrinebot

Comment created by elnur:

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

@doctrinebot

Comment created by elnur:

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 (959a686) 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.

@doctrinebot

Comment created by @beberlei:

I keep trying until i fixed this, now with a commit into DBAL: doctrine/dbal@4cb8a99

Will be included in Beta 2

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by elnur:

Now user`.user`,user.useranduser.userget escaped properly, ending up as `"user"."user"`. Interestingly enough, even only the beginning tick like inuser.userends 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.

@doctrinebot doctrinebot added this to the 2.2-BETA2 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.