153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
+
+
+
+
-
+
-
+
|
(define (db:run-id->dbname run-id)
(cond
((number? run-id) (conc ".db/" (modulo run-id 100) ".db"))
((not run-id) (conc ".db/main.db"))
(else run-id)))
(define (dbfile:get-subdb dbstruct run-id)
(let* ((dbfname (db:run-id->dbname run-id)))
(hash-table-ref/default (dbr:dbstruct-subdbs dbstruct) dbfname #f)))
;; Get/open a database
;; if run-id => get run specific db
;; if #f => get main db
;; if run-id is a string treat it as a filename
;; if db already open - return inmem
;; if db not open, open inmem, rundb and sync then return inmem
;; inuse gets set automatically for rundb's
;;
(define (dbfile:get-dbh dbstruct run-id) ;; RENAME TO db:get-dbh
(let* ((subdb (dbfile:get-subdb dbstruct run-id)))
(if (stack? (dbr:subdb-dbstack subdb))
(if (stack-empty? (dbr:subdb-dbstack subdb))
#f
(stack-pop! (dbr:subdb-dbstack subdb)))
#f)))
(define (dbfile:add-dbh dbstruct run-id db)
(define (dbfile:add-dbh dbstruct run-id dbh)
(let* ((subdb (dbfile:get-subdb dbstruct run-id)))
(if (not (stack? (dbr:subdb-dbstack subdb)))
(dbr:subdb-dbstack-set! subdb (make-stack)))
(stack-push! (dbr:subdb-dbstack subdb) dbh)))
)
|