Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 9b2f93bcf355dc9591bde7ac6b0e2c4b51e360f9 1 parent ec64d52
authored July 16, 2006
133  mod/hotpot/db/postgres7.php
... ...
@@ -1,90 +1,51 @@
1 1
 <?PHP
2 2
 function hotpot_upgrade($oldversion) {
3  
-	global $CFG;
4  
-	$ok = true;
5  
-
6  
-	// set path to update functions
7  
-	$update_to_v2 = "$CFG->dirroot/mod/hotpot/db/update_to_v2.php";
8  
-
9  
-	// update from HotPot v1 to HotPot v2
10  
-	if ($oldversion < 2005031400) {
11  
-		require_once $update_to_v2;
12  
-		$ok = $ok && hotpot_update_to_v2_from_v1();
13  
-	}
14  
-	// update to HotPot v2.1
15  
-	if ($oldversion < 2005090700) {
16  
-		require_once $update_to_v2;
17  
-		$ok = $ok && hotpot_update_to_v2_1();
18  
-	}
19  
-	if ($oldversion > 2005031419 && $oldversion < 2005090702) {
20  
-		// update to from HotPot v2.1.0 or v2.1.1
21  
-		require_once $update_to_v2;
22  
-		$ok = $ok && hotpot_update_to_v2_1_2();
23  
-	}
24  
-	if ($oldversion < 2005090706) {
25  
-		require_once $update_to_v2;
26  
-		$ok = $ok && hotpot_update_to_v2_1_6();
27  
-	}
28  
-	if ($oldversion < 2005090708) {
29  
-		require_once $update_to_v2;
30  
-		$ok = $ok && hotpot_update_to_v2_1_8();
31  
-	}
32  
-	if ($oldversion < 2006042103) {
33  
-		require_once $update_to_v2;
34  
-		$ok = $ok && hotpot_update_to_v2_1_16();
35  
-	}
36  
-	if ($oldversion < 2006042602) {
37  
-		require_once $update_to_v2;
38  
-		$ok = $ok && hotpot_update_to_v2_1_17();
39  
-	}
40  
-	if ($oldversion < 2006042803) {
41  
-		require_once $update_to_v2;
42  
-		$ok = $ok && hotpot_update_to_v2_1_18();
43  
-	}
44  
-
45  
-
46  
-        if ($oldversion < 2006050201) {
47  
-
48  
-            modify_database('', 'ALTER TABLE prefix_hotpot
49  
-                ALTER COLUMN studentfeedbackurl SET DEFAULT \'\',
50  
-                ALTER COLUMN studentfeedbackurl SET NOT NULL,
51  
-                ALTER COLUMN clickreporting SET DEFAULT 0,
52  
-                ALTER COLUMN studentfeedback SET DEFAULT 0');
53  
-
54  
-            modify_database('', 'ALTER TABLE prefix_hotpot_strings
55  
-                ALTER COLUMN string SET DEFAULT \'\'');
56  
-
57  
-            modify_database('', 'ALTER TABLE prefix_hotpot_responses
58  
-                ALTER COLUMN hints TYPE int2,
59  
-                ALTER COLUMN hints SET DEFAULT 0,
60  
-                ALTER COLUMN ignored SET DEFAULT \'\',
61  
-                ALTER COLUMN ignored SET NOT NULL,
62  
-                ALTER COLUMN score TYPE int2,
63  
-                ALTER COLUMN score SET DEFAULT 0,
64  
-                ALTER COLUMN correct SET DEFAULT \'\',
65  
-                ALTER COLUMN correct SET NOT NULL,
66  
-                ALTER COLUMN weighting TYPE int2,
67  
-                ALTER COLUMN weighting SET DEFAULT 0,
68  
-                ALTER COLUMN wrong SET DEFAULT \'\',
69  
-                ALTER COLUMN wrong SET NOT NULL,
70  
-                ALTER COLUMN checks TYPE int2,
71  
-                ALTER COLUMN checks SET DEFAULT 0,
72  
-                ALTER COLUMN clues TYPE int2,
73  
-                ALTER COLUMN clues SET DEFAULT 0');
74  
-
75  
-            modify_database('', 'ALTER TABLE prefix_hotpot_questions
76  
-                ALTER COLUMN "type" SET DEFAULT 0');
77  
-
78  
-            modify_database('', 'ALTER TABLE prefix_hotpot_attempts
79  
-                ALTER COLUMN penalties TYPE smallint,
80  
-                ALTER COLUMN penalties SET DEFAULT 0,
81  
-                ALTER COLUMN score TYPE smallint,
82  
-                ALTER COLUMN score SET DEFAULT 0,
83  
-                ALTER COLUMN status SET DEFAULT 1');
84  
-
85  
-        }
86  
-
87  
-
88  
-        return $ok;
  3
+    global $CFG;
  4
+    $ok = true;
  5
+
  6
+    // set path to update functions
  7
+    $update_to_v2 = "$CFG->dirroot/mod/hotpot/db/update_to_v2.php";
  8
+
  9
+    // update from HotPot v1 to HotPot v2
  10
+    if ($oldversion < 2005031400) {
  11
+        require_once $update_to_v2;
  12
+        $ok = $ok && hotpot_update_to_v2_from_v1();
  13
+    }
  14
+
  15
+    // update to HotPot v2.1
  16
+    if ($oldversion < 2005090700) {
  17
+        require_once $update_to_v2;
  18
+        $ok = $ok && hotpot_update_to_v2_1();
  19
+    }
  20
+    if ($oldversion > 2005031419 && $oldversion < 2005090702) {
  21
+        require_once $update_to_v2;
  22
+        $ok = $ok && hotpot_update_to_v2_1_2();
  23
+    }
  24
+    if ($oldversion < 2005090706) {
  25
+        require_once $update_to_v2;
  26
+        $ok = $ok && hotpot_update_to_v2_1_6();
  27
+    }
  28
+    if ($oldversion < 2005090708) {
  29
+        require_once $update_to_v2;
  30
+        $ok = $ok && hotpot_update_to_v2_1_8();
  31
+    }
  32
+    if ($oldversion < 2006042103) {
  33
+        require_once $update_to_v2;
  34
+        $ok = $ok && hotpot_update_to_v2_1_16();
  35
+    }
  36
+    if ($oldversion < 2006042602) {
  37
+        require_once $update_to_v2;
  38
+        $ok = $ok && hotpot_update_to_v2_1_17();
  39
+    }
  40
+    if ($oldversion < 2006042803) {
  41
+        require_once $update_to_v2;
  42
+        $ok = $ok && hotpot_update_to_v2_1_18();
  43
+    }
  44
+    if ($oldversion < 2006071600) {
  45
+        require_once $update_to_v2;
  46
+        $ok = $ok && hotpot_update_to_v2_1_21();
  47
+    }
  48
+
  49
+    return $ok;
89 50
 }
90 51
 ?>
4  mod/hotpot/db/postgres7.sql
@@ -79,7 +79,7 @@ CREATE TABLE prefix_hotpot_questions (
79 79
 COMMENT ON TABLE prefix_hotpot_questions IS 'details about questions in Hot Potatoes quiz attempts';
80 80
 
81 81
 CREATE INDEX prefix_hotpot_questions_hotpot_idx ON prefix_hotpot_questions (hotpot);
82  
-CREATE INDEX prefix_hotpot_questions_name_idx ON prefix_hotpot_questions (SUBSTR(name,20));
  82
+CREATE INDEX prefix_hotpot_questions_name_idx ON prefix_hotpot_questions (SUBSTR("name",20));
83 83
 
84 84
 #
85 85
 # Table structure for table `hotpot_responses`
@@ -113,4 +113,4 @@ CREATE TABLE prefix_hotpot_strings (
113 113
 );
114 114
 COMMENT ON TABLE prefix_hotpot_strings IS 'strings used in Hot Potatoes questions and responses';
115 115
 
116  
-CREATE INDEX prefix_hotpot_strings_string_idx ON prefix_hotpot_strings (SUBSTR(string,20));
  116
+CREATE INDEX prefix_hotpot_strings_string_idx ON prefix_hotpot_strings (SUBSTR("string",20));
38  mod/hotpot/db/update_to_v2.php
... ...
@@ -1,4 +1,40 @@
1 1
 <?PHP
  2
+function hotpot_update_to_v2_1_21() {
  3
+    global $CFG;
  4
+    $ok = true;
  5
+
  6
+	if (strtolower($CFG->dbtype)=='postgres7') {
  7
+        // ensure setting of default values on certain fields
  8
+        // this was originally done in postgres7.php, but was found to be incompatible with PG7 :-(
  9
+        $table="hotpot";
  10
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'studentfeedbackurl', 'VARCHAR', 255, '',         'NOT NULL', '');
  11
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'studentfeedback',    'INTEGER', 4,   'UNSIGNED', 'NOT NULL', 0);
  12
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'clickreporting',     'INTEGER', 4,   'UNSIGNED', 'NOT NULL', 0);
  13
+
  14
+        $table="hotpot_attempts";
  15
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'score',     'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 0);
  16
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'penalties', 'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 0);
  17
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'status',    'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 1);
  18
+
  19
+        $table="hotpot_questions";
  20
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'type',      'INTEGER', 4, 'UNSIGNED', 'NOT NULL', 0);
  21
+
  22
+        $table="hotpot_responses";
  23
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'score',     'INTEGER', 4,   'UNSIGNED', 'NOT NULL', 0);
  24
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'weighting', 'INTEGER', 4,   'UNSIGNED', 'NOT NULL', 0);
  25
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'correct',   'VARCHAR', 255, '',         'NOT NULL', '');
  26
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'wrong',     'VARCHAR', 255, '',         'NOT NULL', '');
  27
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'ignored',   'VARCHAR', 255, '',         'NOT NULL', '');
  28
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'hints',     'INTEGER', 4,   'UNSIGNED', 'NOT NULL', 0);
  29
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'clues',     'INTEGER', 4,   'UNSIGNED', 'NOT NULL', 0);
  30
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'checks',    'INTEGER', 4,   'UNSIGNED', 'NOT NULL', 0);
  31
+
  32
+        $table="hotpot_strings";
  33
+        $ok = $ok && hotpot_db_update_field_type($table, '', 'string', 'TEXT', '', '', 'NOT NULL', '');
  34
+    }
  35
+
  36
+    return $ok;
  37
+}
2 38
 function hotpot_update_to_v2_1_18() {
3 39
 	$ok = true;
4 40
 
@@ -933,7 +969,7 @@ function hotpot_db_add_index($table, $field, $length='') {
933 969
 		break;
934 970
 		case 'postgres7' :
935 971
 			if ($length) {
936  
-				$field = "SUBSTR($field,$length)";
  972
+				$field = "SUBSTR(\"$field\",$length)";
937 973
 			}
938 974
 			$ok = $ok && $db->Execute("CREATE INDEX $index ON $table ($field)");
939 975
 		break;

0 notes on commit 9b2f93b

Please sign in to comment.
Something went wrong with that request. Please try again.