Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

mod/glossary, mod/hotpot: use sql_concat() and sql_concat_join()

Cleaned up several dbtype conditionals too.
  • Loading branch information...
commit d2715c70b614ebc8dae2d4b183659f1656184703 1 parent 38e02f4
martinlanghoff authored
4 mod/glossary/sql.php
View
@@ -92,9 +92,9 @@
break;
case 'mysql':
if ( $sqlsortkey == 'FIRSTNAME' ) {
- $usernamefield = "CONCAT(CONCAT(u.firstname,' '), u.lastname)";
+ $usernamefield = sql_fullname('u.firstname' , 'u.lastname');
} else {
- $usernamefield = "CONCAT(CONCAT(u.lastname,' '), u.firstname)";
+ $usernamefield = sql_fullname('u.lastname' , 'u.firsttname');
}
$where = "AND left(ucase($usernamefield)," . $textlib->strlen($hook, current_charset()) . ") = '$hook'";
break;
10 mod/hotpot/index.php
View
@@ -203,14 +203,8 @@
$questions = false;
$regradehotpots = array();
- switch (strtolower($CFG->dbtype)) {
- case 'mysql' :
- $field = "CONCAT(hotpot, '_', name)";
- break;
- case 'postgres7' :
- $field = "hotpot||'_'||name";
- break;
- }
+ $field = sql_concat('hotpot', "'_'", 'name');
+
if ($field) {
$questions = get_records_sql("
SELECT $field, COUNT(*), hotpot, name
22 mod/hotpot/lib.php
View
@@ -1089,17 +1089,31 @@ function hotpot_get_grades($hotpot, $user_ids='') {
break;
case HOTPOT_GRADEMETHOD_FIRST:
if ($CFG->dbtype=='postgres7') {
- $grade = "MIN(timestart||'_'||(CASE WHEN (score IS NULL) THEN '' ELSE TRIM(ROUND(score * $weighting, $precision)) END)) AS grade";
+ $grade = "(CASE WHEN (score IS NULL)
+ THEN ''
+ ELSE TRIM(ROUND(score * $weighting, $precision))
+ END)";
} else {
- $grade = "MIN(CONCAT(timestart, '_', IF(score IS NULL, '', ROUND(score * $weighting, $precision)))) AS grade";
+ $grade = "IF(score IS NULL,
+ '',
+ ROUND(score * $weighting, $precision))";
}
+ $grade = sql_concat('timestart', "'_'", $grade);
+ $grade = "MIN($grade) AS grade";
break;
case HOTPOT_GRADEMETHOD_LAST:
if ($CFG->dbtype=='postgres7') {
- $grade = "MAX(timestart||'_'||(CASE WHEN (score IS NULL) THEN '' ELSE TRIM(ROUND(score * $weighting, $precision)) END)) AS grade";
+ $grade = "(CASE WHEN (score IS NULL)
+ THEN ''
+ ELSE TRIM(ROUND(score * $weighting, $precision))
+ END)";
} else {
- $grade = "MAX(CONCAT(timestart, '_', IF(score IS NULL, '', ROUND(score * $weighting, $precision)))) AS grade";
+ $grade = "IF(score IS NULL,
+ '',
+ ROUND(score * $weighting, $precision))";
}
+ $grade = sql_concat('timestart', "'_'", $grade);
+ $grade = "MAX($grade) AS grade";
break;
}
14 mod/hotpot/report.php
View
@@ -594,18 +594,8 @@ function hotpot_get_records_groupby($function, $fieldnames, $table, $select, $gr
// $function is an SQL aggregate function (MAX or MIN)
global $CFG;
-
- switch (strtolower($CFG->dbtype)) {
- case 'mysql':
- $fields = "$groupby, $function(CONCAT(".join(",'_',", $fieldnames).")) AS joinedvalues";
- break;
- case 'postgres7':
- $fields = "$groupby, $function(".join("||'_'||", $fieldnames).") AS joinedvalues";
- break;
- default:
- $fields = "";
- break;
- }
+ $fields = sql_concat_join("'_'", $fieldnames);
+ $fields = "$groupby, $function($fields) AS joinedvalues";
if ($fields) {
$records = get_records_sql("SELECT $fields FROM $table WHERE $select GROUP BY $groupby");
Please sign in to comment.
Something went wrong with that request. Please try again.