This commit is contained in:
Víctor Déniz
2022-10-18 00:26:24 +01:00
2 changed files with 8 additions and 5 deletions
@@ -40,7 +40,7 @@ class groupconcatdistinct extends groupconcat {
}
/**
* This aggregation can be performed on all non-timestamp columns in MySQL and Postgres only
* This aggregation can be performed on all non-timestamp columns in MySQL, Postgres and Oracle only
*
* @param int $columntype
* @return bool
@@ -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());
}
}