From: stronk7 Date: Sat, 13 Jan 2007 00:52:59 +0000 (+0000) Subject: Some more uses of $CFG->dbfamily. MDL-7061 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=38b72419344aee53ac6c21c7511e6bc3aaf49cfa;p=moodle.git Some more uses of $CFG->dbfamily. MDL-7061 --- diff --git a/mod/hotpot/db/update_to_v2.php b/mod/hotpot/db/update_to_v2.php index 91655b292a..4b8441eb21 100644 --- a/mod/hotpot/db/update_to_v2.php +++ b/mod/hotpot/db/update_to_v2.php @@ -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) { diff --git a/mod/hotpot/lib.php b/mod/hotpot/lib.php index d3a496fc88..3decc5432c 100644 --- a/mod/hotpot/lib.php +++ b/mod/hotpot/lib.php @@ -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; diff --git a/mod/wiki/ewikimoodlelib.php b/mod/wiki/ewikimoodlelib.php index d5a0a74647..2ef331df24 100644 --- a/mod/wiki/ewikimoodlelib.php +++ b/mod/wiki/ewikimoodlelib.php @@ -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: diff --git a/search/lib.php b/search/lib.php index ba40fc7f13..8cdd62c9df 100644 --- a/search/lib.php +++ b/search/lib.php @@ -58,11 +58,11 @@ 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: @@ -110,4 +110,4 @@ exit(0); } //search_pexit -?> \ No newline at end of file +?>