From ec2b44d779baed7f62c71e7b7ff0f8868626ea24 Mon Sep 17 00:00:00 2001 From: Benjamin Abraham Date: Mon, 4 Nov 2024 13:43:46 +0100 Subject: [PATCH] Fix #229 Use moodle's sql_cast_char2int() function to assure compatibility with all supported RDBMS --- lib.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib.php b/lib.php index 2d1566f..2625615 100644 --- a/lib.php +++ b/lib.php @@ -848,12 +848,14 @@ function choicegroup_get_choicegroup($choicegroupid) { $grpfilter = "AND grp_o.groupid = :groupid"; } + $castorderby = ($sortcolumn == 'name') ? $DB->sql_cast_char2int("REGEXP_SUBSTR($sortcolumn, '[0-9]+')") . "," : ""; + $sql = "SELECT grp_m.id grpmemberid, grp_m.userid, grp_o.id, grp_o.groupid, grp_o.maxanswers FROM {groups} grp INNER JOIN {choicegroup_options} grp_o on grp.id = grp_o.groupid LEFT JOIN {groups_members} grp_m on grp_m.groupid = grp_o.groupid WHERE grp_o.choicegroupid = :choicegroupid $grpfilter - ORDER BY $sortcolumn ASC"; + ORDER BY $castorderby $sortcolumn ASC"; $rs = $DB->get_recordset_sql($sql, $params);