From 7a00aa4976d0d3d57eccb89e3dee4ee388369cea Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 16 Apr 2015 00:01:06 -0700 Subject: [PATCH] web: changes to support MySQL strict mode In "strict mode", inserts fail if they don't supply values for columns with no default defined in the schema (in non-strict mode, 0 and '' are implicit defaults). Starting with MySQL version 5.6, strict mode is the default. This breaks some of the BOINC web code, which does inserts without giving values to some columns. There are two ways to solve this: 1) change the schema to give defaults everywhere 2) change the PHP code to supply values for more columns. I'm using 1) in some cases and 2) in others. This commit fixes some of the errors; there are others. --- db/schema.sql | 18 +++++++++--------- html/inc/forum_db.inc | 2 +- html/inc/user.inc | 2 +- html/ops/db_update.php | 15 +++++++++++++++ 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/db/schema.sql b/db/schema.sql index 9a38801680..cc4dbcb37b 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -443,18 +443,18 @@ create table forum ( orderID integer not null, title varchar(254) not null, description varchar(254) not null, - timestamp integer not null, + timestamp integer not null default 0, -- time of last new or modified thread or post - threads integer not null, + threads integer not null default 0, -- number of non-hidden threads in forum - posts integer not null, - rate_min_expavg_credit integer not null, - rate_min_total_credit integer not null, - post_min_interval integer not null, - post_min_expavg_credit integer not null, - post_min_total_credit integer not null, + posts integer not null default 0, + rate_min_expavg_credit integer not null default 0, + rate_min_total_credit integer not null default 0, + post_min_interval integer not null default 0, + post_min_expavg_credit integer not null default 0, + post_min_total_credit integer not null default 0, is_dev_blog tinyint not null default 0, - parent_type integer not null, + parent_type integer not null default 0, -- entity type to which this forum is attached: -- 0 == category (public) -- 1 == team diff --git a/html/inc/forum_db.inc b/html/inc/forum_db.inc index 98bebb3dd4..84887630c6 100644 --- a/html/inc/forum_db.inc +++ b/html/inc/forum_db.inc @@ -150,7 +150,7 @@ class BoincForumPrefs { } else { $prefs = self::lookup_userid($user->id); if (!$prefs) { - self::insert("(userid, thread_sorting, pm_notification) values ($user->id, 8, 0)"); + self::insert("(userid, last_post, forum_sorting, thread_sorting, rated_posts, ignorelist, pm_notification) values ($user->id, 0, 0, 8, '', '', 0)"); $prefs = self::lookup_userid($user->id); $prefs->userid = $user->id; $prefs->thread_sorting = 6; diff --git a/html/inc/user.inc b/html/inc/user.inc index ca5d23fa8a..b1aa02039f 100644 --- a/html/inc/user.inc +++ b/html/inc/user.inc @@ -559,7 +559,7 @@ function make_user( $country = BoincDb::escape_string($country); $postal_code = sanitize_tags(BoincDb::escape_string($postal_code)); - $uid = BoincUser::insert("(create_time, email_addr, name, authenticator, country, postal_code, total_credit, expavg_credit, expavg_time, project_prefs, teamid, send_email, show_hosts, cross_project_id, passwd_hash) values($now, '$email_addr', '$name', '$authenticator', '$country', '$postal_code', 0, 0, unix_timestamp(), '$project_prefs', $teamid, 1, 1, '$cross_project_id', '$passwd_hash')"); + $uid = BoincUser::insert("(create_time, email_addr, name, authenticator, country, postal_code, total_credit, expavg_credit, expavg_time, project_prefs, teamid, venue, send_email, show_hosts, posts, seti_id, seti_nresults, seti_last_result_time, seti_total_cpu, has_profile, cross_project_id, passwd_hash, email_validated, donated) values($now, '$email_addr', '$name', '$authenticator', '$country', '$postal_code', 0, 0, unix_timestamp(), '$project_prefs', $teamid, '', 1, 1, 0, 0, 0, 0, 0, 0, '$cross_project_id', '$passwd_hash', 0, 0)"); if (!$uid) { return null; diff --git a/html/ops/db_update.php b/html/ops/db_update.php index 9a5ef352b3..7f12e1118f 100644 --- a/html/ops/db_update.php +++ b/html/ops/db_update.php @@ -975,6 +975,20 @@ function update_10_8_2014() { do_query("alter table user_submit_app add primary key(user_id, app_id)"); } +function update_4_15_2015() { + do_query("alter table forum + alter timestamp set default 0, + alter threads set default 0, + alter posts set default 0, + alter rate_min_expavg_credit set default 0, + alter rate_min_total_credit set default 0, + alter post_min_interval set default 0, + alter post_min_expavg_credit set default 0, + alter post_min_total_credit set default 0, + alter parent_type set default 0 + "); +} + // Updates are done automatically if you use "upgrade". // // If you need to do updates manually, @@ -1019,6 +1033,7 @@ $db_updates = array ( array(27010, "update_6_5_2014"), array(27011, "update_8_15_2014"), array(27012, "update_10_8_2014"), + array(27013, "update_4_15_2015"), ); ?>