Permalink
Browse files

dml-sqlserver MDL-25321 Changed bigint-1 to a variable and used that …

…instead of the int
  • Loading branch information...
1 parent 35d19ea commit 875851a1957509edef30472c997721f8b9bb5a44 Sam Hemelryk committed Dec 23, 2010
Showing with 6 additions and 2 deletions.
  1. +6 −2 lib/dml/sqlsrv_native_moodle_database.php
@@ -779,10 +779,14 @@ private function limit_to_top_n($sql, $offset, $limit) {
// Make sure they are at least 0
$limit = max(0, (int)$limit);
$offset = max(0, (int)$offset);
+ // This is an sqlserver bigint - -1 and will be used as a value
+ // for top when essentially we want everything.
+ // This needs to be a string so that it doesn't get malformed.
+ $bigint = '9223372036854775806';
// If limit is 0 set it to BITINT - 1
if (empty($limit)) {
- $limit = 9223372036854775806;
+ $limit = $bigint;
} else {
$limit = $offset + $limit;
}
@@ -864,7 +868,7 @@ private function limit_to_top_n($sql, $offset, $limit) {
}
// Build the inner outer query.
- $sql = "SELECT TOP 9223372036854775806 ROW_NUMBER() OVER(ORDER BY $orderby) AS sqlsrvrownumber, $columnnames FROM ($sql) AS q";
+ $sql = "SELECT TOP $bigint ROW_NUMBER() OVER(ORDER BY $orderby) AS sqlsrvrownumber, $columnnames FROM ($sql) AS q";
// Build the outer most query.
$sql = "SELECT $columnnames FROM ($sql) AS q WHERE q.sqlsrvrownumber > $offset AND q.sqlsrvrownumber <= $limit";

0 comments on commit 875851a

Please sign in to comment.