Merge pull request #368 from diolektor/fixed-sql-remove-limit-for-update

Fixed SQL. Remove limit from update
This commit is contained in:
Yuriy Pikhtarev 2017-06-14 00:20:24 +03:00 committed by GitHub
commit 69348b2cc6
20 changed files with 31 additions and 31 deletions

View file

@ -92,7 +92,7 @@ if ($submit && $mode == 'user') {
bb_die('Could not update admin status'); bb_die('Could not update admin status');
} }
DB()->query('UPDATE ' . BB_USERS . ' SET user_level = ' . ADMIN . " WHERE user_id = $user_id LIMIT 1"); DB()->query('UPDATE ' . BB_USERS . ' SET user_level = ' . ADMIN . " WHERE user_id = $user_id");
// Delete any entries in auth_access, they are not required if user is becoming an admin // Delete any entries in auth_access, they are not required if user is becoming an admin
delete_permissions($group_id, $user_id); delete_permissions($group_id, $user_id);
@ -109,7 +109,7 @@ if ($submit && $mode == 'user') {
bb_die('Could not update admin status<br /><br />Could not change yourself from an admin to user'); bb_die('Could not update admin status<br /><br />Could not change yourself from an admin to user');
} }
// Update users level, reset to USER // Update users level, reset to USER
DB()->query('UPDATE ' . BB_USERS . ' SET user_level = ' . USER . " WHERE user_id = $user_id LIMIT 1"); DB()->query('UPDATE ' . BB_USERS . ' SET user_level = ' . USER . " WHERE user_id = $user_id");
delete_permissions($group_id, $user_id); delete_permissions($group_id, $user_id);

View file

@ -81,7 +81,7 @@ if ($user_list) {
send_pm($t_data['poster_id'], $subject, $message, BOT_UID); send_pm($t_data['poster_id'], $subject, $message, BOT_UID);
} }
DB()->query("UPDATE " . BB_BT_TORRENTS . " SET call_seed_time = " . TIMENOW . " WHERE topic_id = $topic_id LIMIT 1"); DB()->query("UPDATE " . BB_BT_TORRENTS . " SET call_seed_time = " . TIMENOW . " WHERE topic_id = $topic_id");
meta_refresh(TOPIC_URL . $topic_id); meta_refresh(TOPIC_URL . $topic_id);
bb_die($lang['CALLSEED_MSG_OK']); bb_die($lang['CALLSEED_MSG_OK']);

View file

@ -61,7 +61,7 @@ if ($is_moderator) {
bb_die(implode($upload->errors)); bb_die(implode($upload->errors));
} }
DB()->query("UPDATE " . BB_GROUPS . " SET avatar_ext_id = $avatar_ext_id WHERE group_id = $group_id LIMIT 1"); DB()->query("UPDATE " . BB_GROUPS . " SET avatar_ext_id = $avatar_ext_id WHERE group_id = $group_id");
} }
} }

View file

@ -50,7 +50,7 @@ switch ($mode) {
$this->ajax_die('Invalid mode'); $this->ajax_die('Invalid mode');
} }
DB()->query("UPDATE " . BB_USERS . " SET avatar_ext_id = $new_ext_id WHERE user_id = $user_id LIMIT 1"); DB()->query("UPDATE " . BB_USERS . " SET avatar_ext_id = $new_ext_id WHERE user_id = $user_id");
cache_rm_user_sessions($user_id); cache_rm_user_sessions($user_id);

View file

@ -84,7 +84,7 @@ switch ($mode) {
if (!IS_ADMIN) { if (!IS_ADMIN) {
$this->verify_mod_rights($tor['forum_id']); $this->verify_mod_rights($tor['forum_id']);
} }
DB()->query("UPDATE " . BB_TOPICS . " SET topic_status = " . TOPIC_UNLOCKED . " WHERE topic_id = {$tor['topic_id']} LIMIT 1"); DB()->query("UPDATE " . BB_TOPICS . " SET topic_status = " . TOPIC_UNLOCKED . " WHERE topic_id = {$tor['topic_id']}");
} else { } else {
$this->verify_mod_rights($tor['forum_id']); $this->verify_mod_rights($tor['forum_id']);
} }

View file

@ -46,7 +46,7 @@ foreach ($bf['user_opt'] as $opt_name => $opt_bit) {
} }
} }
DB()->query("UPDATE " . BB_USERS . " SET user_opt = {$u_data['user_opt']} WHERE user_id = $user_id LIMIT 1"); DB()->query("UPDATE " . BB_USERS . " SET user_opt = {$u_data['user_opt']} WHERE user_id = $user_id");
// Удаляем данные из кеша // Удаляем данные из кеша
cache_rm_user_sessions($user_id); cache_rm_user_sessions($user_id);

View file

@ -40,7 +40,7 @@ if ($rank_id != 0 && !isset($ranks[$rank_id])) {
$this->ajax_die("invalid rank_id: $rank_id"); $this->ajax_die("invalid rank_id: $rank_id");
} }
DB()->query("UPDATE " . BB_USERS . " SET user_rank = $rank_id WHERE user_id = $user_id LIMIT 1"); DB()->query("UPDATE " . BB_USERS . " SET user_rank = $rank_id WHERE user_id = $user_id");
cache_rm_user_sessions($user_id); cache_rm_user_sessions($user_id);

View file

@ -70,4 +70,4 @@ switch ($mode) {
} }
$value_sql = DB()->escape($value, true); $value_sql = DB()->escape($value, true);
DB()->query("UPDATE " . BB_GROUPS . " SET $mode = $value_sql WHERE group_id = $group_id LIMIT 1"); DB()->query("UPDATE " . BB_GROUPS . " SET $mode = $value_sql WHERE group_id = $group_id");

View file

@ -174,7 +174,7 @@ switch ($field) {
} }
$value_sql = DB()->escape($value, true); $value_sql = DB()->escape($value, true);
DB()->query("UPDATE $table SET $field = $value_sql WHERE user_id = $user_id LIMIT 1"); DB()->query("UPDATE $table SET $field = $value_sql WHERE user_id = $user_id");
cache_rm_user_sessions($user_id); cache_rm_user_sessions($user_id);

View file

@ -104,7 +104,7 @@ switch ($mode) {
} }
if ($tz != $bb_cfg['board_timezone']) { if ($tz != $bb_cfg['board_timezone']) {
// Set current user timezone // Set current user timezone
DB()->query("UPDATE " . BB_USERS . " SET user_timezone = $tz WHERE user_id = " . $userdata['user_id'] . " LIMIT 1"); DB()->query("UPDATE " . BB_USERS . " SET user_timezone = $tz WHERE user_id = " . $userdata['user_id']);
$bb_cfg['board_timezone'] = $tz; $bb_cfg['board_timezone'] = $tz;
cache_rm_user_sessions($userdata['user_id']); cache_rm_user_sessions($userdata['user_id']);
} }

View file

@ -69,7 +69,7 @@ switch ($mode) {
$topic_title_sql = DB()->escape($new_title); $topic_title_sql = DB()->escape($new_title);
DB()->query("UPDATE " . BB_TOPICS . " SET topic_title = '$topic_title_sql' WHERE topic_id = $topic_id LIMIT 1"); DB()->query("UPDATE " . BB_TOPICS . " SET topic_title = '$topic_title_sql' WHERE topic_id = $topic_id");
// Обновление кеша новостей на главной // Обновление кеша новостей на главной
$news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id'])); $news_forums = array_flip(explode(',', $bb_cfg['latest_news_forum_id']));

View file

@ -151,9 +151,9 @@ switch ($this->request['type']) {
$this->ajax_die(sprintf($lang['MAX_SMILIES_PER_POST'], $bb_cfg['max_smilies'])); $this->ajax_die(sprintf($lang['MAX_SMILIES_PER_POST'], $bb_cfg['max_smilies']));
} }
} }
DB()->query("UPDATE " . BB_POSTS_TEXT . " SET post_text = '" . DB()->escape($text) . "' WHERE post_id = $post_id LIMIT 1"); DB()->query("UPDATE " . BB_POSTS_TEXT . " SET post_text = '" . DB()->escape($text) . "' WHERE post_id = $post_id");
if ($post['topic_last_post_id'] != $post['post_id'] && $userdata['user_id'] == $post['poster_id']) { if ($post['topic_last_post_id'] != $post['post_id'] && $userdata['user_id'] == $post['poster_id']) {
DB()->query("UPDATE " . BB_POSTS . " SET post_edit_time = '" . TIMENOW . "', post_edit_count = post_edit_count + 1 WHERE post_id = $post_id LIMIT 1"); DB()->query("UPDATE " . BB_POSTS . " SET post_edit_time = '" . TIMENOW . "', post_edit_count = post_edit_count + 1 WHERE post_id = $post_id");
} }
$s_text = str_replace('\n', "\n", $text); $s_text = str_replace('\n', "\n", $text);
$s_topic_title = str_replace('\n', "\n", $post['topic_title']); $s_topic_title = str_replace('\n', "\n", $post['topic_title']);

View file

@ -131,7 +131,7 @@ switch ($mode) {
$new_tpl_id = $tpl_id; $new_tpl_id = $tpl_id;
$this->response['msg'] = "Включен шаблон $tpl_name"; $this->response['msg'] = "Включен шаблон $tpl_name";
} }
DB()->query("UPDATE " . BB_FORUMS . " SET forum_tpl_id = $new_tpl_id WHERE forum_id = $forum_id LIMIT 1"); DB()->query("UPDATE " . BB_FORUMS . " SET forum_tpl_id = $new_tpl_id WHERE forum_id = $forum_id");
break; break;
// сохранение изменений // сохранение изменений
@ -142,7 +142,7 @@ switch ($mode) {
$msg .= 'Шаблон был отредактирован: ' . html_entity_decode($last_edit_by_username) . ', ' . delta_time($tpl_data['tpl_last_edit_tm']) . " назад\n\n"; $msg .= 'Шаблон был отредактирован: ' . html_entity_decode($last_edit_by_username) . ', ' . delta_time($tpl_data['tpl_last_edit_tm']) . " назад\n\n";
$this->ajax_die($msg); $this->ajax_die($msg);
} }
$sql = "UPDATE " . BB_TOPIC_TPL . " SET " . DB()->build_array('UPDATE', $sql_args) . " WHERE tpl_id = $tpl_id LIMIT 1"; $sql = "UPDATE " . BB_TOPIC_TPL . " SET " . DB()->build_array('UPDATE', $sql_args) . " WHERE tpl_id = $tpl_id";
if (!@DB()->query($sql)) { if (!@DB()->query($sql)) {
$sql_error = DB()->sql_error(); $sql_error = DB()->sql_error();
} }

View file

@ -464,5 +464,5 @@ function get_parsed_post($postrow, $mode = 'full', $return_chars = 600)
function update_post_html($postrow) function update_post_html($postrow)
{ {
DB()->query("DELETE FROM " . BB_POSTS_HTML . " WHERE post_id = " . (int)$postrow['post_id'] . " LIMIT 1"); DB()->query("DELETE FROM " . BB_POSTS_HTML . " WHERE post_id = " . (int)$postrow['post_id']);
} }

View file

@ -159,7 +159,7 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_
if ($update_post_time && $mode == 'editpost' && $post_data['last_post'] && !$post_data['first_post']) { if ($update_post_time && $mode == 'editpost' && $post_data['last_post'] && !$post_data['first_post']) {
$edited_sql .= ", post_time = $current_time "; $edited_sql .= ", post_time = $current_time ";
//lpt //lpt
DB()->sql_query("UPDATE " . BB_TOPICS . " SET topic_last_post_time = $current_time WHERE topic_id = $topic_id LIMIT 1"); DB()->sql_query("UPDATE " . BB_TOPICS . " SET topic_last_post_time = $current_time WHERE topic_id = $topic_id");
} }
$sql = ($mode != "editpost") ? "INSERT INTO " . BB_POSTS . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip, poster_rg_id, attach_rg_sig) VALUES ($topic_id, $forum_id, " . $userdata['user_id'] . ", '$post_username', $current_time, '" . USER_IP . "', $poster_rg_id, $attach_rg_sig)" : "UPDATE " . BB_POSTS . " SET post_username = '$post_username'" . $edited_sql . ", poster_rg_id = $poster_rg_id, attach_rg_sig = $attach_rg_sig WHERE post_id = $post_id"; $sql = ($mode != "editpost") ? "INSERT INTO " . BB_POSTS . " (topic_id, forum_id, poster_id, post_username, post_time, poster_ip, poster_rg_id, attach_rg_sig) VALUES ($topic_id, $forum_id, " . $userdata['user_id'] . ", '$post_username', $current_time, '" . USER_IP . "', $poster_rg_id, $attach_rg_sig)" : "UPDATE " . BB_POSTS . " SET post_username = '$post_username'" . $edited_sql . ", poster_rg_id = $poster_rg_id, attach_rg_sig = $attach_rg_sig WHERE post_id = $post_id";

View file

@ -116,7 +116,7 @@ function tracker_unregister($attach_id, $mode = '')
// Unset DL-Type for topic // Unset DL-Type for topic
if ($bb_cfg['bt_unset_dltype_on_tor_unreg'] && $topic_id) { if ($bb_cfg['bt_unset_dltype_on_tor_unreg'] && $topic_id) {
$sql = "UPDATE " . BB_TOPICS . " SET topic_dl_type = " . TOPIC_DL_TYPE_NORMAL . " WHERE topic_id = $topic_id LIMIT 1"; $sql = "UPDATE " . BB_TOPICS . " SET topic_dl_type = " . TOPIC_DL_TYPE_NORMAL . " WHERE topic_id = $topic_id";
if (!$result = DB()->sql_query($sql)) { if (!$result = DB()->sql_query($sql)) {
bb_die('Could not update topics table #1'); bb_die('Could not update topics table #1');
@ -146,7 +146,7 @@ function tracker_unregister($attach_id, $mode = '')
} }
// Update tracker_status // Update tracker_status
$sql = "UPDATE " . BB_ATTACHMENTS_DESC . " SET tracker_status = 0 WHERE attach_id = $attach_id LIMIT 1"; $sql = "UPDATE " . BB_ATTACHMENTS_DESC . " SET tracker_status = 0 WHERE attach_id = $attach_id";
if (!DB()->sql_query($sql)) { if (!DB()->sql_query($sql)) {
bb_die('Could not update torrent status #1'); bb_die('Could not update torrent status #1');
@ -226,7 +226,7 @@ function change_tor_type($attach_id, $tor_status_gold)
$tor_status_gold = (int)$tor_status_gold; $tor_status_gold = (int)$tor_status_gold;
$info_hash = null; $info_hash = null;
DB()->query("UPDATE " . BB_BT_TORRENTS . " SET tor_type = $tor_status_gold WHERE topic_id = $topic_id LIMIT 1"); DB()->query("UPDATE " . BB_BT_TORRENTS . " SET tor_type = $tor_status_gold WHERE topic_id = $topic_id");
// Ocelot // Ocelot
if ($bb_cfg['ocelot']['enabled']) { if ($bb_cfg['ocelot']['enabled']) {
@ -356,7 +356,7 @@ function tracker_register($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVED
} }
// update tracker status for this attachment // update tracker status for this attachment
$sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . " SET tracker_status = 1 WHERE attach_id = $attach_id LIMIT 1"; $sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . " SET tracker_status = 1 WHERE attach_id = $attach_id";
if (!DB()->sql_query($sql)) { if (!DB()->sql_query($sql)) {
bb_die('Could not update torrent status #2'); bb_die('Could not update torrent status #2');
@ -364,7 +364,7 @@ function tracker_register($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVED
// set DL-Type for topic // set DL-Type for topic
if ($bb_cfg['bt_set_dltype_on_tor_reg']) { if ($bb_cfg['bt_set_dltype_on_tor_reg']) {
$sql = 'UPDATE ' . BB_TOPICS . ' SET topic_dl_type = ' . TOPIC_DL_TYPE_DL . " WHERE topic_id = $topic_id LIMIT 1"; $sql = 'UPDATE ' . BB_TOPICS . ' SET topic_dl_type = ' . TOPIC_DL_TYPE_DL . " WHERE topic_id = $topic_id";
if (!$result = DB()->sql_query($sql)) { if (!$result = DB()->sql_query($sql)) {
bb_die('Could not update topics table #2'); bb_die('Could not update topics table #2');
@ -372,7 +372,7 @@ function tracker_register($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVED
} }
if ($bb_cfg['tracker']['tor_topic_up']) { if ($bb_cfg['tracker']['tor_topic_up']) {
DB()->query("UPDATE " . BB_TOPICS . " SET topic_last_post_time = GREATEST(topic_last_post_time, " . (TIMENOW - 3 * 86400) . ") WHERE topic_id = $topic_id LIMIT 1"); DB()->query("UPDATE " . BB_TOPICS . " SET topic_last_post_time = GREATEST(topic_last_post_time, " . (TIMENOW - 3 * 86400) . ") WHERE topic_id = $topic_id");
} }
if ($reg_mode == 'request' || $reg_mode == 'newtopic') { if ($reg_mode == 'request' || $reg_mode == 'newtopic') {
@ -557,7 +557,7 @@ function generate_passkey($user_id, $force_generate = false)
return $passkey_val; return $passkey_val;
} }
// Update // Update
DB()->query("UPDATE IGNORE " . BB_BT_USERS . " SET auth_key = '$passkey_val' WHERE user_id = $user_id LIMIT 1"); DB()->query("UPDATE IGNORE " . BB_BT_USERS . " SET auth_key = '$passkey_val' WHERE user_id = $user_id");
if (DB()->affected_rows() == 1) { if (DB()->affected_rows() == 1) {
// Ocelot // Ocelot

View file

@ -65,7 +65,7 @@ if ($tpl_data) {
if ($tpl_data['tpl_rules_post_id']) { if ($tpl_data['tpl_rules_post_id']) {
if (!$tpl_rules_html = bbcode2html(DB()->fetch_row("SELECT post_text FROM " . BB_POSTS_TEXT . " WHERE post_id = " . $tpl_data['tpl_rules_post_id'], 'post_text'))) { if (!$tpl_rules_html = bbcode2html(DB()->fetch_row("SELECT post_text FROM " . BB_POSTS_TEXT . " WHERE post_id = " . $tpl_data['tpl_rules_post_id'], 'post_text'))) {
$tpl_data['tpl_rules_post_id'] = 0; $tpl_data['tpl_rules_post_id'] = 0;
DB()->query("UPDATE " . BB_TOPIC_TPL . " SET tpl_rules_post_id = 0 WHERE tpl_id = {$f_data['forum_tpl_id']} LIMIT 1"); DB()->query("UPDATE " . BB_TOPIC_TPL . " SET tpl_rules_post_id = 0 WHERE tpl_id = {$f_data['forum_tpl_id']}");
} }
} }

View file

@ -650,7 +650,7 @@ if ($submit && !$errors) {
$sql_args = DB()->build_array('UPDATE', $db_data); $sql_args = DB()->build_array('UPDATE', $db_data);
DB()->query("UPDATE " . BB_USERS . " SET $sql_args WHERE user_id = {$pr_data['user_id']} LIMIT 1"); DB()->query("UPDATE " . BB_USERS . " SET $sql_args WHERE user_id = {$pr_data['user_id']}");
if ($pr_data['user_id'] != $userdata['user_id']) { if ($pr_data['user_id'] != $userdata['user_id']) {
if ($pr_data['user_level'] == MOD && !empty($db_data['username'])) { if ($pr_data['user_level'] == MOD && !empty($db_data['username'])) {

View file

@ -109,7 +109,7 @@ switch ($mode) {
if (!$t_data['topic_vote']) { if (!$t_data['topic_vote']) {
bb_die($lang['POST_HAS_NO_POLL']); bb_die($lang['POST_HAS_NO_POLL']);
} }
DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 1 WHERE topic_id = $topic_id LIMIT 1"); DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 1 WHERE topic_id = $topic_id");
bb_die($lang['NEW_POLL_START']); bb_die($lang['NEW_POLL_START']);
break; break;
@ -118,7 +118,7 @@ switch ($mode) {
if (!$t_data['topic_vote']) { if (!$t_data['topic_vote']) {
bb_die($lang['POST_HAS_NO_POLL']); bb_die($lang['POST_HAS_NO_POLL']);
} }
DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = " . POLL_FINISHED . " WHERE topic_id = $topic_id LIMIT 1"); DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = " . POLL_FINISHED . " WHERE topic_id = $topic_id");
bb_die($lang['NEW_POLL_END']); bb_die($lang['NEW_POLL_END']);
break; break;

View file

@ -95,7 +95,7 @@ class Poll
DB()->query("REPLACE INTO " . BB_POLL_VOTES . $sql_args); DB()->query("REPLACE INTO " . BB_POLL_VOTES . $sql_args);
DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 1 WHERE topic_id = $topic_id LIMIT 1"); DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 1 WHERE topic_id = $topic_id");
} }
/** /**
@ -105,7 +105,7 @@ class Poll
*/ */
public function delete_poll($topic_id) public function delete_poll($topic_id)
{ {
DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 0 WHERE topic_id = $topic_id LIMIT 1"); DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 0 WHERE topic_id = $topic_id");
$this->delete_votes_data($topic_id); $this->delete_votes_data($topic_id);
} }