Fixing offsetting in paginated queries in SqlSrv

This commit is contained in:
Jose Lorenzo Rodriguez 2011-06-21 17:09:12 -04:30
parent 2e5bdd862b
commit 9aa2a4227f

View file

@ -517,9 +517,6 @@ class Sqlserver extends DboSource {
$limit = preg_replace('/\s*offset.*$/i', '', $limit); $limit = preg_replace('/\s*offset.*$/i', '', $limit);
preg_match('/top\s+([0-9]+)/i', $limit, $limitVal); preg_match('/top\s+([0-9]+)/i', $limit, $limitVal);
$offset = intval($offset[1]) + intval($limitVal[1]); $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) { if (!$order) {
$order = 'ORDER BY (SELECT NULL)'; $order = 'ORDER BY (SELECT NULL)';
} }
@ -530,7 +527,7 @@ class Sqlserver extends DboSource {
SELECT {$fields}, ROW_NUMBER() OVER ({$order}) AS {$rowCounter} SELECT {$fields}, ROW_NUMBER() OVER ({$order}) AS {$rowCounter}
FROM {$table} {$alias} {$joins} {$conditions} {$group} FROM {$table} {$alias} {$joins} {$conditions} {$group}
) AS _cake_paging_ ) AS _cake_paging_
WHERE _cake_paging_.{$rowCounter} > {$limit2} WHERE _cake_paging_.{$rowCounter} >= {$offset}
ORDER BY _cake_paging_.{$rowCounter} ORDER BY _cake_paging_.{$rowCounter}
"; ";
return $pagination; return $pagination;