diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2022-05-19 03:13:02 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2022-05-19 03:13:02 -0400 |
commit | ffc69576f2832d705a1b1f8ef35d534029b5f1ca (patch) | |
tree | 9e66cab91f071f5071a5278e03ab4fb26c8180fc /src/discord/store.cpp | |
parent | 2bed7f161b47c63370147318d0fa90b778667bc5 (diff) | |
download | abaddon-portaudio-ffc69576f2832d705a1b1f8ef35d534029b5f1ca.tar.gz abaddon-portaudio-ffc69576f2832d705a1b1f8ef35d534029b5f1ca.zip |
fix role updates (fixes #69, fixes #70)
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; } |