Browse Source

ZF-8901 - Fixed limit() method issue with order by multiple columns

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21885 44c647ce-9c0f-0410-b52a-842ac1e357ba
juokaz 16 years ago
parent
commit
86c0aeba00
2 changed files with 21 additions and 2 deletions
  1. 1 1
      library/Zend/Db/Adapter/Sqlsrv.php
  2. 20 1
      tests/Zend/Db/Adapter/SqlsrvTest.php

+ 1 - 1
library/Zend/Db/Adapter/Sqlsrv.php

@@ -620,7 +620,7 @@ class Zend_Db_Adapter_Sqlsrv extends Zend_Db_Adapter_Abstract
             if (!$orderby) {
                 $over = 'ORDER BY (SELECT 0)';
             } else {
-                $over = preg_replace('/\".*\".\"(.*)\"/i', '"inner_tbl"."$1"', $orderby);
+                $over = preg_replace('/\"[^,]*\".\"([^,]*)\"/i', '"inner_tbl"."$1"', $orderby);
             }
             
             // Remove ORDER BY clause from $sql

+ 20 - 1
tests/Zend/Db/Adapter/SqlsrvTest.php

@@ -535,7 +535,26 @@ class Zend_Db_Adapter_SqlsrvTest extends Zend_Db_Adapter_TestCommon
             'Expecting row count to be 1');
         $this->assertEquals(2, $result[0]['product_id'],
             'Expecting to get product_id 2');
-    }     
+    }  
+    
+    /**
+     * @group ZF-8901
+     */
+    public function testAdapterLimitOffsetWithMultipleOrderColumns()
+    {
+        $products = $this->_db->quoteIdentifier('zfproducts');
+        $product_id = $this->_db->quoteIdentifier('product_id');
+        $product_name = $this->_db->quoteIdentifier('product_name');
+
+        $sql = $this->_db->limit("SELECT * FROM $products ORDER BY $products.$product_id ASC, $products.$product_name DESC", 1, 1);
+
+        $stmt = $this->_db->query($sql);
+        $result = $stmt->fetchAll();
+        $this->assertEquals(1, count($result),
+            'Expecting row count to be 1');
+        $this->assertEquals(2, $result[0]['product_id'],
+            'Expecting to get product_id 2');
+    }    
 
     public function getDriver()
     {