From 95c7d1d0763f072ce399e57596838340537f7db2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Wed, 13 Mar 2013 15:17:42 +0100 Subject: [PATCH] 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. --- mod/workshop/locallib.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index 60ff66702e8..d79554e6644 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -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); }