ZF-7666: LIMIT 0 ; fails to be generated
Denis reported in ZF-7650 that a receive(0) didn't work properly. I started checking all of the other Zend_Queue_Db adapter and found that the Zend_Db_Select() code suffers from a similar issue as well.
Our code executes the following:
$maxMessages = 0 $query->from($info['name'], array('*')) ->where('queue_id=?', $this->getQueueId($queue->getName())) ->where('handle IS NULL OR timeout+' . (int)$timeout . ' < ' . (int)$microtime) ->limit($maxMessages);
Which generates the following SQL:
SELECT `message`.* FROM `message` WHERE (queue_id=96) AND (handle IS NULL OR timeout+30 < 1251045482) FOR UPDATE
The LIMIT 0 is missing.
Which causes all values to be returned.
I tried a LIMIT 0 in MySQL, and I got the following
mysql> SELECT `message`.* FROM `message` WHERE (queue_id=96) AND (handle IS NULL OR timeout+30 < 1251045482) LIMIT 0 FOR UPDATE; Empty set (0.00 sec)
So, LIMIT 0 does work, it doesn't make a lot of sense, but it does work.