Skip to content

Commit

Permalink
Fixing offsetting in paginated queries in SqlSrv
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jun 21, 2011
1 parent 2e5bdd8 commit 9aa2a42
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions lib/Cake/Model/Datasource/Database/Sqlserver.php
Expand Up @@ -517,9 +517,6 @@ public function renderStatement($type, $data) {
$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)';
}
Expand All @@ -530,7 +527,7 @@ public function renderStatement($type, $data) {
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;
Expand Down

0 comments on commit 9aa2a42

Please sign in to comment.