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
Posted by Thomas Weidner (thomas) on 2007-11-16T11:26:15.000+0000
Well...
The actual way would be
I think "Between" is not supported by all adapters.
Posted by Thomas Weidner (thomas) on 2007-11-22T03:32:30.000+0000
Unassigned as original additional where methodology was not accepted.
Posted by Thomas Weidner (thomas) on 2008-03-11T03:33:59.000+0000
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.
Posted by Wil Sinclair (wil) on 2008-04-18T13:20:27.000+0000
Please evaluate and categorize as necessary.
Posted by Wil Sinclair (wil) on 2008-12-04T13:17:29.000+0000
Reassigning to Ralph since he's the new maintainer of Zend_Db
Posted by Ralph Schindler (ralph) on 2009-01-10T10:52:08.000+0000
Will be evaluted with linked issue, I am not sure between is the correct addition where WHERE would be more intuitive
Posted by Adam Lundrigan (adamlundrigan) on 2012-05-05T23:18:27.000+0000
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:
Closing as Won't Fix.