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