MDL-72184 dml: implement driver methods for casting to char.

This commit is contained in:
Paul Holden
2022-06-12 19:31:34 +01:00
parent ca583bddaf
commit 27f9929b52
5 changed files with 73 additions and 2 deletions
+11 -1
View File
@@ -1453,6 +1453,16 @@ class pgsql_native_moodle_database extends moodle_database {
return '((' . $int1 . ') # (' . $int2 . '))';
}
/**
* Return SQL for casting to char of given field/expression
*
* @param string $field Table field or SQL expression to be cast
* @return string
*/
public function sql_cast_to_char(string $field): string {
return "CAST({$field} AS VARCHAR)";
}
public function sql_cast_char2int($fieldname, $text=false) {
return ' CAST(' . $fieldname . ' AS INT) ';
}
@@ -1493,7 +1503,7 @@ class pgsql_native_moodle_database extends moodle_database {
*/
public function sql_group_concat(string $field, string $separator = ', ', string $sort = ''): string {
$fieldsort = $sort ? "ORDER BY {$sort}" : '';
return "STRING_AGG(CAST({$field} AS VARCHAR), '{$separator}' {$fieldsort})";
return "STRING_AGG(" . $this->sql_cast_to_char($field) . ", '{$separator}' {$fieldsort})";
}
public function sql_regex_supported() {