@@ -347,31 +347,22 @@ void SQLiteBatch::Close()
347
347
}
348
348
349
349
// Free all of the prepared statements
350
- int ret = sqlite3_finalize (m_read_stmt);
351
- if (ret != SQLITE_OK) {
352
- LogPrintf (" SQLiteBatch: Batch closed but could not finalize read statement: %s\n " , sqlite3_errstr (ret));
353
- }
354
- ret = sqlite3_finalize (m_insert_stmt);
355
- if (ret != SQLITE_OK) {
356
- LogPrintf (" SQLiteBatch: Batch closed but could not finalize insert statement: %s\n " , sqlite3_errstr (ret));
357
- }
358
- ret = sqlite3_finalize (m_overwrite_stmt);
359
- if (ret != SQLITE_OK) {
360
- LogPrintf (" SQLiteBatch: Batch closed but could not finalize overwrite statement: %s\n " , sqlite3_errstr (ret));
361
- }
362
- ret = sqlite3_finalize (m_delete_stmt);
363
- if (ret != SQLITE_OK) {
364
- LogPrintf (" SQLiteBatch: Batch closed but could not finalize delete statement: %s\n " , sqlite3_errstr (ret));
365
- }
366
- ret = sqlite3_finalize (m_cursor_stmt);
367
- if (ret != SQLITE_OK) {
368
- LogPrintf (" SQLiteBatch: Batch closed but could not finalize cursor statement: %s\n " , sqlite3_errstr (ret));
350
+ const std::vector<std::pair<sqlite3_stmt**, const char *>> statements{
351
+ {&m_read_stmt, " read" },
352
+ {&m_insert_stmt, " insert" },
353
+ {&m_overwrite_stmt, " overwrite" },
354
+ {&m_delete_stmt, " delete" },
355
+ {&m_cursor_stmt, " cursor" },
356
+ };
357
+
358
+ for (const auto & [stmt_prepared, stmt_description] : statements) {
359
+ int res = sqlite3_finalize (*stmt_prepared);
360
+ if (res != SQLITE_OK) {
361
+ LogPrintf (" SQLiteBatch: Batch closed but could not finalize %s statement: %s\n " ,
362
+ stmt_description, sqlite3_errstr (res));
363
+ }
364
+ *stmt_prepared = nullptr ;
369
365
}
370
- m_read_stmt = nullptr ;
371
- m_insert_stmt = nullptr ;
372
- m_overwrite_stmt = nullptr ;
373
- m_delete_stmt = nullptr ;
374
- m_cursor_stmt = nullptr ;
375
366
}
376
367
377
368
bool SQLiteBatch::ReadKey (CDataStream&& key, CDataStream& value)
0 commit comments