From ffb762aae0fc91cc31048f7cc4d9d7cfc8ace200 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Wed, 13 Jul 2022 23:44:16 +0200 Subject: [PATCH] MDL-75208 oracle: Amend a couple of queries to make Oracle happy The changes introduced here are completely safe, just we stop binding SITEID and, instead, embed it in the SQL. Why? Because Oracle 21 has started to return non-sense results when SITEID is bound. After lots of tests, attempts, debugging... we have been unable to find any logic to the need of this change and also, have been unable to reproduce the problem with a standalone script that pretty much runs the same queries that the ones changed here. I'm sure that there is something, somewhere, but have failed to find it, grrr. Please read MDL-75208 and linked issues to find more information about this problem, that is one of the biggest mysteries I've seen recently. Maybe at the end there is a tiny detail that explains it all, but it's really well hidden. --- course/lib.php | 7 ++----- lib/enrollib.php | 8 ++++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/course/lib.php b/course/lib.php index 803d28da3ac..1aa7d42ee8d 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2477,9 +2477,7 @@ function update_course($data, $editoroptions = NULL) { function average_number_of_participants(bool $onlyactive = false, int $lastloginsince = null): float { global $DB; - $params = [ - 'siteid' => SITEID, - ]; + $params = []; $sql = "SELECT DISTINCT ue.userid, e.courseid FROM {user_enrolments} ue @@ -2490,8 +2488,7 @@ function average_number_of_participants(bool $onlyactive = false, int $lastlogin $sql .= "JOIN {user} u ON u.id = ue.userid "; } - $sql .= "WHERE e.courseid <> :siteid - AND c.visible = 1 "; + $sql .= "WHERE e.courseid <> " . SITEID . " AND c.visible = 1 "; if ($onlyactive) { $sql .= "AND ue.status = :active diff --git a/lib/enrollib.php b/lib/enrollib.php index 334784091bf..c053a3faaab 100644 --- a/lib/enrollib.php +++ b/lib/enrollib.php @@ -670,8 +670,8 @@ function enrol_get_my_courses($fields = null, $sort = null, $limit = 0, $coursei $orderby = "ORDER BY $sort"; } - $wheres = array("c.id <> :siteid"); - $params = array('siteid'=>SITEID); + $wheres = ['c.id <> ' . SITEID]; + $params = []; if (isset($USER->loginascontext) and $USER->loginascontext->contextlevel == CONTEXT_COURSE) { // list _only_ this course - anything else is asking for trouble... @@ -1075,7 +1075,7 @@ function enrol_get_all_users_courses($userid, $onlyactive = false, $fields = nul $orderby = "ORDER BY $sort"; } - $params = array('siteid'=>SITEID); + $params = []; if ($onlyactive) { $subwhere = "WHERE ue.status = :active AND e.status = :enabled AND ue.timestart < :now1 AND (ue.timeend = 0 OR ue.timeend > :now2)"; @@ -1101,7 +1101,7 @@ function enrol_get_all_users_courses($userid, $onlyactive = false, $fields = nul $subwhere ) en ON (en.courseid = c.id) $ccjoin - WHERE c.id <> :siteid + WHERE c.id <> " . SITEID . " $orderby"; $params['userid'] = $userid;