Fix sql queries UPDATE for SQLite #10

This commit is contained in:
Visman 2021-12-23 16:35:15 +07:00
parent 2d71c280ca
commit efae0295e4
4 changed files with 24 additions and 31 deletions

View file

@ -54,26 +54,19 @@ class Merge extends Action
}
//???? перенести обработку в посты?
$vars = [
'start' => "[from]",
'end' => "[/from]\n",
'topics' => $ids,
];
$query = 'UPDATE ::posts AS p, ::topics as t
SET p.message=CONCAT(?s:start, t.subject, ?s:end, p.message)
WHERE p.topic_id IN (?ai:topics) AND t.id=p.topic_id';
$query = 'UPDATE ::posts
SET message=CONCAT(?s:prefix, message), topic_id=?i:new
WHERE topic_id=?i:id';
$this->c->DB->exec($query, $vars);
foreach ($otherTopics as $topic) {
$vars = [
':new' => $firstTopic->id,
':id' => $topic->id,
':prefix' => "[from]{$topic->subject}[/from]\n",
];
$vars = [
'id' => $firstTopic->id,
'topics' => $ids,
];
$query = 'UPDATE ::posts AS p
SET p.topic_id=?i:id
WHERE p.topic_id IN (?ai:topics)';
$this->c->DB->exec($query, $vars);
$this->c->DB->exec($query, $vars);
}
// добавить перенос подписок на первую тему?

View file

@ -71,9 +71,9 @@ class ChangeGroup extends Action
':new' => $newGroupId,
':ids' => $ids,
];
$query = 'UPDATE ::users AS u
SET u.group_id = ?i:new
WHERE u.id IN (?ai:ids)';
$query = 'UPDATE ::users
SET group_id = ?i:new
WHERE id IN (?ai:ids)';
$this->c->DB->exec($query, $vars);

View file

@ -38,22 +38,22 @@ class UpdateCountPosts extends Action
unset($ids[0]); // ????
if (empty($ids)) {
$where = 'u.id > 0';
$where = '::users.id > 0';
$vars = [];
} else {
$where = 'u.id IN (?ai:ids)';
$where = '::users.id IN (?ai:ids)';
$vars = [
':ids' => \array_keys($ids),
];
}
$query = 'UPDATE ::users AS u
SET u.num_posts = COALESCE((
$query = 'UPDATE ::users
SET num_posts = COALESCE((
SELECT COUNT(p.id)
FROM ::posts AS p
INNER JOIN ::topics AS t ON t.id=p.topic_id
INNER JOIN ::forums AS f ON f.id=t.forum_id
WHERE p.poster_id=u.id AND f.no_sum_mess=0
WHERE p.poster_id=::users.id AND f.no_sum_mess=0
GROUP BY p.poster_id
), 0)
WHERE ' . $where;

View file

@ -38,21 +38,21 @@ class UpdateCountTopics extends Action
unset($ids[0]); // ????
if (empty($ids)) {
$where = 'u.id > 0';
$where = '::users.id > 0';
$vars = [];
} else {
$where = 'u.id IN (?ai:ids)';
$where = '::users.id IN (?ai:ids)';
$vars = [
':ids' => \array_keys($ids),
];
}
$query = 'UPDATE ::users AS u
SET u.num_topics = COALESCE((
$query = 'UPDATE ::users
SET num_topics = COALESCE((
SELECT COUNT(t.id)
FROM ::topics AS t
INNER JOIN ::posts AS p ON t.first_post_id=p.id
WHERE p.poster_id=u.id AND t.moved_to=0
WHERE p.poster_id=::users.id AND t.moved_to=0
GROUP BY p.poster_id
), 0)
WHERE ' . $where;