views:

24

answers:

1

Hello, 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')
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?

+1  A: 

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'
jeremy
Thank you, this works! Too bad you can't test function without having a table with at least one record...
greg0ire