Skip to content

Commit

Permalink
MDL-84532 qtype_ordering: Fix failing query in mssql on upgrade
Browse files Browse the repository at this point in the history
The SELECT statement can only include columns that are part of the
GROUP BY clause. To resolve this issue, instead of including all columns
('*'), only the 'id' column is now included in the SELECT statement,
while still preserving the existing GROUP BY statement. This column is
the only one needed to identify the relevant qtype_ordering_options
record that requires updating in the next step.
  • Loading branch information
Mihail Geshoski committed Feb 24, 2025
1 parent 5a8b259 commit d617d8b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions question/type/ordering/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ function xmldb_qtype_ordering_upgrade($oldversion) {
// We need to find all ordering question configurations that currently store the unsupported "0" (all) option
// for the 'selectcount' setting and the total number of answers that are related to each of these ordering
// questions.
$sql = "SELECT qoo.*, COUNT(DISTINCT(qa.id)) AS answerscount
$sql = "SELECT qoo.id, COUNT(DISTINCT(qa.id)) AS answerscount
FROM {qtype_ordering_options} qoo
JOIN {question_answers} qa ON qa.question = qoo.questionid
WHERE selectcount = :selectcount
Expand All @@ -311,9 +311,8 @@ function xmldb_qtype_ordering_upgrade($oldversion) {
// to the total number of answers related to this question. This way, we are making sure that the original
// behavior is preserved and all existing items (answers) related to the question will be included in the
// subset.
$questionoption->selectcount = $questionoption->answerscount;
unset($questionoption->answerscount);
$DB->update_record('qtype_ordering_options', $questionoption);
$DB->set_field('qtype_ordering_options', 'selectcount', $questionoption->answerscount,
['id' => $questionoption->id]);
}
$questionoptions->close();

Expand Down Expand Up @@ -341,7 +340,7 @@ function xmldb_qtype_ordering_upgrade($oldversion) {
// We need to find all ordering question configurations that currently store the unsupported "0" (all) option
// for the 'selectcount' setting and the total number of answers that are related to each of these ordering
// questions.
$sql = "SELECT qoo.*, COUNT(DISTINCT(qa.id)) AS answerscount
$sql = "SELECT qoo.id, COUNT(DISTINCT(qa.id)) AS answerscount
FROM {qtype_ordering_options} qoo
JOIN {question_answers} qa ON qa.question = qoo.questionid
WHERE selectcount = :selectcount
Expand All @@ -352,9 +351,8 @@ function xmldb_qtype_ordering_upgrade($oldversion) {
// to the total number of answers related to this question. This way, we are making sure that the original
// behavior is preserved and all existing items (answers) related to the question will be included in the
// subset.
$questionoption->selectcount = $questionoption->answerscount;
unset($questionoption->answerscount);
$DB->update_record('qtype_ordering_options', $questionoption);
$DB->set_field('qtype_ordering_options', 'selectcount', $questionoption->answerscount,
['id' => $questionoption->id]);
}
$questionoptions->close();

Expand Down

0 comments on commit d617d8b

Please sign in to comment.