From c3d0157b0dcd4e1c710d4198d8f8615f93ef4ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Mudr=C3=A1k?= Date: Wed, 13 Mar 2013 14:24:16 +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 | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index 3d7781938a6..7cebddc7ba4 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -418,8 +418,10 @@ class workshop { return array(); } - list($sort, $sortparams) = users_order_by_sql('u'); - $sql .= " ORDER BY $sort"; + list($sort, $sortparams) = users_order_by_sql('tmp'); + $sql = "SELECT * + FROM ($sql) tmp + ORDER BY $sort"; return $DB->get_records_sql($sql, array_merge($params, $sortparams), $limitfrom, $limitnum); } @@ -467,8 +469,10 @@ class workshop { return array(); } - list($sort, $sortparams) = users_order_by_sql('u'); - $sql .= " ORDER BY $sort"; + list($sort, $sortparams) = users_order_by_sql('tmp'); + $sql = "SELECT * + FROM ($sql) tmp + ORDER BY $sort"; return $DB->get_records_sql($sql, array_merge($params, $sortparams), $limitfrom, $limitnum); } @@ -518,8 +522,10 @@ class workshop { return array(); } - list($sort, $sortparams) = users_order_by_sql(); - $sql .= " ORDER BY $sort"; + list($sort, $sortparams) = users_order_by_sql('tmp'); + $sql = "SELECT * + FROM ($sql) tmp + ORDER BY $sort"; return $DB->get_records_sql($sql, array_merge($params, $sortparams), $limitfrom, $limitnum); }