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

Cleaned up several dbtype conditionals too.
This commit is contained in:
martinlanghoff 2006-09-26 05:06:44 +00:00
parent 38e02f4c32
commit d2715c70b6
4 changed files with 24 additions and 26 deletions

View File

@ -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;

View File

@ -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

View File

@ -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;
}

View File

@ -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");