18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
(use sqlite3 srfi-1 posix regex regex-case srfi-69 csv-xml s11n md5 message-digest base64)
(import (prefix sqlite3 sqlite3:))
(import (prefix base64 base64:))
(declare (unit sdb))
;;
(define (sdb:open) ;; (conc *toppath* "/megatest.db") (car *configinfo*)))
(if (not *toppath*)
(if (not (setup-for-run))
(begin
(debug:print 0 "ERROR: Attempted to open db when not in megatest area. Exiting.")
(exit))))
(let* ((dbpath (conc *toppath* "/db/sdb.db")) ;; fname)
(dbexists (let ((fe (file-exists? dbpath)))
(if fe
fe
(begin
(create-directory (conc *toppath* "/db") #t)
#f))))
(sdb (sqlite3:open-database dbpath))
|
|
|
|
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
(use sqlite3 srfi-1 posix regex regex-case srfi-69 csv-xml s11n md5 message-digest base64)
(import (prefix sqlite3 sqlite3:))
(import (prefix base64 base64:))
(declare (unit sdb))
;;
(define (sdb:open #!key (fname #f)) ;; (conc *toppath* "/megatest.db") (car *configinfo*)))
(if (not *toppath*)
(if (not (setup-for-run))
(begin
(debug:print 0 "ERROR: Attempted to open db when not in megatest area. Exiting.")
(exit))))
(let* ((dbpath (conc *toppath* "/db/" (if fname fname "sdb.db"))) ;; fname)
(dbexists (let ((fe (file-exists? dbpath)))
(if fe
fe
(begin
(create-directory (conc *toppath* "/db") #t)
#f))))
(sdb (sqlite3:open-database dbpath))
|
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
(lambda (istr)
(set! str istr)
(hash-table-set! id-cache id str))
sdb
"SELECT str FROM strs WHERE id=?;" id))
str))
(define sdb:qry
(let ((sdb #f)
(scache (make-hash-table))
(icache (make-hash-table)))
(lambda (cmd var)
(if (not sdb)(set! sdb (sdb:open)))
(case cmd
((init) (if (not sdb)(set! sdb (sdb:open))))
((finalize!) (if sdb (sqlite3:finalize! sdb)))
((getid) (let ((id (sdb:string->id sdb scache var)))
(if id
id
(begin
(sdb:register-string sdb var)
(sdb:string->id sdb scache var)))))
((getstr) (if (or (number? var)
(string->number var))
(sdb:id->string sdb icache var)
var))
(else #f)))))
|
>
>
|
|
|
|
>
>
>
|
|
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
(lambda (istr)
(set! str istr)
(hash-table-set! id-cache id str))
sdb
"SELECT str FROM strs WHERE id=?;" id))
str))
;; Numbers get passed though in both directions
;;
(define (make-sdb:qry #!key (fname #f))
(let ((sdb (sdb:open fname: fname))
(scache (make-hash-table))
(icache (make-hash-table)))
(lambda (cmd var)
;; (if (not sdb)(set! sdb (sdb:open)))
(case cmd
;; ((init) (if (not sdb)(set! sdb (sdb:open))))
((finalize!) (if sdb (sqlite3:finalize! sdb)))
((getid) (let ((id (if (or (number? var)
(string->number var))
var
(sdb:string->id sdb scache var))))
(if id
id
(begin
(sdb:register-string sdb var)
(sdb:string->id sdb scache var)))))
((getstr) (if (or (number? var)
(string->number var))
(sdb:id->string sdb icache var)
var))
(else #f)))))
|