diff options
Diffstat (limited to 'src/discord/store.cpp')
-rw-r--r-- | src/discord/store.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/discord/store.cpp b/src/discord/store.cpp index 71fdfcc..f11206a 100644 --- a/src/discord/store.cpp +++ b/src/discord/store.cpp @@ -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; } |