Skip to content

Commit

Permalink
Fix #229
Browse files Browse the repository at this point in the history
Use moodle's sql_cast_char2int() function to assure compatibility with all supported RDBMS
  • Loading branch information
Benjamin-unige committed Nov 4, 2024
1 parent f8828bf commit ec2b44d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit ec2b44d

Please sign in to comment.