Issues

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

Issue Type: Bug Created: 2012-08-17T18:32:19.000+0000 Last Updated: 2012-10-08T20:14:57.000+0000 Status: Closed Fix version(s): Reporter: Bruno VACHRY (doubleslash) Assignee: Ralph Schindler (ralph) Tags: - Zend\Db

  • Select
  • Zend\Db\Sql\Select
  • rand()

Related issues: Attachments:

Description

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

<pre class="highlight">
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);
    }



<pre class="highlight">
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

Posted by Ralph Schindler (ralph) on 2012-10-08T20:14:57.000+0000

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

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts