fix role updates (fixes #69, fixes #70)

This commit is contained in:
ouwou
2022-05-19 03:13:02 -04:00
parent 2bed7f161b
commit ffc69576f2
3 changed files with 33 additions and 12 deletions

View File

@@ -1078,6 +1078,14 @@ void Store::ClearRecipient(Snowflake channel_id, Snowflake user_id) {
s->Reset();
}
void Store::ClearRole(Snowflake id) {
auto &s = m_stmt_clr_role;
s->Bind(1, id);
s->Step();
s->Reset();
}
std::unordered_set<Snowflake> Store::GetChannels() const {
auto &s = m_stmt_get_chan_ids;
std::unordered_set<Snowflake> r;
@@ -1522,6 +1530,16 @@ bool Store::CreateTables() {
return false;
}
if (m_db.Execute(R"(
CREATE TRIGGER remove_deleted_roles AFTER DELETE ON roles
BEGIN
DELETE FROM member_roles WHERE role = old.id;
END
)") != SQLITE_OK) {
fprintf(stderr, "failed to create roles trigger: %s\n", m_db.ErrStr());
return false;
}
return true;
}
@@ -2159,6 +2177,17 @@ bool Store::CreateStatements() {
return false;
}
m_stmt_clr_role = std::make_unique<Statement>(m_db, R"(
DELETE FROM roles
WHERE id = ?1;
DELETE FROM member_roles
WHERE role = ?1;
)");
if (!m_stmt_clr_role->OK()) {
fprintf(stderr, "failed to prepare clear role statement: %s\n", m_db.ErrStr());
return false;
}
return true;
}