mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-25 08:21:24 +02:00
wallet: refactor: dedup sqlite statement deletions
This commit is contained in:
parent
9a3670930e
commit
ea19cc844e
@ -347,31 +347,22 @@ void SQLiteBatch::Close()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Free all of the prepared statements
|
// Free all of the prepared statements
|
||||||
int ret = sqlite3_finalize(m_read_stmt);
|
const std::vector<std::pair<sqlite3_stmt**, const char*>> statements{
|
||||||
if (ret != SQLITE_OK) {
|
{&m_read_stmt, "read"},
|
||||||
LogPrintf("SQLiteBatch: Batch closed but could not finalize read statement: %s\n", sqlite3_errstr(ret));
|
{&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));
|
||||||
}
|
}
|
||||||
ret = sqlite3_finalize(m_insert_stmt);
|
*stmt_prepared = nullptr;
|
||||||
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));
|
|
||||||
}
|
|
||||||
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)
|
bool SQLiteBatch::ReadKey(CDataStream&& key, CDataStream& value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user