Issues

ZF-2211: between support in select statement

Description

Hi,

I'd like to use the "BETWEEN" operator in my select statement. (ex : SELECT * FROM product WHERE price BETWEEN x AND y) Currently i don't see how i can do this. So I write my own function, I give it to you the code, but i think there is a better way to do the same thing cause in fact i just want to quote 2 values separatly. It should be better if the where function do something like that.

 
    /**
    * $select->between('price BETWEEN ? ', 100, 200);
    */

    public function between($cond)
    {
        if (func_num_args() > 1) {
            $min  = $this->_adapter->quote(func_get_arg(1));
            $max  = $this->_adapter->quote(func_get_arg(2));
            $cond = str_replace('?', $min . ' AND ' . $max, $cond);
        }

        if ($this->_parts[self::WHERE]) {
            $this->_parts[self::WHERE][] = "AND ($cond)";
        } else {
            $this->_parts[self::WHERE][] = "($cond)";
        }

        return $this;
    }

Comments

Well...

The actual way would be


$this->where('price > ?', 100)->where('price < ?', 200);

I think "Between" is not supported by all adapters.

Unassigned as original additional where methodology was not accepted.

Class will be reworked by Simon... sorry if I confused anybody. He has a better overview over the complete Db design, not only Zend_Db_Select and will help better than me.

Please evaluate and categorize as necessary.

Reassigning to Ralph since he's the new maintainer of Zend_Db

Will be evaluted with linked issue, I am not sure between is the correct addition where WHERE would be more intuitive

The BETWEEN operator is part of SQL-92 and AFAIK is well supported by the RDBMSes Zend_Db abstracts. I would favor implementation of ZF-2142 (Allow the where() method of Zend_Db_Select to accept multiple arguments for automatic quoting) instead of the OP's suggestion:


$select->where('price BETWEEN ? AND ?', 100, 200);

Closing as Won't Fix.