From 79add84ecc776f5424e97e74b828c75fc5488c75 Mon Sep 17 00:00:00 2001 From: Gent Semaj Date: Sun, 7 Dec 2025 13:47:29 -0800 Subject: [PATCH] Work around orphaned email attachments --- src/db/email.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/db/email.cpp b/src/db/email.cpp index 297b766..7eb8153 100644 --- a/src/db/email.cpp +++ b/src/db/email.cpp @@ -329,12 +329,23 @@ bool Database::sendEmail(EmailData* data, std::vector attachments, Pl sqlite3_bind_int(stmt, 7, item.iTimeLimit); if (sqlite3_step(stmt) != SQLITE_DONE) { - std::cout << "[WARN] Database: Failed to send email: " << sqlite3_errmsg(db) << std::endl; - sqlite3_exec(db, "ROLLBACK TRANSACTION;", NULL, NULL, NULL); - sqlite3_finalize(stmt); - return false; + // very likely the UNIQUE constraint failing due to + // orphaned attachments from an old email. + // try deleting them first + _deleteEmailAttachments(data->PlayerId, data->MsgIndex, -1); + + // try again + sqlite3_reset(stmt); + if (sqlite3_step(stmt) != SQLITE_DONE) { + // different error, give up + std::cout << "[WARN] Database: Failed to send email: " << sqlite3_errmsg(db) << std::endl; + sqlite3_exec(db, "ROLLBACK TRANSACTION;", NULL, NULL, NULL); + sqlite3_finalize(stmt); + return false; + } } sqlite3_reset(stmt); + sqlite3_clear_bindings(stmt); } sqlite3_finalize(stmt);