[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: database: Fix SQL file reading.
From: |
Mathieu Othacehe |
Subject: |
branch master updated: database: Fix SQL file reading. |
Date: |
Fri, 30 Apr 2021 03:31:26 -0400 |
This is an automated email from the git hooks/post-receive script.
mothacehe pushed a commit to branch master
in repository guix-cuirass.
The following commit(s) were added to refs/heads/master by this push:
new aa3c57b database: Fix SQL file reading.
aa3c57b is described below
commit aa3c57b56b42355bd946aad1506cd550036e3999
Author: Mathieu Othacehe <othacehe@gnu.org>
AuthorDate: Fri Apr 30 09:29:25 2021 +0200
database: Fix SQL file reading.
* src/cuirass/database.scm (read-sql-file): Return the given SQL file as a
single string.
(db-load): Adapt it.
---
src/cuirass/database.scm | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/src/cuirass/database.scm b/src/cuirass/database.scm
index 8193690..4f4fd98 100644
--- a/src/cuirass/database.scm
+++ b/src/cuirass/database.scm
@@ -36,6 +36,7 @@
#:use-module (ice-9 ftw)
#:use-module (ice-9 rdelim)
#:use-module (ice-9 regex)
+ #:use-module (ice-9 textual-ports)
#:use-module (ice-9 threads)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-19)
@@ -293,16 +294,8 @@ DB is bound to the argument of that critical section: the
database connection."
(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
- (lambda (port)
- (let loop ((insts '()))
- (let ((inst (read-delimited ";" port 'concat)))
- (if (or (eof-object? inst)
- ;; Don't cons the spaces after the last instructions.
- (string-every char-whitespace? inst))
- (reverse! insts)
- (loop (cons inst insts))))))))
+ "Return a string containing SQL instructions from FILE-NAME."
+ (call-with-input-file file-name get-string-all))
(define (expect-one-row rows)
"Several SQL queries expect one result, or zero if not found. This gets rid
@@ -313,8 +306,7 @@ of the list, and returns #f when there is no result."
(define (db-load db schema)
"Evaluate the file SCHEMA, which may contain SQL queries, into DB."
- (for-each (cut exec-query db <>)
- (read-sql-file schema)))
+ (exec-query db (read-sql-file schema)))
(define (db-schema-version db)
(catch 'psql-query-error
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: database: Fix SQL file reading.,
Mathieu Othacehe <=