[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]

From: Ludovic Courtès
Date: Thu, 25 Jan 2018 04:42:07 -0500 (EST)

branch: master
commit c4963deca159ba11a4dba54e2026bbb4b1ceea51
Author: Ludovic Courtès <address@hidden>
Date:   Thu Jan 25 10:38:19 2018 +0100

    database: Turn 'sqlite-exec' into a macro.
    * src/cuirass/database.scm (%sqlite-exec): New procedure.
    (sqlite-exec): New macro.
 src/cuirass/database.scm | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index 539aa31..f0dc4ad 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -53,11 +53,8 @@
             ;; Macros.
-(define (sqlite-exec db msg . args)
-  "Wrap 'sqlite-prepare', 'sqlite-step', and 'sqlite-finalize'. Send message
-MSG to database DB.  MSG and ARGS are passed to 'format'."
-  (let* ((sql  (apply format #f msg args))
-         (stmt (sqlite-prepare db sql))
+(define (%sqlite-exec db sql)
+  (let* ((stmt (sqlite-prepare db sql))
          (res  (let loop ((res '()))
                  (let ((row (sqlite-step stmt)))
                    (if (not row)
@@ -66,6 +63,19 @@ MSG to database DB.  MSG and ARGS are passed to 'format'."
     (sqlite-finalize stmt)
+(define-syntax sqlite-exec
+  ;; Note: Making it a macro so -Wformat can do its job.
+  (lambda (s)
+    "Wrap 'sqlite-prepare', 'sqlite-step', and 'sqlite-finalize'.  Send to 
+SQL statement to DB.  FMT and ARGS are passed to 'format'."
+    (syntax-case s ()
+      ((_ db fmt args ...)
+       #'(%sqlite-exec db (format #f fmt args ...)))
+      (id
+       (identifier? #'id)
+       #'(lambda (db fmt . args)
+           (%sqlite-exec db (apply format #f fmt args)))))))
 (define %package-database
   ;; Define to the database file name of this package.
   (make-parameter (string-append %localstatedir "/run/" %package

reply via email to

[Prev in Thread] Current Thread [Next in Thread]