From 2ff317ac8a6731a9a9fc3559c4ecde9a11a77372 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Mon, 5 Sep 2022 21:35:27 +0100 Subject: [PATCH] MDL-70613 mod_feedback: cast feedback text values for table sorting. Specifically avoids Oracle ORA-00932 (inconsistent CLOB datatype). --- mod/feedback/classes/responses_table.php | 6 ++++-- mod/feedback/tests/behat/non_anonymous.feature | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mod/feedback/classes/responses_table.php b/mod/feedback/classes/responses_table.php index 6b0731033e4..58a9c241127 100644 --- a/mod/feedback/classes/responses_table.php +++ b/mod/feedback/classes/responses_table.php @@ -289,6 +289,8 @@ class mod_feedback_responses_table extends table_sql { * are only needed when outputting or downloading data. */ protected function add_all_values_to_output() { + global $DB; + $tablecolumns = array_keys($this->columns); $tableheaders = $this->headers; @@ -308,7 +310,7 @@ class mod_feedback_responses_table extends table_sql { if ($columnscount++ < self::TABLEJOINLIMIT) { // Mysql has a limit on the number of tables in the join, so we only add limited number of columns here, // the rest will be added in {@link self::build_table()} and {@link self::build_table_chunk()} functions. - $this->sql->fields .= ", v{$nr}.value AS val{$nr}"; + $this->sql->fields .= ", " . $DB->sql_cast_to_char("v{$nr}.value") . " AS val{$nr}"; $this->sql->from .= " LEFT OUTER JOIN {feedback_value} v{$nr} " . "ON v{$nr}.completed = c.id AND v{$nr}.item = :itemid{$nr}"; $this->sql->params["itemid{$nr}"] = $item->id; @@ -560,7 +562,7 @@ class mod_feedback_responses_table extends table_sql { $from = '{feedback_completed} c'; $params = []; foreach ($columnsgroup as $nr => $item) { - $fields .= ", v{$nr}.value AS val{$nr}"; + $fields .= ", " . $DB->sql_cast_to_char("v{$nr}.value") . " AS val{$nr}"; $from .= " LEFT OUTER JOIN {feedback_value} v{$nr} " . "ON v{$nr}.completed = c.id AND v{$nr}.item = :itemid{$nr}"; $params["itemid{$nr}"] = $item->id; diff --git a/mod/feedback/tests/behat/non_anonymous.feature b/mod/feedback/tests/behat/non_anonymous.feature index b25964bc722..0e329babc10 100644 --- a/mod/feedback/tests/behat/non_anonymous.feature +++ b/mod/feedback/tests/behat/non_anonymous.feature @@ -140,6 +140,12 @@ Feature: Non anonymous feedback And I should not see "Next" And I should see "Prev" And I click on "Back" "link" in the "region-main" "region" + # Sort the feedback responses. + And I click on "Do you like this course?" "link" in the "generaltable" "table" + And "Username 1" "table_row" should appear before "Username 2" "table_row" + # Now sort descending. + And I click on "Do you like this course?" "link" in the "generaltable" "table" + And "Username 2" "table_row" should appear before "Username 1" "table_row" # Delete non anonymous response And I click on "Delete entry" "link" in the "Username 1" "table_row" And I press "Yes"