diff options
author | Mathieu Lirzin <mthl@gnu.org> | 2016-07-21 18:43:07 +0200 |
---|---|---|
committer | Mathieu Lirzin <mthl@gnu.org> | 2016-07-25 02:12:40 +0200 |
commit | 18e42be3029af2aa655fc7819caf0cc23b8ba9f2 (patch) | |
tree | d05105049ceb410d924821d55c37601553c82414 | |
parent | adc624c75a579677f35da60a7a01a2a988898e73 (diff) | |
download | cuirass-18e42be3029af2aa655fc7819caf0cc23b8ba9f2.tar cuirass-18e42be3029af2aa655fc7819caf0cc23b8ba9f2.tar.gz |
database: Use 'simple-format' in 'sqlite-exec'.
-rw-r--r-- | src/cuirass/database.scm | 24 |
1 files 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))) |