diff options
author | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2021-04-02 15:22:21 +0200 |
---|---|---|
committer | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2021-04-02 15:48:02 +0200 |
commit | ea19cc844e780b29825b26aee321204be981a3ae (patch) | |
tree | 21b05007992bd5ebafd876dfe1ece62eda2a2aab /src/wallet/sqlite.cpp | |
parent | 9a3670930eaf6b495f81ef9c5f6e68883a3a2750 (diff) |
wallet: refactor: dedup sqlite statement deletions
Diffstat (limited to 'src/wallet/sqlite.cpp')
-rw-r--r-- | src/wallet/sqlite.cpp | 39 |
1 files changed, 15 insertions, 24 deletions
diff --git a/src/wallet/sqlite.cpp b/src/wallet/sqlite.cpp index f7aa576956..91891c5fc2 100644 --- a/src/wallet/sqlite.cpp +++ b/src/wallet/sqlite.cpp @@ -347,31 +347,22 @@ void SQLiteBatch::Close() } // Free all of the prepared statements - int ret = sqlite3_finalize(m_read_stmt); - if (ret != SQLITE_OK) { - LogPrintf("SQLiteBatch: Batch closed but could not finalize read statement: %s\n", sqlite3_errstr(ret)); - } - ret = sqlite3_finalize(m_insert_stmt); - if (ret != SQLITE_OK) { - LogPrintf("SQLiteBatch: Batch closed but could not finalize insert statement: %s\n", sqlite3_errstr(ret)); - } - ret = sqlite3_finalize(m_overwrite_stmt); - if (ret != SQLITE_OK) { - LogPrintf("SQLiteBatch: Batch closed but could not finalize overwrite statement: %s\n", sqlite3_errstr(ret)); - } - ret = sqlite3_finalize(m_delete_stmt); - if (ret != SQLITE_OK) { - LogPrintf("SQLiteBatch: Batch closed but could not finalize delete statement: %s\n", sqlite3_errstr(ret)); - } - ret = sqlite3_finalize(m_cursor_stmt); - if (ret != SQLITE_OK) { - LogPrintf("SQLiteBatch: Batch closed but could not finalize cursor statement: %s\n", sqlite3_errstr(ret)); + const std::vector<std::pair<sqlite3_stmt**, const char*>> statements{ + {&m_read_stmt, "read"}, + {&m_insert_stmt, "insert"}, + {&m_overwrite_stmt, "overwrite"}, + {&m_delete_stmt, "delete"}, + {&m_cursor_stmt, "cursor"}, + }; + + for (const auto& [stmt_prepared, stmt_description] : statements) { + int res = sqlite3_finalize(*stmt_prepared); + if (res != SQLITE_OK) { + LogPrintf("SQLiteBatch: Batch closed but could not finalize %s statement: %s\n", + stmt_description, sqlite3_errstr(res)); + } + *stmt_prepared = nullptr; } - m_read_stmt = nullptr; - m_insert_stmt = nullptr; - m_overwrite_stmt = nullptr; - m_delete_stmt = nullptr; - m_cursor_stmt = nullptr; } bool SQLiteBatch::ReadKey(CDataStream&& key, CDataStream& value) |