2010-09-23 66 views
1

我想測試DQL是否支持這種語法:ROUND(NOW(), 'YEAR')(MySQL確實)。以下是我試過在MySQL控制檯:如何在沒有FROM子句的情況下測試dql代碼?

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

試圖在DQL同樣的事情給出了這樣:

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 

如何測試在DQL的功能,而無需使用FROM子句?

回答

1

你可以做這樣的事情:

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

我知道你不想使用FROM子句,但我認爲DQL查詢必須作用於模型。

greg0ire>對我來說,這裏是我試過(和結果):

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

謝謝,這個作品!太糟糕了,如果沒有至少有一條記錄的表格,就無法測試功能... – greg0ire 2010-09-23 13:13:18

相關問題