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 {
|
} else {
|
||||||
//could be a comma delimited string
|
//could be a comma delimited string
|
||||||
$bits=explode(',', $sqlQuery->limit);
|
$bits=explode(',', $sqlQuery->limit);
|
||||||
$limit=trim($bits[0]);
|
if(sizeof($bits) > 1) {
|
||||||
if(isset($bits[1]))
|
list($offset, $limit) = $bits;
|
||||||
$offset=trim($bits[1]);
|
} else {
|
||||||
|
$limit = $bits[0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$text = '';
|
$text = '';
|
||||||
@ -1030,9 +1032,14 @@ class MSSQLDatabase extends Database {
|
|||||||
|
|
||||||
// If there's a limit and an offset, then we need to do a subselect
|
// If there's a limit and an offset, then we need to do a subselect
|
||||||
} else if($limit && $offset) {
|
} else if($limit && $offset) {
|
||||||
$text = "SELECT * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY $sqlQuery->orderby)"
|
if($sqlQuery->orderby) {
|
||||||
. " AS Number, ";
|
$rowNumber = "ROW_NUMBER() OVER (ORDER BY $sqlQuery->orderby) AS Number";
|
||||||
$suffixText .= ") AS Numbered WHERE Number BETWEEN $offset AND " . ($offset+$limit)
|
} 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";
|
. " ORDER BY Number";
|
||||||
$nestedQuery = true;
|
$nestedQuery = true;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user