Permalink
Browse files

MDL-26844 ugly workaround for PHP int size limitation in query limits

It looks like the pg driver or database is internally overflowing at least on my 64bit test setup, I think we can safely return all results when from + num is over our max PHP integer.
  • Loading branch information...
1 parent 3d24c50 commit 4335aa296e09d9a0329af7231bb241e8585d193c @skodak skodak committed Mar 16, 2011
Showing with 6 additions and 0 deletions.
  1. +6 −0 lib/dml/pgsql_native_moodle_database.php
View
6 lib/dml/pgsql_native_moodle_database.php
@@ -623,6 +623,9 @@ public function get_recordset_sql($sql, array $params=null, $limitfrom=0, $limit
if ($limitfrom or $limitnum) {
if ($limitnum < 1) {
$limitnum = "ALL";
+ } else if (PHP_INT_MAX - $limitnum < $limitfrom) {
+ // this is a workaround for weird max int problem
+ $limitnum = "ALL";
}
$sql .= " LIMIT $limitnum OFFSET $limitfrom";
}
@@ -662,6 +665,9 @@ public function get_records_sql($sql, array $params=null, $limitfrom=0, $limitnu
if ($limitfrom or $limitnum) {
if ($limitnum < 1) {
$limitnum = "ALL";
+ } else if (PHP_INT_MAX - $limitnum < $limitfrom) {
+ // this is a workaround for weird max int problem
+ $limitnum = "ALL";
}
$sql .= " LIMIT $limitnum OFFSET $limitfrom";
}

0 comments on commit 4335aa2

Please sign in to comment.