MDL-72722 reportbuilder: Oracle support for distinct group concat.

Requirements for Oracle were increased to 19c for Moodle 4.1 - now
with support for DISTINCT keyword within the LISTAGG function:

https://livesql.oracle.com/apex/livesql/file/content_HT1O85E4BHSBWN93G1B3M8SI2.html
This commit is contained in:
Paul Holden
2022-06-22 23:09:03 +01:00
parent 8f492a836a
commit 9a24440386
2 changed files with 7 additions and 4 deletions
@@ -51,6 +51,7 @@ class groupconcatdistinct extends groupconcat {
$dbsupportedtype = in_array($DB->get_dbfamily(), [
'mysql',
'postgres',
'oracle',
]);
return $dbsupportedtype && parent::compatible($columntype);
@@ -66,8 +67,10 @@ class groupconcatdistinct extends groupconcat {
public static function get_field_sql(string $field, int $columntype): string {
global $DB;
// DB limitations mean we only support MySQL and Postgres, and each handle it differently.
$fieldsort = database::sql_group_concat_sort($field);
// Postgres handles group concatenation differently in that it requires the expression to be cast to char, so we can't
// simply pass "DISTINCT {$field}" to the {@see \moodle_database::sql_group_concat} method in all cases.
if ($DB->get_dbfamily() === 'postgres') {
$field = $DB->sql_cast_to_char($field);
if ($fieldsort !== '') {
@@ -20,6 +20,7 @@ namespace core_reportbuilder\local\aggregation;
use core_reportbuilder_testcase;
use core_reportbuilder_generator;
use core_reportbuilder\local\report\column;
use core_user\reportbuilder\datasource\users;
defined('MOODLE_INTERNAL') || die();
@@ -44,9 +45,8 @@ class groupconcatdistinct_test extends core_reportbuilder_testcase {
public function setUp(): void {
global $DB;
$dbfamily = $DB->get_dbfamily();
if (!in_array($dbfamily, ['mysql', 'postgres'])) {
$this->markTestSkipped("Distinct group concatenation not supported in {$dbfamily}");
if (!groupconcatdistinct::compatible(column::TYPE_TEXT)) {
$this->markTestSkipped('Distinct group concatenation not supported in ' . $DB->get_dbfamily());
}
}