zendframework / zend-db

Db component from Zend Framework
BSD 3-Clause "New" or "Revised" License
101 stars 122 forks source link

Issues in date format using new Expression("date_format(client_created, '%m-%d-%Y')") #151

Open kudeepak opened 8 years ago

kudeepak commented 8 years ago

https://github.com/zendframework/zendframework/blob/release-2.4/library/Zend/Db/Sql/Expression.php

As we checked, it has issues to format the date. When we have taken replaced the code of 2.4 with version 2.3, it is running proper You can look into the following function of the file "https://github.com/zendframework/zendframework/blob/release-2.4/library/Zend/Db/Sql/Expression.php"

 /**
     * @return array
     * @throws Exception\RuntimeException
     */
    public function getExpressionData()
    {
        $parameters = (is_scalar($this->parameters)) ? array($this->parameters) : $this->parameters;
        $types = array();
        $parametersCount = count($parameters);
        if ($parametersCount == 0 && strpos($this->expression, self::PLACEHOLDER) !== false) {
            // if there are no parameters, but there is a placeholder
            $parametersCount = substr_count($this->expression, self::PLACEHOLDER);
            $parameters = array_fill(0, $parametersCount, null);
        }
        for ($i = 0; $i < $parametersCount; $i++) {
            $types[$i] = (isset($this->types[$i]) && ($this->types[$i] == self::TYPE_IDENTIFIER || $this->types[$i] == self::TYPE_LITERAL))
                ? $this->types[$i] : self::TYPE_VALUE;
        }
        // assign locally, escaping % signs
        $expression = str_replace('%', '%%', $this->expression);
        if ($parametersCount > 0) {
            $count = 0;
            $expression = str_replace(self::PLACEHOLDER, '%s', $expression, $count);
            if ($count !== $parametersCount) {
                throw new Exception\RuntimeException('The number of replacements in the expression does not match the number of parameters');
            }
        }
        return array(array(
            $expression,
            $parameters,
            $types
        ));
    }
michalbundyra commented 4 years ago

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at https://github.com/laminas/laminas-db/issues/103.