Index: library/Zend/Db/Select.php =================================================================== --- library/Zend/Db/Select.php (revision 22458) +++ library/Zend/Db/Select.php (working copy) @@ -526,14 +526,14 @@ * appears. See {@link where()} for an example * * @param string $cond The HAVING condition. - * @param string|Zend_Db_Expr $val The value to quote into the condition. + * @param mixed $value OPTIONAL The value to quote into the condition. + * @param constant $type OPTIONAL The type of the given value * @return Zend_Db_Select This Zend_Db_Select object. */ - public function having($cond) + public function having($cond, $value = null, $type = null) { - if (func_num_args() > 1) { - $val = func_get_arg(1); - $cond = $this->_adapter->quoteInto($cond, $val); + if ($value) { + $cond = $this->_adapter->quoteInto($cond, $value, $type); } if ($this->_parts[self::HAVING]) { @@ -551,16 +551,16 @@ * Otherwise identical to orHaving(). * * @param string $cond The HAVING condition. - * @param mixed $val The value to quote into the condition. + * @param mixed $value OPTIONAL The value to quote into the condition. + * @param constant $type OPTIONAL The type of the given value * @return Zend_Db_Select This Zend_Db_Select object. * * @see having() */ - public function orHaving($cond) + public function orHaving($cond, $value = null, $type = null) { - if (func_num_args() > 1) { - $val = func_get_arg(1); - $cond = $this->_adapter->quoteInto($cond, $val); + if ($value) { + $cond = $this->_adapter->quoteInto($cond, $value, $type); } if ($this->_parts[self::HAVING]) { Index: tests/Zend/Db/Select/StaticTest.php =================================================================== --- tests/Zend/Db/Select/StaticTest.php (revision 22458) +++ tests/Zend/Db/Select/StaticTest.php (working copy) @@ -509,6 +509,99 @@ $this->assertEquals('SELECT "zfbugs_products"."bug_id", COUNT(*) AS "thecount" FROM "zfbugs_products" GROUP BY "bug_id" HAVING (COUNT(*) > 1) OR (COUNT(*) = 1) ORDER BY "bug_id" ASC', $sql); } + /** + * Test if the quotation type could be passed + * + * @group ZF-10000 + */ + public function testSelectHavingQuoteBySpecificType() + { + $select = $this->_select() + ->columns(array('count' => 'COUNT(*)')) + ->group('bug_id'); + + $select->having('COUNT(*) > ?', '1', Zend_Db::INT_TYPE); + $this->assertEquals('SELECT "zfproducts".*, COUNT(*) AS "count" FROM "zfproducts" GROUP BY "bug_id" HAVING (COUNT(*) > 1)', $select->__toString()); + } + + /** + * Test if the quotation is done for int + * + * @group ZF-10000 + */ + public function testSelectHavingQuoteAsIntAutomatically() + { + $select = $this->_select() + ->columns(array('count' => 'COUNT(*)')) + ->group('bug_id'); + + $select->having('COUNT(*) > ?', 1); + $this->assertEquals('SELECT "zfproducts".*, COUNT(*) AS "count" FROM "zfproducts" GROUP BY "bug_id" HAVING (COUNT(*) > 1)', $select->__toString()); + } + + /** + * Test if the quotation is done for string + * + * @group ZF-10000 + */ + public function testSelectHavingQuoteAsStringAutomatically() + { + $select = $this->_select() + ->columns(array('count' => 'COUNT(*)')) + ->group('bug_id'); + + $select->having('COUNT(*) > ?', '1'); + $this->assertEquals('SELECT "zfproducts".*, COUNT(*) AS "count" FROM "zfproducts" GROUP BY "bug_id" HAVING (COUNT(*) > \'1\')', $select->__toString()); + } + + /** + * Test if the quotation type could be passed + * + * @group ZF-10000 + */ + public function testSelectOrHavingQuoteBySpecificType() + { + $select = $this->_select() + ->columns(array('count' => 'COUNT(*)')) + ->group('bug_id'); + + $select->having('COUNT(*) > ?', '1', Zend_Db::INT_TYPE); + $select->orHaving('COUNT(*) = ?', '2', Zend_Db::INT_TYPE); + $this->assertEquals('SELECT "zfproducts".*, COUNT(*) AS "count" FROM "zfproducts" GROUP BY "bug_id" HAVING (COUNT(*) > 1) OR (COUNT(*) = 2)', $select->__toString()); + } + + /** + * Test if the quotation is done for int + * + * @group ZF-10000 + */ + public function testSelectOrHavingQuoteAsIntAutomatically() + { + $select = $this->_select() + ->columns(array('count' => 'COUNT(*)')) + ->group('bug_id'); + + $select->having('COUNT(*) > ?', 1); + $select->orHaving('COUNT(*) = ?', 2); + $this->assertEquals('SELECT "zfproducts".*, COUNT(*) AS "count" FROM "zfproducts" GROUP BY "bug_id" HAVING (COUNT(*) > 1) OR (COUNT(*) = 2)', $select->__toString()); + } + + /** + * Test if the quotation is done for string + * + * @group ZF-10000 + */ + public function testSelectOrHavingQuoteAsStringAutomatically() + { + $select = $this->_select() + ->columns(array('count' => 'COUNT(*)')) + ->group('bug_id'); + + $select->having('COUNT(*) > ?', '1'); + $select->orHaving('COUNT(*) = ?', '2'); + $this->assertEquals('SELECT "zfproducts".*, COUNT(*) AS "count" FROM "zfproducts" GROUP BY "bug_id" HAVING (COUNT(*) > \'1\') OR (COUNT(*) = \'2\')', $select->__toString()); + } + /** * Test adding an ORDER BY clause to a Zend_Db_Select object. */