Permalink
Browse files

Fix "data truncated errors" by setting set NULL values in int field t…

…o 0 before changing to NOT NULL DEFAULT 0
  • Loading branch information...
1 parent a42ca12 commit 530cd21dc2f96e058a395b645bd4202fb712df37 gbateson committed Apr 27, 2006
Showing with 38 additions and 24 deletions.
  1. +5 −23 mod/hotpot/db/mysql.php
  2. +32 −0 mod/hotpot/db/update_to_v2.php
  3. +1 −1 mod/hotpot/version.php
View
@@ -27,32 +27,14 @@ function hotpot_upgrade($oldversion) {
$ok = $ok && hotpot_update_to_v2_1_16();
}
-
- if ($oldversion < 2006042600) {
- table_column('hotpot_attempts','starttime','starttime','int','10','unsigned','0','not null');
- table_column('hotpot_attempts','endtime','endtime','int','10','unsigned','0','not null');
- table_column('hotpot_attempts','score','score','int','6','unsigned','0','not null');
- table_column('hotpot_attempts','penalties','penalties','int','6','unsigned','0','not null');
- table_column('hotpot_attempts','timestart','timestart','int','10','unsigned','0','not null');
- table_column('hotpot_attempts','timefinish','timefinish','int','10','unsigned','0','not null');
- table_column('hotpot_attempts','clickreportid','clickreportid','int','10','unsigned','0','not null');
-
- execute_sql("ALTER TABLE {$CFG->prefix}hotpot_questions CHANGE type type tinyint(4) unsigned NOT NULL default '0'");
-
- table_column('hotpot_questions','text','text','int','10','unsigned','0','not null');
-
-
- execute_sql("ALTER TABLE {$CFG->prefix}hotpot_responses CHANGE weighting weighting smallint(8) unsigned NOT NULL default '0'");
- execute_sql("ALTER TABLE {$CFG->prefix}hotpot_responses CHANGE score score smallint(8) unsigned NOT NULL default '0'");
- execute_sql("ALTER TABLE {$CFG->prefix}hotpot_responses CHANGE hints hints smallint(6) unsigned NOT NULL default '0'");
- execute_sql("ALTER TABLE {$CFG->prefix}hotpot_responses CHANGE clues clues smallint(6) unsigned NOT NULL default '0'");
- execute_sql("ALTER TABLE {$CFG->prefix}hotpot_responses CHANGE checks checks smallint(6) unsigned NOT NULL default '0'");
-
- }
+ // update to HotPot v2.1.17
+ if ($oldversion < 2006042601) {
+ $ok = $ok && hotpot_get_update_to_v2();
+ $ok = $ok && hotpot_update_to_v2_1_17();
+ }
return $ok;
}
-
function hotpot_get_update_to_v2() {
global $CFG;
$filepath = "$CFG->dirroot/mod/hotpot/db/update_to_v2.php";
@@ -1,4 +1,36 @@
<?PHP
+function hotpot_update_to_v2_1_17() {
+ global $CFG;
+ $ok = true;
+
+ $ok = $ok && hotpot_denull_int_field('hotpot_attempts', 'starttime', '10');
+ $ok = $ok && hotpot_denull_int_field('hotpot_attempts', 'endtime', '10');
+ $ok = $ok && hotpot_denull_int_field('hotpot_attempts', 'score', '6');
+ $ok = $ok && hotpot_denull_int_field('hotpot_attempts', 'penalties', '6');
+ $ok = $ok && hotpot_denull_int_field('hotpot_attempts', 'timestart', '10');
+ $ok = $ok && hotpot_denull_int_field('hotpot_attempts', 'timefinish', '10');
+ $ok = $ok && hotpot_denull_int_field('hotpot_attempts', 'clickreportid', '10');
+
+ $ok = $ok && hotpot_denull_int_field('hotpot_questions', 'type', '4');
+ $ok = $ok && hotpot_denull_int_field('hotpot_questions', 'text', '10');
+
+ $ok = $ok && hotpot_denull_int_field('hotpot_responses', 'weighting', '8');
+ $ok = $ok && hotpot_denull_int_field('hotpot_responses', 'score', '8');
+ $ok = $ok && hotpot_denull_int_field('hotpot_responses', 'hints', '6');
+ $ok = $ok && hotpot_denull_int_field('hotpot_responses', 'clues', '6');
+ $ok = $ok && hotpot_denull_int_field('hotpot_responses', 'checks', '6');
+
+ return $ok;
+}
+function hotpot_denull_int_field($table, $field, $size) {
+ global $CFG;
+ $ok = true;
+
+ $ok = $ok && execute_sql("UPDATE {$CFG->prefix}$table SET $field=0 WHERE $field IS NULL");
+ $ok = $ok && hotpot_db_update_field_type($table, $field, $field, 'INTEGER', $size, 'UNSIGNED', 'NOT NULL', 0);
+
+ return $ok;
+}
function hotpot_update_to_v2_1_16() {
global $CFG;
$ok = true;
View
@@ -3,7 +3,7 @@
/// Code fragment to define the version of hotpot
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
-$module->version = 2006042600; // release date of this version (see note below)
+$module->version = 2006042601; // release date of this version (see note below)
$module->release = 'v2.1.16'; // human-friendly version name (used in mod/hotpot/lib.php)
$module->cron = 0; // period for cron to check this module (secs)
// interpretation of YYYYMMDDXY version numbers

0 comments on commit 530cd21

Please sign in to comment.