Skip to content

Commit 6636a26

Browse files
committed
Implement SQLiteBatch::Close
1 parent 9382535 commit 6636a26

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/wallet/sqlite.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ SQLiteBatch::SQLiteBatch(SQLiteDatabase& database)
182182

183183
void SQLiteBatch::Close()
184184
{
185+
// If m_db is in a transaction (i.e. not in autocommit mode), then abort the transaction in progress
186+
if (m_database.m_db && sqlite3_get_autocommit(m_database.m_db) == 0) {
187+
if (TxnAbort()) {
188+
LogPrintf("SQLiteBatch: Batch closed unexpectedly without the transaction being explicitly committed or aborted\n");
189+
} else {
190+
LogPrintf("SQLiteBatch: Batch closed and failed to abort transaction\n");
191+
}
192+
}
185193
}
186194

187195
bool SQLiteBatch::ReadKey(CDataStream&& key, CDataStream& value)

0 commit comments

Comments
 (0)