aboutsummaryrefslogtreecommitdiff
path: root/gn/db
diff options
context:
space:
mode:
Diffstat (limited to 'gn/db')
-rw-r--r--gn/db/mysql.scm15
1 files changed, 11 insertions, 4 deletions
diff --git a/gn/db/mysql.scm b/gn/db/mysql.scm
index fb7093a..760e578 100644
--- a/gn/db/mysql.scm
+++ b/gn/db/mysql.scm
@@ -18,7 +18,8 @@
get-row
get-rows
get-rows-apply
- check
+ has-result?
+ ensure
;db-open
;db-query
;db-get-row
@@ -36,7 +37,7 @@
(define (call-with-db thunk)
(thunk (db-open)))
-(define (check db)
+(define (ensure db)
"Use DBI-style handle to report an error. On error the program will stop."
(match (dbi-get_status db)
((stat . msg) (if (= stat 0)
@@ -46,15 +47,21 @@
(newline)
(assert stat))))))
+(define (has-result? db)
+ "Return #t or #f if result is valid"
+ (match (dbi-get_status db)
+ ((stat . msg) (= stat 0))))
+
(define (get-row db)
+ "Return record and #f is it was the last one"
(dbi-get_row db))
(define (get-rows db list)
"After running dbi-query we can fetch all rows and return them as a list of records, which is an alist:
(dbi-query db \"SELECT StrainId,Strain.Name FROM Strain, StrainXRef WHERE StrainXRef.StrainId = Strain.Id AND StrainXRef.InbredSetId = 1 ORDER BY StrainId;\")
- (db-check db)
- (display (db-get-rows db '()))
+ (ensure db)
+ (display (get-rows db '()))
(((StrainId . 4) (Name . BXD1)) ((StrainId . 5) (Name . BXD2))...
"