function get_sort_sql($fieldname) {
global $CFG;
- switch ($CFG->dbtype) {
+ switch ($CFG->dbfamily) {
case 'mysql': // string in an arithmetic operation is converted to a floating-point number
return '('.$fieldname.'+0.0)';
-
- default:
+ 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;
}
}
}
-?>
\ No newline at end of file
+?>
function get_sort_sql($fieldname) {
global $CFG;
- switch ($CFG->dbtype) {
+ switch ($CFG->dbfamily) {
case 'mysql': // string in an arithmetic operation is converted to a floating-point number
return '('.$fieldname.'+0.0)';
-
- default:
+ 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;
}
}
// Some differences SQL
$LIKE = sql_ilike();
$NOTLIKE = 'NOT ' . $LIKE;
- if ($CFG->dbtype == 'postgres7') {
+ if ($CFG->dbfamily == 'postgres') {
$REGEXP = '~*';
$NOTREGEXP = '!~*';
} else {
}
//TODO: there must be a nice way to do this that keeps both postgres and mysql 3.2x happy but I can't find it right now.
- if ($CFG->dbtype == 'postgres7' || $CFG->dbtype == 'mssql' ||
- $CFG->dbtype == 'mssql_n' || $CFG->dbtype == 'odbc_mssql' || $CFG->dbtype == 'oci8po') {
+ if ($CFG->dbfamily == 'postgres' || $CFG->dbfamily == 'mssql' || $CFG->dbfamily == 'oracle') {
return get_records_sql("SELECT $postdata, d.name, d.timemodified, d.usermodified, d.groupid,
u.firstname, u.lastname, u.email, u.picture $umfields
FROM {$CFG->prefix}forum_discussions d
AND p.parent = 0
$timelimit $groupselect $userselect
ORDER BY $forumsort", $limitfrom, $limitnum);
- } else {
+ } else { // MySQL query. TODO: Check if this is needed (MySQL 4.1 should work with the above query)
return get_records_sql("SELECT $postdata, d.name, d.timemodified, d.usermodified, d.groupid,
u.firstname, u.lastname, u.email, u.picture $umfields
FROM ({$CFG->prefix}forum_posts p,
$groupsel = ' AND (d.groupid = '.$groupid.' OR d.groupid = -1)';
}
- if ($CFG->dbtype === 'postgres7') {
+ if ($CFG->dbfamily === 'postgres' || $CFG->dbfamily === 'mssql' || $CFG->dbfamily === 'oracle') {
// this query takes 20ms, vs several minutes for the one below
$sql = " SELECT COUNT (DISTINCT u.id ) "
. " FROM ( "
. " WHERE d.forum = $forumid $groupsel "
. " AND p.modified < $cutoffdate"
. ") u";
- } else {
+ } else { // This is for MySQL. TODO: Check if the above works for MySQL 4.1
$sql = 'SELECT COUNT(DISTINCT p.id) '.
'FROM '.$CFG->prefix.'forum_posts p,'.$CFG->prefix.'forum_read r,'.$CFG->prefix.'forum_discussions d '.
'WHERE d.forum = '.$forumid.$groupsel.' AND p.discussion = d.id AND '.
}
/// Some differences in syntax for entrygreSQL
- switch ($CFG->dbtype) {
- case 'postgres7':
+ switch ($CFG->dbfamily) {
+ case 'postgres':
$LIKE = "ILIKE"; // case-insensitive
$NOTLIKE = "NOT ILIKE"; // case-insensitive
$REGEXP = "~*";
/// Under Oracle and MSSQL, trim the + and - operators and perform
/// simpler LIKE search
- if ($CFG->dbtype == 'oci8po' || $CFG->dbtype == 'mssql' || $CFG->dbtype == 'mssql_n' || $CFG->dbtype == 'odbc_mssql') {
+ if ($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') {
$searchterm = trim($searchterm, '+-');
}
case 'search':
/// Some differences in syntax for PostgreSQL
- if ($CFG->dbtype == "postgres7") {
+ if ($CFG->dbfamily == "postgres") {
$REGEXP = "~*";
$NOTREGEXP = "!~*";
} else {
/// Under Oracle and MSSQL, trim the + and - operators and perform
/// simpler LIKE search
- if ($CFG->dbtype == 'oci8po' || $CFG->dbtype == 'mssql' || $CFG->dbtype == 'mssql_n' || $CFG->dbtype == 'odbc_mssql') {
+ if ($CFG->dbfamily == 'oracle' || $CFG->dbfamily == 'mssql') {
$searchterm = trim($searchterm, '+-');
}