diff options
author | Mathieu Lirzin <mthl@gnu.org> | 2016-07-22 12:35:09 +0200 |
---|---|---|
committer | Mathieu Lirzin <mthl@gnu.org> | 2016-07-25 02:12:40 +0200 |
commit | b1dd669196b01ac2dcd7accd052b28b536b85e08 (patch) | |
tree | 77b4146135f389fe90671286f18c05415daea837 | |
parent | 18e42be3029af2aa655fc7819caf0cc23b8ba9f2 (diff) | |
download | cuirass-b1dd669196b01ac2dcd7accd052b28b536b85e08.tar cuirass-b1dd669196b01ac2dcd7accd052b28b536b85e08.tar.gz |
database: sqlite-exec: Return every rows.
Export it. Add a test.
-rw-r--r-- | src/cuirass/database.scm | 12 | ||||
-rw-r--r-- | tests/database.scm | 10 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm index 5a5b61b..8ce4153 100644 --- a/src/cuirass/database.scm +++ b/src/cuirass/database.scm @@ -29,6 +29,7 @@ db-delete-evaluation db-add-build-log read-sql-file + sqlite-exec ;; Parameters. %package-database ;; Macros. @@ -39,9 +40,14 @@ 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))) + (stmt (sqlite-prepare db sql)) + (res (let loop ((res '())) + (let ((row (sqlite-step stmt))) + (if (not row) + (reverse! res) + (loop (cons row res))))))) + (sqlite-finalize stmt) + res)) (define %package-database ;; Define to the database file name of this package. diff --git a/tests/database.scm b/tests/database.scm index eb75363..75431e9 100644 --- a/tests/database.scm +++ b/tests/database.scm @@ -42,6 +42,16 @@ (test-assert "db-init" (%db (db-init))) + (test-assert "sqlite-exec" + (begin + (sqlite-exec (%db) "\ +INSERT INTO build (job_spec, drv) VALUES ('job1', 'drv1');") + (sqlite-exec (%db) "\ +INSERT INTO build (job_spec, drv) VALUES ('job2', 'drv2');") + (sqlite-exec (%db) "\ +INSERT INTO build (job_spec, drv) VALUES ('job3', 'drv3');") + (sqlite-exec (%db) "SELECT * FROM build;"))) + (test-assert "db-add-evaluation" (%id (db-add-evaluation (%db) (make-dummy-job)))) |