MDL-38215 Fix cross-db support in workshop SQL queries

The $sql used in these methods may contain multiple parts glued
together by the UNION operator. Simply appending the ORDER BY statement
to the end of the query does not work in all DBs (failure reported at
Oracle). Following the pattern already applied in MDL-30051, we wrap the
SQL into yet another SELECT statement and perform ordering there.

Credit goes to Sara Cenni for suggesting the fix.
This commit is contained in:
David Mudrák
2013-03-13 15:17:42 +01:00
parent 1bfc006d96
commit 95c7d1d076
+9 -3
View File
@@ -400,7 +400,9 @@ class workshop {
return array();
}
$sql .= " ORDER BY lastname ASC, firstname ASC, id ASC";
$sql = "SELECT *
FROM ($sql) tmp
ORDER BY tmp.lastname ASC, tmp.firstname ASC, tmp.id ASC";
return $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
}
@@ -448,7 +450,9 @@ class workshop {
return array();
}
$sql .= " ORDER BY lastname ASC, firstname ASC, id ASC";
$sql = "SELECT *
FROM ($sql) tmp
ORDER BY tmp.lastname ASC, tmp.firstname ASC, tmp.id ASC";
return $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
}
@@ -498,7 +502,9 @@ class workshop {
return array();
}
$sql .= " ORDER BY lastname ASC, firstname ASC, id ASC";
$sql = "SELECT *
FROM ($sql) tmp
ORDER BY tmp.lastname ASC, tmp.firstname ASC, tmp.id ASC";
return $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
}