ZF2-474: Zend\Db\Sql\Select doesn't support order by rand()

Description

Zend\Db\Sql\Select::processOrder() always add quote identifier to order's values.


protected function processOrder(PlatformInterface $platform, Adapter $adapter = null, ParameterContainer $parameterContainer = null)
    {
        if (empty($this->order)) {
            return null;
        }
        $orders = array();
        foreach ($this->order as $k => $v) {
            if (is_int($k)) {
                if (strpos($v, ' ') !== false) {
                    list($k, $v) = preg_split('# #', $v, 2);
                } else {
                    $k = $v;
                    $v = self::ORDER_ASCENDING;
                }
            }
            if (strtoupper($v) == self::ORDER_DESENDING) {
                $orders[] = array($platform->quoteIdentifierInFragment($k), self::ORDER_DESENDING);
            } else {
                $orders[] = array($platform->quoteIdentifierInFragment($k), self::ORDER_ASCENDING);
            }
        }
        return array($orders);
    }

protected function processOrder(PlatformInterface $platform, Adapter $adapter = null, ParameterContainer $parameterContainer = null)
    {
        if (empty($this->order)) {
            return null;
        }
        $orders = array();
        foreach ($this->order as $k => $v) {
            if (is_int($k) && is_string($v)) {
                if (strpos($v, ' ') !== false) {
                    list($k, $v) = preg_split('# #', $v, 2);
                } else {
                    $k = $v;
                    $v = self::ORDER_ASCENDING;
                }
                
                if (strtoupper($v) == self::ORDER_DESENDING) {
                    $orders[] = array($platform->quoteIdentifierInFragment($k), self::ORDER_DESENDING);
                } else {
                    $orders[] = array($platform->quoteIdentifierInFragment($k), self::ORDER_ASCENDING);
                }
            }
            elseif(is_a($v,'Zend\Db\Sql\Expression')) {
                $v = $v->getExpression();
                if (strpos($v, ' ') !== false) {
                    list($k, $v) = preg_split('# #', $v, 2);
                } else {
                    $k = $v;
                    $v = self::ORDER_ASCENDING;
                }
                
                if (strtoupper($v) == self::ORDER_DESENDING) {
                    $orders[] = array($k, self::ORDER_DESENDING);
                } else {
                    $orders[] = array($k, self::ORDER_ASCENDING);
                }
            }
        }
        return array($orders);
    }

Comments

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2529