From 18e42be3029af2aa655fc7819caf0cc23b8ba9f2 Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Thu, 21 Jul 2016 18:43:07 +0200 Subject: database: Use 'simple-format' in 'sqlite-exec'. --- src/cuirass/database.scm | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm index 361584e..5a5b61b 100644 --- a/src/cuirass/database.scm +++ b/src/cuirass/database.scm @@ -34,9 +34,12 @@ ;; Macros. with-database)) -(define (sqlite-exec db sql) - "Wrap 'sqlite-prepare', 'sqlite-step', and 'sqlite-finalize'." - (let ((stmt (sqlite-prepare db sql))) +(define (sqlite-exec db msg . args) + "Wrap 'sqlite-prepare', 'sqlite-step', and 'sqlite-finalize'. Send message +MSG to database DB. MSG can contain '~A' and '~S' escape characters which +will be replaced by ARGS." + (let* ((sql (apply simple-format #f msg args)) + (stmt (sqlite-prepare db sql))) (sqlite-step stmt) (sqlite-finalize stmt))) @@ -86,11 +89,9 @@ database object." (define (db-add-evaluation db job) "Store a derivation result in database DB and return its ID." - (sqlite-exec - db - (format #f "insert into build (job_spec, drv) values ('~A', '~A');" - (assq-ref job #:job-name) - (assq-ref job #:derivation))) + (sqlite-exec db "insert into build (job_spec, drv) values ('~A', '~A');" + (assq-ref job #:job-name) + (assq-ref job #:derivation)) (let* ((stmt (sqlite-prepare db "select last_insert_rowid() from build;")) (res (sqlite-step stmt))) (sqlite-finalize stmt) @@ -107,8 +108,7 @@ database object." (define (db-delete-evaluation db id) "Delete a job in database DB which corresponds to ID." - (sqlite-exec db - (format #f "delete from build where id=~A;" id))) + (sqlite-exec db "delete from build where id=~A;" id)) (define-syntax-rule (with-database db body ...) "Run BODY with a connection to the database which is bound to DB in BODY." @@ -135,6 +135,4 @@ string." (seek log 0 SEEK_SET) (read-quoted-string log)) (else #f)))) - (sqlite-exec db - (format #f "update build set log='~A' where id=~A;" - log* id)))) + (sqlite-exec db "update build set log='~A' where id=~A;" log* id))) -- cgit v1.2.3