Skip to content

Instantly share code, notes, and snippets.

@rwestphal
Created June 18, 2018 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwestphal/a3afbbe8432bceb4edfd4e99da049227 to your computer and use it in GitHub Desktop.
Save rwestphal/a3afbbe8432bceb4edfd4e99da049227 to your computer and use it in GitHub Desktop.
int nb_db_set_max_transactions(unsigned int max)
{
#ifdef HAVE_CONFIG_ROLLBACKS
int ret;
/*
* Delete old entries if necessary and update the SQL trigger that
* auto-deletes old entries.
*/
ret = db_execute(
" \
BEGIN TRANSACTION; \
DELETE FROM TRANSACTIONS WHERE ROWID IN (SELECT ROWID FROM \
TRANSACTIONS ORDER BY ROWID DESC LIMIT -1 OFFSET %u); \
DROP TRIGGER delete_tail; \
CREATE TRIGGER delete_tail AFTER INSERT ON TRANSACTIONS \
FOR EACH ROW \
BEGIN \
DELETE FROM TRANSACTIONS WHERE ID%%%u=NEW.ID%%%u AND ID!=NEW.ID;\
END; \
COMMIT;",
max, max, max);
if (ret != 0)
return NB_ERR;
#endif /* HAVE_CONFIG_ROLLBACKS */
return NB_OK;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment