]> git.mjollnir.org Git - moodle.git/commitdiff
Some more uses of $CFG->dbfamily. MDL-7061
authorstronk7 <stronk7>
Sat, 13 Jan 2007 00:32:19 +0000 (00:32 +0000)
committerstronk7 <stronk7>
Sat, 13 Jan 2007 00:32:19 +0000 (00:32 +0000)
mod/data/field/latlong/field.class.php
mod/data/field/number/field.class.php
mod/forum/lib.php
mod/forum/search.php
mod/glossary/lib.php
mod/glossary/sql.php

index 9addeca64fb0952277fb68beb4f6824ee3dd6a6b..8e9d14af7d440db4654c49cdf6be3c1a47cc7ae3 100755 (executable)
@@ -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
+?>
index 3d5a019d4e68d57399d0ae3edd68c8c4f3b77a55..3bb34649b682757bbc20830ac17f0a516578f9fd 100755 (executable)
@@ -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;
         }
     }
 
index 8518bf45dd9299582cfaa8e6d7e8ebc107a0b155..41ca909eef06b7abd66357719c6d57b8367c5e30 100644 (file)
@@ -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 '.
index 29015ce56841f6d122f7a7bab1a52220f334f590..cb2b46aa4a3454b42609ee42e45e6680555fe1b4 100644 (file)
@@ -294,7 +294,7 @@ function forum_print_big_search_form($course) {
     echo '<td class="c1"><input type="text" size="35" name="notwords" value="'.s($notwords).'" alt="" /></td>';
     echo '</tr>';
 
-    if ($CFG->dbtype == 'mysql' || $CFG->dbtype == 'postgres7') {
+    if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') {
         echo '<tr>';
         echo '<td class="c0">'.get_string('searchfullwords', 'forum').':</td>';
         echo '<td class="c1"><input type="text" size="35" name="fullwords" value="'.s($fullwords).'" alt="" /></td>';
index 123a31209ab7c0eb26ca372225ba9f3eeadab60c..c1c699281eb0c3798d08ced05119e76a0a37caf5 100644 (file)
@@ -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, '+-');
         }
 
index 19b3b4779c84663aefc6a1a4635e6ca1b7b6405b..7f59a5587eb935f8452ada2b91d1521f7f072559 100644 (file)
         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, '+-');
                 }