[db] wrap db_purge_cruft in a transaction

This commit is contained in:
chme 2016-12-27 21:31:01 +01:00
parent cf7787dbc2
commit be6b4376e8

View File

@ -734,12 +734,15 @@ db_purge_cruft(time_t ref)
"DELETE FROM files WHERE -1 <> %d AND db_timestamp < %" PRIi64 ";",
};
db_transaction_begin();
for (i = 0; i < (sizeof(queries_tmpl) / sizeof(queries_tmpl[0])); i++)
{
query = sqlite3_mprintf(queries_tmpl[i], PL_SPECIAL, (int64_t)ref);
if (!query)
{
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
db_transaction_end();
return;
}
@ -754,6 +757,7 @@ db_purge_cruft(time_t ref)
if (!query)
{
DPRINTF(E_LOG, L_DB, "Out of memory for query string\n");
db_transaction_end();
return;
}
@ -763,6 +767,8 @@ db_purge_cruft(time_t ref)
if (ret == 0)
DPRINTF(E_DBG, L_DB, "Purged %d rows\n", sqlite3_changes(hdl));
db_transaction_end();
#undef Q_TMPL
}