function get_sort_sql($fieldname) {
global $DB;
- switch ($DB->get_db_family()) {
- case 'mysql':
- // string in an arithmetic operation is converted to a floating-point number
- return '('.$fieldname.'+0.0)';
- case 'postgres':
- //cast is for PG
- return 'CAST('.$fieldname.' AS REAL)';
- default:
- //Return just the fieldname. TODO: Look behaviour under MSSQL and Oracle
- return $fieldname;
- }
+ return $DB->sql_cast_char2real($fieldname, true);
}
function export_text_value($record) {
function get_sort_sql($fieldname) {
global $DB;
- switch ($DB->get_db_family()) {
- case 'mysql':
- // string in an arithmetic operation is converted to a floating-point number
- return '('.$fieldname.'+0.0)';
- case 'postgres':
- // cast for PG
- return 'CAST('.$fieldname.' AS REAL)';
- default:
- // the rest, just the field name. TODO: Analyse behaviour under MSSQL and Oracle
- return $fieldname;
- }
+ return $DB->sql_cast_char2real($fieldname, true);
}
}
} else {
- $sortcontent = $sortfield->get_sort_field();
- $sortcontentfull = $sortfield->get_sort_sql('c.'.$sortcontent);
+ $sortcontent = $DB->sql_compare_text('c.' . $sortfield->get_sort_field());
+ $sortcontentfull = $sortfield->get_sort_sql($sortcontent);
- $what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname, '.$DB->sql_compare_text($sortcontentfull).' AS _order ';
+ $what = ' DISTINCT r.id, r.approved, r.timecreated, r.timemodified, r.userid, u.firstname, u.lastname, ' . $sortcontentfull . ' AS _order ';
$count = ' COUNT(DISTINCT c.recordid) ';
$tables = '{data_content} c, {data_records} r, {data_content} cs, {user} u ';
$where = 'WHERE c.recordid = r.id