yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.24k stars 6.9k forks source link

Query builder breaks table names containing whitespace #3824

Closed Obramko closed 10 years ago

Obramko commented 10 years ago

Some RDMS (like PostgreSQL) allows whitespaces in table names, which have to be quoted. A regex at db/QueryBuilder.php breaks such table names, e.g. table ' "one two" ' becomes ' "one" "two" ' instead.

I'm preparing a pull request with easy fix of this issue, but it needs testing.

samdark commented 10 years ago

The fix is not correct since it breaks aliases usage:

SELECT * FROM post p WHERE active = 1;

becomes

SELECT * FROM `post p` WHERE `active` = 1;
samdark commented 10 years ago

I don't see a way to automatically differentiate usage of table with space from table with alias.

cebe commented 10 years ago

does yii escape already escaped table names?

samdark commented 10 years ago

Yes, it seems so.

qiangxue commented 10 years ago

Duplicate of #3533.