开发者

How can I test dql code without FROM clause?

I want to test whether DQL supports this syntax : ROUND(NOW(), 'YEAR') (MySQL does). Here is what I tried in MySQL console:

mysql> SELECT ROUND(NOW(), 'YEAR');
+----------------------+
| ROUND(NOW(), 'YEAR') |
+----------------------+
|       20100923135639 |
+----------------------+

Trying the same thing in DQL gives this:

techosaure :( \>~/workspace/carel  ./symfony  doctrine:dql --show-sql "Select ROUND(NOW(),'YEAR')";
>> doctrine  executing dql query
DQL: Select ROUND(NOW(),'YEAR'开发者_StackOverflow中文版)
PHP Fatal error:  Maximum function nesting level of '100' reached, aborting! in /opt/symfony-1.4.6/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Query/Tokenizer.php on line 352

How can I test a function in DQL without using a FROM clause?


You could do something like this:

Doctrine_Query::create()
  ->from('Model m')
  ->select('m.id, ROUND(NOW(), "YEAR") AS round_test')
  ->fetchOne();

I know you don't want to use a FROM clause, but I think DQL queries have to be acting on a model.

greg0ire> In my case, here is what I tried (and the result):

techosaure :( \>~/workspace/carel  ./symfony  doctrine:dql --show-sql "Select ROUND(NOW(),'YEAR') FROM AdminEntity";
>> doctrine  executing dql query
DQL: Select ROUND(NOW(),'YEAR') FROM AdminEntity
SQL: SELECT ROUND(NOW(), 'YEAR') AS a__0 FROM admin_entity a
found 1 results
-
  ROUND: '20100923151158'
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜