开发者

Escaping backslash in namespaces with DQL (Doctrine 2)

I'm a bit confused about writing queries in DQL. From the official documentation:

$query = $em->createQuery('SELECT u FROM MyProject\Model\User u WHERE u.age > 20');

Why the backslash of the namespace is not escaped?

I'm getting a warning in Zend Studio for that reason, and it works anyway, but I think is just "luck", because neither \M nor \U are valid escaped sequence开发者_StackOverflow中文版s.

What do you think? is safe to use that syntax? or is better to escape the "\" always in DQL?

$query = $em->createQuery('SELECT u FROM MyProject\\Model\\User u WHERE u.age > 20');


See Dynamic namespace names (quoted identifiers) should escape backslash

Looks like the first syntax is just lucky. :) I haven't tried it myself, so if you say that query with escaping works just as query without escping, it's better use escaped queries.


Good point, but DQL takes query and matches to Namespace and Class before sending parsed query to database engine.

MyProject\Model\User is trim down to table name specified in User class.

SELECT u FROM MyProject\Model\User u WHERE u.age > 20 becomes

SELECT u FROM user[ie table name specified in User class] u WHERE u.age > 20

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜