Permalink
Browse files

two fixes connected with UTF migration: (i) remove $CFG->prefix from …

…all index names, (ii) force type of "name" field in "hotpot_questions" table to "text"
  • Loading branch information...
gbateson
gbateson committed Apr 23, 2006
1 parent ec16135 commit df795ee9508f865f90d03b294232faca53e30a1e
Showing with 56 additions and 18 deletions.
  1. +7 −8 mod/hotpot/db/mysql.php
  2. +7 −7 mod/hotpot/db/mysql.sql
  3. +5 −0 mod/hotpot/db/postgres7.php
  4. +37 −3 mod/hotpot/db/update_to_v2.php
View
@@ -21,17 +21,15 @@ function hotpot_upgrade($oldversion) {
$ok = $ok && hotpot_get_update_to_v2();
$ok = $ok && hotpot_update_to_v2_1_2();
}
-
- if ($oldversion < 2006042100) {
- $result = execute_sql("ALTER TABLE {$CFG->prefix}hotpot_questions DROP INDEX {$CFG->prefix}hotpot_questions_name_idx");
- $result = execute_sql("ALTER TABLE {$CFG->prefix}hotpot_questions ADD INDEX hotpot_questions_name_idx (name(20))");
-
- }
-
-
+ // update to HotPot v2.1.16
+ if ($oldversion < 2006042101) {
+ $ok = $ok && hotpot_get_update_to_v2();
+ $ok = $ok && hotpot_update_to_v2_1_16();
+ }
return $ok;
}
+
function hotpot_get_update_to_v2() {
global $CFG;
$filepath = "$CFG->dirroot/mod/hotpot/db/update_to_v2.php";
@@ -43,4 +41,5 @@ function hotpot_get_update_to_v2() {
}
return $ok;
}
+
?>
View
@@ -44,8 +44,8 @@ CREATE TABLE prefix_hotpot_attempts (
status tinyint(4) unsigned NOT NULL default '1',
clickreportid int(10) unsigned default NULL,
PRIMARY KEY (id),
- KEY prefix_hotpot_attempts_hotpot_idx (hotpot),
- KEY prefix_hotpot_attempts_userid_idx (userid)
+ KEY hotpot_attempts_hotpot_idx (hotpot),
+ KEY hotpot_attempts_userid_idx (userid)
) TYPE=MyISAM COMMENT='details about Hot Potatoes quiz attempts';
#
# Table structure for table `hotpot_details`
@@ -55,7 +55,7 @@ CREATE TABLE prefix_hotpot_details (
attempt int(10) unsigned NOT NULL default '0',
details text default '',
PRIMARY KEY (id),
- KEY prefix_hotpot_details_attempt_idx (attempt)
+ KEY hotpot_details_attempt_idx (attempt)
) TYPE=MyISAM COMMENT='raw details (as XML) of Hot Potatoes quiz attempts';
#
# Table structure for table `hotpot_questions`
@@ -68,7 +68,7 @@ CREATE TABLE prefix_hotpot_questions (
hotpot int(10) unsigned NOT NULL default '0',
PRIMARY KEY (id),
KEY hotpot_questions_name_idx (name(20)),
- KEY prefix_hotpot_questions_hotpot_idx (hotpot)
+ KEY hotpot_questions_hotpot_idx (hotpot)
) TYPE=MyISAM COMMENT='details about questions in Hot Potatoes quiz attempts';
#
# Table structure for table `hotpot_responses`
@@ -86,8 +86,8 @@ CREATE TABLE prefix_hotpot_responses (
clues smallint(6) default NULL,
checks smallint(6) default NULL,
PRIMARY KEY (id),
- KEY prefix_hotpot_responses_attempt_idx (attempt),
- KEY prefix_hotpot_responses_question_idx (question)
+ KEY hotpot_responses_attempt_idx (attempt),
+ KEY hotpot_responses_question_idx (question)
) TYPE=MyISAM COMMENT='details about responses in Hot Potatoes quiz attempts';
#
# Table structure for table `hotpot_strings`
@@ -96,6 +96,6 @@ CREATE TABLE prefix_hotpot_strings (
id int(10) unsigned NOT NULL auto_increment,
string text NOT NULL default '',
PRIMARY KEY (id),
- KEY prefix_hotpot_strings_string_idx (string(20))
+ KEY hotpot_strings_string_idx (string(20))
) TYPE=MyISAM COMMENT='strings used in Hot Potatoes questions and responses';
@@ -27,6 +27,11 @@ function hotpot_upgrade($oldversion) {
$ok = $ok && hotpot_get_update_to_v2();
$ok = $ok && hotpot_update_to_v2_1_8();
}
+ // update to HotPot v2.1.16
+ if ($oldversion < 2006042101) {
+ $ok = $ok && hotpot_get_update_to_v2();
+ $ok = $ok && hotpot_update_to_v2_1_16();
+ }
return $ok;
}
function hotpot_get_update_to_v2() {
@@ -1,4 +1,31 @@
<?PHP
+function hotpot_update_to_v2_1_16() {
+ global $CFG;
+ $ok = true;
+
+ // 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') {
+ $ok = $ok && hotpot_index_remove_prefix('hotpot_attempts', 'hotpot');
+ $ok = $ok && hotpot_index_remove_prefix('hotpot_attempts', 'userid');
+ $ok = $ok && hotpot_index_remove_prefix('hotpot_details', 'attempt');
+ $ok = $ok && hotpot_index_remove_prefix('hotpot_questions', 'hotpot');
+ $ok = $ok && hotpot_index_remove_prefix('hotpot_questions', 'name', 20);
+ $ok = $ok && hotpot_index_remove_prefix('hotpot_responses', 'attempt');
+ $ok = $ok && hotpot_index_remove_prefix('hotpot_responses', 'question');
+ $ok = $ok && hotpot_index_remove_prefix('hotpot_strings', 'string', 20);
+ }
+ return $ok;
+}
+function hotpot_index_remove_prefix($table, $field, $length=0) {
+ global $CFG;
+ $index = "{$table}_{$field}_idx";
+ hotpot_db_delete_index("{$CFG->prefix}$table", "{$CFG->prefix}$index");
+ hotpot_db_delete_index("{$CFG->prefix}$table", $index);
+ return hotpot_db_add_index($table, $field, $length);
+}
+
function hotpot_update_to_v2_1_8() {
global $CFG;
$ok = true;
@@ -776,13 +803,20 @@ function hotpot_db_delete_index($table, $index, $feedback=false) {
}
function hotpot_db_add_index($table, $field, $length='') {
global $CFG, $db;
- // expand $table and $index names
+
+ if (strtolower($CFG->dbtype)=='postgres7') {
+ $index = "{$CFG->prefix}{$table}_{$field}_idx";
+ } else {
+ // mysql (and others)
+ $index = "{$table}_{$field}_idx";
+ }
$table = "{$CFG->prefix}$table";
- $index = "{$table}_{$field}_idx";
+
// delete $index if it already exists
$ok = hotpot_db_delete_index($table, $index);
+
switch (strtolower($CFG->dbtype)) {
- case 'mysql' :
+ case 'mysql' :
$length = empty($length) ? '' : " ($length)";
$ok = $ok && $db->Execute("ALTER TABLE `$table` ADD INDEX `$index` (`$field`$length)");
break;

0 comments on commit df795ee

Please sign in to comment.