Created
June 18, 2018 23:27
-
-
Save rwestphal/a3afbbe8432bceb4edfd4e99da049227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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