mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
BUGFIX: Fixed limit/offset code in MSSQL
This commit is contained in:
parent
bff10ffc99
commit
0585ef3908
@ -1006,9 +1006,11 @@ class MSSQLDatabase extends Database {
|
||||
} else {
|
||||
//could be a comma delimited string
|
||||
$bits=explode(',', $sqlQuery->limit);
|
||||
$limit=trim($bits[0]);
|
||||
if(isset($bits[1]))
|
||||
$offset=trim($bits[1]);
|
||||
if(sizeof($bits) > 1) {
|
||||
list($offset, $limit) = $bits;
|
||||
} else {
|
||||
$limit = $bits[0];
|
||||
}
|
||||
}
|
||||
|
||||
$text = '';
|
||||
@ -1030,9 +1032,14 @@ class MSSQLDatabase extends Database {
|
||||
|
||||
// If there's a limit and an offset, then we need to do a subselect
|
||||
} else if($limit && $offset) {
|
||||
$text = "SELECT * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY $sqlQuery->orderby)"
|
||||
. " AS Number, ";
|
||||
$suffixText .= ") AS Numbered WHERE Number BETWEEN $offset AND " . ($offset+$limit)
|
||||
if($sqlQuery->orderby) {
|
||||
$rowNumber = "ROW_NUMBER() OVER (ORDER BY $sqlQuery->orderby) AS Number";
|
||||
} else {
|
||||
$firstCol = reset($sqlQuery->select);
|
||||
$rowNumber = "ROW_NUMBER() OVER (ORDER BY $firstCol) AS Number";
|
||||
}
|
||||
$text = "SELECT * FROM ( SELECT $rowNumber, ";
|
||||
$suffixText .= ") AS Numbered WHERE Number BETWEEN " . ($offset+1) ." AND " . ($offset+$limit)
|
||||
. " ORDER BY Number";
|
||||
$nestedQuery = true;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user