From f5287dc11ed091bf4b9d1d34d9f5404704aa3b2d Mon Sep 17 00:00:00 2001 From: Mathieu Othacehe Date: Wed, 3 Mar 2021 08:39:02 +0100 Subject: [PATCH] Add with-transaction. * src/cuirass/database.scm (with-transaction): New macro. --- .dir-locals.el | 1 + src/cuirass/database.scm | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.dir-locals.el b/.dir-locals.el index b0223cc..45731c6 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -13,6 +13,7 @@ (eval put 'test-error 'scheme-indent-function 1) (eval put 'make-parameter 'scheme-indent-function 1) (eval put 'with-database 'scheme-indent-function 0) + (eval put 'with-transaction 'scheme-indent-function 0) (texinfo-mode (indent-tabs-mode) (fill-column . 72) diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm index 1d309ce..cc4ff5a 100644 --- a/src/cuirass/database.scm +++ b/src/cuirass/database.scm @@ -107,7 +107,8 @@ ;; Macros. exec-query/bind with-database - with-db-worker-thread)) + with-db-worker-thread + with-transaction)) ;; Maximum priority for a Build or Specification. (define max-priority 9) @@ -273,6 +274,13 @@ DB is bound to the argument of that critical section: the database connection." (number->string receive-timeout) caller-name)))))) +(define-syntax-rule (with-transaction exp ...) + "Evalute EXP within an SQL transaction." + (with-db-worker-thread db + (exec-query db "BEGIN TRANSACTION;") + exp ... + (exec-query db "COMMIT;"))) + (define (read-sql-file file-name) "Return a list of string containing SQL instructions from FILE-NAME." (call-with-input-file file-name