MDL-84532 qtype_ordering: Fix failing query in mssql on upgrade

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.
This commit is contained in:
Mihail Geshoski
2025-02-24 18:02:06 +08:00
parent e06475d8ae
commit cdce19d0d0
+6 -8
View File
@@ -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
@@ -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();
@@ -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
@@ -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();