]> git.mjollnir.org Git - moodle.git/commitdiff
Some more uses of $CFG->dbfamily. MDL-7061
authorstronk7 <stronk7>
Sat, 13 Jan 2007 00:52:59 +0000 (00:52 +0000)
committerstronk7 <stronk7>
Sat, 13 Jan 2007 00:52:59 +0000 (00:52 +0000)
mod/hotpot/db/update_to_v2.php
mod/hotpot/lib.php
mod/wiki/ewikimoodlelib.php
search/lib.php

index 91655b292a19c9c0989184484a52f9d735dd8852..4b8441eb216a3c555764f127981bfcc2da523a53 100644 (file)
@@ -6,7 +6,7 @@ function hotpot_update_to_v2_2() {
     // remove the index on hotpot_questions.name
     $table = 'hotpot_questions';
     $field = 'name';
-    if (strtolower($CFG->dbtype)=='postgres7') {
+    if (strtolower($CFG->dbfamily)=='postgres') {
         $index = "{$CFG->prefix}{$table}_{$field}_idx";
     } else {
         $index = "{$table}_{$field}_idx";
@@ -30,7 +30,7 @@ function hotpot_update_to_v2_2() {
     // remove the index on hotpot_strings.string
     $table = 'hotpot_strings';
     $field = 'string';
-    if (strtolower($CFG->dbtype)=='postgres7') {
+    if (strtolower($CFG->dbfamily)=='postgres') {
         $index = "{$CFG->prefix}{$table}_{$field}_idx";
     } else {
         $index = "{$table}_{$field}_idx";
@@ -57,7 +57,7 @@ function hotpot_update_to_v2_1_21() {
     global $CFG;
     $ok = true;
 
-    if (strtolower($CFG->dbtype)=='postgres7') {
+    if (strtolower($CFG->dbfamily)=='postgres') {
         // ensure setting of default values on certain fields
         // this was originally done in postgres7.php, but was found to be incompatible with PG7 :-(
         $table="hotpot";
@@ -183,7 +183,7 @@ function hotpot_update_to_v2_1_16() {
     // make sure type of 'name' is a text field (not varchar 255)
     $ok = $ok && hotpot_db_update_field_type('hotpot_questions', 'name', 'name', 'TEXT',   '',  '', 'NOT NULL', '');
 
-    if (strtolower($CFG->dbtype)=='mysql') {
+    if (strtolower($CFG->dbfamily)=='mysql') {
 
         // set default values on certain VARCHAR(255) fields
         $fields = array(
@@ -217,7 +217,7 @@ function hotpot_index_remove_prefix($table, $field) {
 function hotpot_update_to_v2_1_8() {
     global $CFG;
     $ok = true;
-    if (strtolower($CFG->dbtype)=='postgres7') {
+    if (strtolower($CFG->dbfamily)=='postgres') {
         // add, delete and rename certain fields and indexes
         // that were not correctly setup by postgres7.sql
 
@@ -233,7 +233,7 @@ function hotpot_update_to_v2_1_6() {
     global $CFG;
     $ok = true;
 
-    if (strtolower($CFG->dbtype)=='postgres7') {
+    if (strtolower($CFG->dbfamily)=='postgres') {
         // add, delete and rename certain fields and indexes
         // that were not correctly setup by postgres7.sql
 
@@ -326,11 +326,11 @@ function hotpot_update_to_v2_1() {
     // hotpot_questions: change type of "name" field to "text"
     $ok = $ok && hotpot_db_update_field_type('hotpot_questions', 'name', 'name', 'TEXT',   '',  '', 'NOT NULL', '');
     // hotpot_questions: nullify empty and non-numeric (shouldn't be any) values in "text" field
-    switch (strtolower($CFG->dbtype)) {
+    switch (strtolower($CFG->dbfamily)) {
         case 'mysql' : 
             $NOT_REGEXP = 'NOT REGEXP';
         break;
-        case 'postgres7' :
+        case 'postgres' :
             $NOT_REGEXP = '!~';
         break;
         default:
@@ -349,9 +349,9 @@ function hotpot_update_to_v2_1() {
         // do nothing
     } else {
         $ok = $ok && hotpot_create_table($table);
-        switch (strtolower($CFG->dbtype)) {
+        switch (strtolower($CFG->dbfamily)) {
             case 'mysql' : 
-            case 'postgres7' :
+            case 'postgres' :
                 $sql = "
                     INSERT INTO {$CFG->prefix}$table (attempt, details) 
                     SELECT a.id AS attempt, a.details AS details
@@ -918,7 +918,7 @@ function hotpot_db_index_exists($table, $index, $feedback=false) {
     // save and switch off SQL message echo
     $debug = $db->debug;
     $db->debug = $feedback;
-    switch (strtolower($CFG->dbtype)) {
+    switch (strtolower($CFG->dbfamily)) {
         case 'mysql' : 
             $rs = $db->Execute("SHOW INDEX FROM `$table`");
             if ($rs && $rs->RecordCount()>0) {
@@ -931,7 +931,7 @@ function hotpot_db_index_exists($table, $index, $feedback=false) {
                 }
             }
         break;
-        case 'postgres7' :
+        case 'postgres' :
             $rs = $db->Execute("SELECT relname FROM pg_class WHERE relname = '$index' AND relkind='i'");
             if ($rs && $rs->RecordCount()>0) {
                 $exists = true;
@@ -947,11 +947,11 @@ function hotpot_db_delete_index($table, $index, $feedback=false) {
     $ok = true;
     // check index exists
     if (hotpot_db_index_exists($table, $index)) {
-        switch (strtolower($CFG->dbtype)) {
+        switch (strtolower($CFG->dbfamily)) {
             case 'mysql' : 
                 $sql = "ALTER TABLE `$table` DROP INDEX `$index`";
             break;
-            case 'postgres7' :
+            case 'postgres' :
                 $sql = "DROP INDEX $index";
             break;
             default: // unknown database type
@@ -974,7 +974,7 @@ function hotpot_db_delete_index($table, $index, $feedback=false) {
 function hotpot_db_add_index($table, $field, $length='') {
     global $CFG, $db;
 
-    if (strtolower($CFG->dbtype)=='postgres7') {
+    if (strtolower($CFG->dbfamily)=='postgres') {
         $index = "{$CFG->prefix}{$table}_{$field}_idx";
     } else {
         // mysql (and others)
@@ -985,11 +985,11 @@ function hotpot_db_add_index($table, $field, $length='') {
     // delete $index if it already exists
     $ok = hotpot_db_delete_index($table, $index);
 
-    switch (strtolower($CFG->dbtype)) {
+    switch (strtolower($CFG->dbfamily)) {
         case 'mysql' :
             $ok = $ok && $db->Execute("ALTER TABLE `$table` ADD INDEX `$index` (`$field`)");
         break;
-        case 'postgres7' :
+        case 'postgres' :
             $ok = $ok && $db->Execute("CREATE INDEX $index ON $table (\"$field\")");
         break;
         default: // unknown database type
@@ -1012,7 +1012,7 @@ function hotpot_db_object_exists($table, $field='', $feedback=false) {
     // expand table name
     $table = "{$CFG->prefix}$table";
     // set $sql
-    switch (strtolower($CFG->dbtype)) {
+    switch (strtolower($CFG->dbfamily)) {
         case 'mysql' : 
             if (empty($field)) {
                 $sql = "SHOW TABLES LIKE '$table'";
@@ -1020,7 +1020,7 @@ function hotpot_db_object_exists($table, $field='', $feedback=false) {
                 $sql = "SHOW COLUMNS FROM `$table` LIKE '$field'";
             }
         break;
-        case 'postgres7' :
+        case 'postgres' :
             if (empty($field)) {
                 $sql = "SELECT relname FROM pg_class WHERE relname = '$table' AND relkind='r'";
             } else {
@@ -1084,11 +1084,11 @@ function hotpot_db_append_table($oldtable, $table, $feedback=true) {
             if (empty($fieldnames)) {
                 $ok = false;
             } else {
-                switch (strtolower($CFG->dbtype)) {
+                switch (strtolower($CFG->dbfamily)) {
                     case 'mysql':
                         $ok = execute_sql("INSERT INTO `$table` ($fieldnames) SELECT $fieldnames FROM `$oldtable` WHERE 1");
                         break;
-                    case 'postgres7':
+                    case 'postgres':
                         $ok = execute_sql("INSERT INTO $table ($fieldnames) SELECT $fieldnames FROM $oldtable");
                         break;
                     default:
@@ -1107,11 +1107,11 @@ function hotpot_db_append_table($oldtable, $table, $feedback=true) {
 function hotpot_db_set_table_comment($table, $comment, $feedback=true) {
     global $CFG;
     $ok = true;
-    switch (strtolower($CFG->dbtype)) {
+    switch (strtolower($CFG->dbfamily)) {
         case 'mysql' :
             $ok = execute_sql("ALTER TABLE {$CFG->prefix}$table COMMENT='$comment'");
             break;
-        case 'postgres7' :
+        case 'postgres' :
             $ok = execute_sql("COMMENT ON TABLE {$CFG->prefix}$table IS '$comment'");
             break;
     }
@@ -1150,7 +1150,7 @@ function hotpot_db_update_field_type($table, $oldfield, $field, $type, $size, $u
     // set full table name
     $table = "{$CFG->prefix}$table";
     // update the field in the database
-    switch (strtolower($CFG->dbtype)) {
+    switch (strtolower($CFG->dbfamily)) {
         case 'mysql':
             // optimize integer types
             switch (strtoupper($type)) {
@@ -1202,7 +1202,7 @@ function hotpot_db_update_field_type($table, $oldfield, $field, $type, $size, $u
             }
             $ok = $ok && execute_sql("ALTER TABLE `$table` $action `$field` $fieldtype");
         break;
-        case 'postgres7':
+        case 'postgres':
             // get db version 
             //    N.B. $db->ServerInfo() usually returns blank 
             //    (except lib/adodb/drivers/adodb-postgre64-inc.php)
@@ -1270,7 +1270,7 @@ function hotpot_db_update_field_type($table, $oldfield, $field, $type, $size, $u
                 execute_sql('VACUUM FULL '.$table);
             }
         break;
-    } // end switch $CGF->dbtype
+    } // end switch $CGF->dbfamily
     return $ok;
 }
 function hotpot_db_update_record($table, $record, $forcenull=false) {
index d3a496fc881a003e25f54faf066c8f91095f9792..3decc5432c2c442c48aafbdb03883d422cb6db2a 100644 (file)
@@ -1153,7 +1153,7 @@ function hotpot_get_grades($hotpot, $user_ids='') {
             $grade = "ROUND(SUM(score)/COUNT(id) * $weighting, $precision) AS grade";
             break;
         case HOTPOT_GRADEMETHOD_FIRST:
-            if ($CFG->dbtype=='postgres7') {
+            if ($CFG->dbfamily=='postgres') {
                 $grade = "(CASE WHEN (score IS NULL) 
                                 THEN '' 
                                 ELSE TRIM(ROUND(score * $weighting, $precision)) 
@@ -1167,7 +1167,7 @@ function hotpot_get_grades($hotpot, $user_ids='') {
             $grade = "MIN($grade) AS grade";
             break;
         case HOTPOT_GRADEMETHOD_LAST:
-            if ($CFG->dbtype=='postgres7') {
+            if ($CFG->dbfamily=='postgres') {
                 $grade = "(CASE WHEN (score IS NULL) 
                                 THEN '' 
                                 ELSE TRIM(ROUND(score * $weighting, $precision)) 
@@ -1250,12 +1250,12 @@ function hotpot_scale_used ($hotpotid, $scaleid) {
 function hotpot_add_attempt($hotpotid) {
     global $db, $CFG, $USER;
     $time = time();
-    switch (strtolower($CFG->dbtype)) {
+    switch (strtolower($CFG->dbfamily)) {
         case 'mysql':
             $timefinish = "IF(a.timefinish IS NULL, '$time', a.timefinish)";
             $clickreportid = "IF(a.clickreportid IS NULL, a.id, a.clickreportid)";
             break;
-        case 'postgres7':
+        case 'postgres':
             $timefinish = "WHEN(a.timefinish IS NULL) THEN '$time' ELSE a.timefinish";
             $clickreportid = "WHEN(a.clickreportid IS NULL) THEN a.id ELSE a.clickreportid";
             break;
index d5a0a7464755fd703f0fd95efd8b9ee95b20c05f..2ef331df24467cddbc9621ca774386a176447176 100644 (file)
@@ -181,8 +181,8 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
           e.g. array("flags","meta","lastmodified");
       */
       case "GETALL":
-         switch ($CFG->dbtype) {
-             case 'postgres7':
+         switch ($CFG->dbfamily) {
+             case 'postgres':
                  $sql= "SELECT pagename AS id, ".
                       implode(", ", $args) .
                       " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
@@ -300,12 +300,11 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
 
 function anydb_escape_string($s) {
    global $CFG ;
-   $type = ($CFG->dbtype);
-   switch ($CFG->dbtype) {
+   switch ($CFG->dbfamily) {
         case 'mysql':
             $s = mysql_escape_string($s);
             break;
-        case 'postgres7':
+        case 'postgres':
             $s = pg_escape_string($s);
             break;
         default:
index ba40fc7f13dbed996cb966b92eb2d9ea1dbf33aa..8cdd62c9df925953967a2279224fccfa214988d5 100644 (file)
   function search_escape_string($str) {
     global $CFG;
 
-    switch ($CFG->dbtype) {
+    switch ($CFG->dbfamily) {
       case 'mysql':
         $s = mysql_real_escape_string($str);
         break;
-      case 'postgres7':
+      case 'postgres':
         $s = pg_escape_string($str);
         break;
       default:
     exit(0);
   } //search_pexit
 
-?>
\ No newline at end of file
+?>