From 9aa2a4227f1974472d32687eeffd0f23458ed9ba Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Tue, 21 Jun 2011 17:09:12 -0430 Subject: [PATCH] Fixing offsetting in paginated queries in SqlSrv --- lib/Cake/Model/Datasource/Database/Sqlserver.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Sqlserver.php b/lib/Cake/Model/Datasource/Database/Sqlserver.php index 32bc68f6e..d1c831bb1 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlserver.php +++ b/lib/Cake/Model/Datasource/Database/Sqlserver.php @@ -517,9 +517,6 @@ class Sqlserver extends DboSource { $limit = preg_replace('/\s*offset.*$/i', '', $limit); preg_match('/top\s+([0-9]+)/i', $limit, $limitVal); $offset = intval($offset[1]) + intval($limitVal[1]); - $rOrder = $this->__switchSort($order); - list($order2, $rOrder) = array($this->__mapFields($order), $this->__mapFields($rOrder)); - $limit2 = str_replace('TOP', '', $limit); if (!$order) { $order = 'ORDER BY (SELECT NULL)'; } @@ -530,7 +527,7 @@ class Sqlserver extends DboSource { SELECT {$fields}, ROW_NUMBER() OVER ({$order}) AS {$rowCounter} FROM {$table} {$alias} {$joins} {$conditions} {$group} ) AS _cake_paging_ - WHERE _cake_paging_.{$rowCounter} > {$limit2} + WHERE _cake_paging_.{$rowCounter} >= {$offset} ORDER BY _cake_paging_.{$rowCounter} "; return $pagination;