From: stronk7 Date: Sat, 13 Jan 2007 00:32:19 +0000 (+0000) Subject: Some more uses of $CFG->dbfamily. MDL-7061 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a4bad45c2c67cc7fa7d76e17a05c0797ec6309ef;p=moodle.git Some more uses of $CFG->dbfamily. MDL-7061 --- diff --git a/mod/data/field/latlong/field.class.php b/mod/data/field/latlong/field.class.php index 9addeca64f..8e9d14af7d 100755 --- a/mod/data/field/latlong/field.class.php +++ b/mod/data/field/latlong/field.class.php @@ -169,14 +169,15 @@ class data_field_latlong extends data_field_base { 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 +?> diff --git a/mod/data/field/number/field.class.php b/mod/data/field/number/field.class.php index 3d5a019d4e..3bb34649b6 100755 --- a/mod/data/field/number/field.class.php +++ b/mod/data/field/number/field.class.php @@ -47,12 +47,13 @@ class data_field_number extends data_field_base { 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; } } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 8518bf45dd..41ca909eef 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -1278,7 +1278,7 @@ function forum_search_posts($searchterms, $courseid=0, $limitfrom=0, $limitnum=5 // Some differences SQL $LIKE = sql_ilike(); $NOTLIKE = 'NOT ' . $LIKE; - if ($CFG->dbtype == 'postgres7') { + if ($CFG->dbfamily == 'postgres') { $REGEXP = '~*'; $NOTREGEXP = '!~*'; } else { @@ -1584,8 +1584,7 @@ function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC", } //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 @@ -1596,7 +1595,7 @@ function forum_get_discussions($forum="0", $forumsort="d.timemodified DESC", 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, @@ -4074,7 +4073,7 @@ function forum_tp_count_forum_read_records($userid, $forumid, $groupid=false) { $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 ( " @@ -4091,7 +4090,7 @@ function forum_tp_count_forum_read_records($userid, $forumid, $groupid=false) { . " 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 '. diff --git a/mod/forum/search.php b/mod/forum/search.php index 29015ce568..cb2b46aa4a 100644 --- a/mod/forum/search.php +++ b/mod/forum/search.php @@ -294,7 +294,7 @@ function forum_print_big_search_form($course) { echo ''; echo ''; - if ($CFG->dbtype == 'mysql' || $CFG->dbtype == 'postgres7') { + if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') { echo ''; echo ''.get_string('searchfullwords', 'forum').':'; echo ''; diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 123a31209a..c1c699281e 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -946,8 +946,8 @@ function glossary_search($course, $searchterms, $extended = 0, $glossary = NULL) } /// 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 = "~*"; @@ -976,7 +976,7 @@ function glossary_search($course, $searchterms, $extended = 0, $glossary = NULL) /// 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, '+-'); } diff --git a/mod/glossary/sql.php b/mod/glossary/sql.php index 19b3b4779c..7f59a5587e 100644 --- a/mod/glossary/sql.php +++ b/mod/glossary/sql.php @@ -135,7 +135,7 @@ case 'search': /// Some differences in syntax for PostgreSQL - if ($CFG->dbtype == "postgres7") { + if ($CFG->dbfamily == "postgres") { $REGEXP = "~*"; $NOTREGEXP = "!~*"; } else { @@ -163,7 +163,7 @@ /// 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, '+-'); }