2014-07-25, 07:40 PM
The limit portion of the query needs to be removed from the following locations. Limits should not be used when doing update/deletes since the row being removed will always be ambiguous. In addition, this causes all kinds of issues with binary logging/replication in statement mode in MySQL since the slave or cloned database could be out of sync if different rows are removed. In each case, there should never be duplicates for the where clause anyway.
Here is an example of the error produced
inc/class_moderation.php, lines 2643-2644
inc/class_session.php, line 416
inc/class_session.php, line 461
inc/functions.php, line 849
inc/functions_archive.php, line 217
inc/functions_user.php, all 5 of these queries...
inc/datahandlers/login.php, both of these queries...
inc/tasks/massmail.php, 2 queries
admin/modules/forum/management.php, 2 queries...
admin/inc/functions.php, line 615
admin/inc/functions_themes.php, 3 queries
admin/index.php, 2 queries...
Here is an example of the error produced
Quote:[Warning] Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. The statement is unsafe because it uses a LIMIT clause. This is unsafe because the set of rows included cannot be predicted. Statement: UPDATE mybb_sessions
inc/class_moderation.php, lines 2643-2644
$db->update_query("threads", $new_subject, "tid='{$thread['tid']}'", 1);
$db->update_query("posts", $new_subject, "tid='{$thread['tid']}' AND replyto='0'", 1);
inc/class_session.php, line 416
$db->update_query("spiders", $updated_spider, "sid='{$spider_id}'", 1);
inc/class_session.php, line 461
$db->update_query("sessions", $onlinedata, "sid='{$sid}'", 1);
inc/functions.php, line 849
$db->update_query("sessions", $noperm_array, "sid='{$session->sid}'", 1);
inc/functions_archive.php, line 217
$db->update_query("sessions", $noperm_array, "sid='{$session->sid}'", 1);
inc/functions_user.php, all 5 of these queries...
104 - $db->update_query("users", $sql_array, "uid='".$user['uid']."'", 1);
113 - $db->update_query("users", $sql_array, "uid = ".$user['uid'], 1);
164 - $db->update_query("users", $newpassword, "uid='$uid'", 1);
217 - $db->update_query("users", $sql_array, "uid='{$uid}'", 1);
236 - $db->update_query("users", $sql_array, "uid='{$uid}'", 1);
inc/datahandlers/login.php, both of these queries...
181 - $db->update_query("users", $sql_array, "uid = '{$this->login_data['uid']}'", 1);
192 - $db->update_query("users", $sql_array, "uid = '{$this->login_data['uid']}'", 1);
inc/tasks/massmail.php, 2 queries
38 - $db->update_query("massemails", array('status' => 2), "mid='{$mass_email['mid']}'", 1);
146 - $db->update_query("massemails", $update_array, "mid='{$mass_email['mid']}'", 1);
admin/modules/forum/management.php, 2 queries...
1399 - $db->update_query("forums", array("parentlist" => make_parent_list($fid)), "fid='{$fid}'", 1);
1414 - $db->update_query("forums", array("parentlist" => make_parent_list($child['fid'])), "fid='{$child['fid']}'", 1);
admin/inc/functions.php, line 615
$db->update_query("adminoptions", array("loginlockoutexpiry" => TIME_NOW+((int)$mybb->settings['loginattemptstimeout']*60)), "uid='".(int)$uid."'", 1);
admin/inc/functions_themes.php, 3 queries
498 - $db->update_query("themestylesheets", array('cachefile' => $db->escape_string($stylesheet['name'])), "sid='{$stylesheet['sid']}'", 1);
511 - $db->update_query("themestylesheets", array('cachefile' => $db->escape_string($stylesheet['name'])), "sid='{$stylesheet['sid']}'", 1);
517 - $db->update_query("themestylesheets", array('lastmodified' => TIME_NOW), "sid='{$stylesheet['sid']}'", 1);
admin/index.php, 2 queries...
209 - $db->update_query("adminoptions", array("loginattempts" => 0, "loginlockoutexpiry" => 0), "uid='".(int)$mybb->user['uid']."'", 1);
272 - $db->update_query("adminoptions", array("loginattempts" => "loginattempts+1"), "uid='".(int)$login_user['uid']."'", 1, true);
283 - $db->update_query("adminoptions", array("loginlockoutexpiry" => TIME_NOW+((int)$mybb->settings['loginattemptstimeout']*60)), "uid='".(int)$login_user['uid']."'", 1);