Explorar el Código

Added patch by Martin Hujer - resolves ZF-10000

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22850 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic hace 15 años
padre
commit
9950df79eb
Se han modificado 2 ficheros con 103 adiciones y 10 borrados
  1. 10 10
      library/Zend/Db/Select.php
  2. 93 0
      tests/Zend/Db/Select/StaticTest.php

+ 10 - 10
library/Zend/Db/Select.php

@@ -526,14 +526,14 @@ class Zend_Db_Select
      * appears. See {@link where()} for an example
      * appears. See {@link where()} for an example
      *
      *
      * @param string $cond The HAVING condition.
      * @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.
      * @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]) {
         if ($this->_parts[self::HAVING]) {
@@ -551,16 +551,16 @@ class Zend_Db_Select
      * Otherwise identical to orHaving().
      * Otherwise identical to orHaving().
      *
      *
      * @param string $cond The HAVING condition.
      * @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.
      * @return Zend_Db_Select This Zend_Db_Select object.
      *
      *
      * @see having()
      * @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]) {
         if ($this->_parts[self::HAVING]) {

+ 93 - 0
tests/Zend/Db/Select/StaticTest.php

@@ -509,6 +509,99 @@ class Zend_Db_Select_StaticTest extends Zend_Db_Select_TestCommon
         $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);
         $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.
      * Test adding an ORDER BY clause to a Zend_Db_Select object.
      */
      */