Permalink
Browse files

add double quotes to index fields to avoid reserved words errors in p…

…g7. correct setting of default values in HotPot 2006050201 which was incompatible with pg7.3
  • Loading branch information...
1 parent ec64d52 commit 9b2f93bcf355dc9591bde7ac6b0e2c4b51e360f9 gbateson committed Jul 16, 2006
Showing with 86 additions and 89 deletions.
  1. +47 −86 mod/hotpot/db/postgres7.php
  2. +2 −2 mod/hotpot/db/postgres7.sql
  3. +37 −1 mod/hotpot/db/update_to_v2.php
View
133 mod/hotpot/db/postgres7.php
@@ -1,90 +1,51 @@
<?PHP
function hotpot_upgrade($oldversion) {
- global $CFG;
- $ok = true;
-
- // set path to update functions
- $update_to_v2 = "$CFG->dirroot/mod/hotpot/db/update_to_v2.php";
-
- // update from HotPot v1 to HotPot v2
- if ($oldversion < 2005031400) {
- require_once $update_to_v2;
- $ok = $ok && hotpot_update_to_v2_from_v1();
- }
- // update to HotPot v2.1
- if ($oldversion < 2005090700) {
- require_once $update_to_v2;
- $ok = $ok && hotpot_update_to_v2_1();
- }
- if ($oldversion > 2005031419 && $oldversion < 2005090702) {
- // update to from HotPot v2.1.0 or v2.1.1
- require_once $update_to_v2;
- $ok = $ok && hotpot_update_to_v2_1_2();
- }
- if ($oldversion < 2005090706) {
- require_once $update_to_v2;
- $ok = $ok && hotpot_update_to_v2_1_6();
- }
- if ($oldversion < 2005090708) {
- require_once $update_to_v2;
- $ok = $ok && hotpot_update_to_v2_1_8();
- }
- if ($oldversion < 2006042103) {
- require_once $update_to_v2;
- $ok = $ok && hotpot_update_to_v2_1_16();
- }
- if ($oldversion < 2006042602) {
- require_once $update_to_v2;
- $ok = $ok && hotpot_update_to_v2_1_17();
- }
- if ($oldversion < 2006042803) {
- require_once $update_to_v2;
- $ok = $ok && hotpot_update_to_v2_1_18();
- }
-
-
- if ($oldversion < 2006050201) {
-
- modify_database('', 'ALTER TABLE prefix_hotpot
- ALTER COLUMN studentfeedbackurl SET DEFAULT \'\',
- ALTER COLUMN studentfeedbackurl SET NOT NULL,
- ALTER COLUMN clickreporting SET DEFAULT 0,
- ALTER COLUMN studentfeedback SET DEFAULT 0');
-
- modify_database('', 'ALTER TABLE prefix_hotpot_strings
- ALTER COLUMN string SET DEFAULT \'\'');
-
- modify_database('', 'ALTER TABLE prefix_hotpot_responses
- ALTER COLUMN hints TYPE int2,
- ALTER COLUMN hints SET DEFAULT 0,
- ALTER COLUMN ignored SET DEFAULT \'\',
- ALTER COLUMN ignored SET NOT NULL,
- ALTER COLUMN score TYPE int2,
- ALTER COLUMN score SET DEFAULT 0,
- ALTER COLUMN correct SET DEFAULT \'\',
- ALTER COLUMN correct SET NOT NULL,
- ALTER COLUMN weighting TYPE int2,
- ALTER COLUMN weighting SET DEFAULT 0,
- ALTER COLUMN wrong SET DEFAULT \'\',
- ALTER COLUMN wrong SET NOT NULL,
- ALTER COLUMN checks TYPE int2,
- ALTER COLUMN checks SET DEFAULT 0,
- ALTER COLUMN clues TYPE int2,
- ALTER COLUMN clues SET DEFAULT 0');
-
- modify_database('', 'ALTER TABLE prefix_hotpot_questions
- ALTER COLUMN "type" SET DEFAULT 0');
-
- modify_database('', 'ALTER TABLE prefix_hotpot_attempts
- ALTER COLUMN penalties TYPE smallint,
- ALTER COLUMN penalties SET DEFAULT 0,
- ALTER COLUMN score TYPE smallint,
- ALTER COLUMN score SET DEFAULT 0,
- ALTER COLUMN status SET DEFAULT 1');
-
- }
-
-
- return $ok;
+ global $CFG;
+ $ok = true;
+
+ // set path to update functions
+ $update_to_v2 = "$CFG->dirroot/mod/hotpot/db/update_to_v2.php";
+
+ // update from HotPot v1 to HotPot v2
+ if ($oldversion < 2005031400) {
+ require_once $update_to_v2;
+ $ok = $ok && hotpot_update_to_v2_from_v1();
+ }
+
+ // update to HotPot v2.1
+ if ($oldversion < 2005090700) {
+ require_once $update_to_v2;
+ $ok = $ok && hotpot_update_to_v2_1();
+ }
+ if ($oldversion > 2005031419 && $oldversion < 2005090702) {
+ require_once $update_to_v2;
+ $ok = $ok && hotpot_update_to_v2_1_2();
+ }
+ if ($oldversion < 2005090706) {
+ require_once $update_to_v2;
+ $ok = $ok && hotpot_update_to_v2_1_6();
+ }
+ if ($oldversion < 2005090708) {
+ require_once $update_to_v2;
+ $ok = $ok && hotpot_update_to_v2_1_8();
+ }
+ if ($oldversion < 2006042103) {
+ require_once $update_to_v2;
+ $ok = $ok && hotpot_update_to_v2_1_16();
+ }
+ if ($oldversion < 2006042602) {
+ require_once $update_to_v2;
+ $ok = $ok && hotpot_update_to_v2_1_17();
+ }
+ if ($oldversion < 2006042803) {
+ require_once $update_to_v2;
+ $ok = $ok && hotpot_update_to_v2_1_18();
+ }
+ if ($oldversion < 2006071600) {
+ require_once $update_to_v2;
+ $ok = $ok && hotpot_update_to_v2_1_21();
+ }
+
+ return $ok;
}
?>
View
4 mod/hotpot/db/postgres7.sql
@@ -79,7 +79,7 @@ CREATE TABLE prefix_hotpot_questions (
COMMENT ON TABLE prefix_hotpot_questions IS 'details about questions in Hot Potatoes quiz attempts';
CREATE INDEX prefix_hotpot_questions_hotpot_idx ON prefix_hotpot_questions (hotpot);
-CREATE INDEX prefix_hotpot_questions_name_idx ON prefix_hotpot_questions (SUBSTR(name,20));
+CREATE INDEX prefix_hotpot_questions_name_idx ON prefix_hotpot_questions (SUBSTR("name",20));
#
# Table structure for table `hotpot_responses`
@@ -113,4 +113,4 @@ CREATE TABLE prefix_hotpot_strings (
);
COMMENT ON TABLE prefix_hotpot_strings IS 'strings used in Hot Potatoes questions and responses';
-CREATE INDEX prefix_hotpot_strings_string_idx ON prefix_hotpot_strings (SUBSTR(string,20));
+CREATE INDEX prefix_hotpot_strings_string_idx ON prefix_hotpot_strings (SUBSTR("string",20));
View
38 mod/hotpot/db/update_to_v2.php
@@ -1,4 +1,40 @@
<?PHP
+function hotpot_update_to_v2_1_21() {
+ global $CFG;
+ $ok = true;
+
+ if (strtolower($CFG->dbtype)=='postgres7') {
+ // 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";
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'studentfeedbackurl', 'VARCHAR', 255, '', 'NOT NULL', '');
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'studentfeedback', 'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 0);
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'clickreporting', 'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 0);
+
+ $table="hotpot_attempts";
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'score', 'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 0);
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'penalties', 'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 0);
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'status', 'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 1);
+
+ $table="hotpot_questions";
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'type', 'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 0);
+
+ $table="hotpot_responses";
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'score', 'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 0);
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'weighting', 'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 0);
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'correct', 'VARCHAR', 255, '', 'NOT NULL', '');
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'wrong', 'VARCHAR', 255, '', 'NOT NULL', '');
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'ignored', 'VARCHAR', 255, '', 'NOT NULL', '');
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'hints', 'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 0);
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'clues', 'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 0);
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'checks', 'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 0);
+
+ $table="hotpot_strings";
+ $ok = $ok && hotpot_db_update_field_type($table, '', 'string', 'TEXT', '', '', 'NOT NULL', '');
+ }
+
+ return $ok;
+}
function hotpot_update_to_v2_1_18() {
$ok = true;
@@ -933,7 +969,7 @@ function hotpot_db_add_index($table, $field, $length='') {
break;
case 'postgres7' :
if ($length) {
- $field = "SUBSTR($field,$length)";
+ $field = "SUBSTR(\"$field\",$length)";
}
$ok = $ok && $db->Execute("CREATE INDEX $index ON $table ($field)");
break;

0 comments on commit 9b2f93b

Please sign in to comment.