Index: db.scm ================================================================== --- db.scm +++ db.scm @@ -137,40 +137,10 @@ (define (db:setup do-sync) (assert *toppath* "FATAL: db:setup called before launch:setup has been run.") (dbfile:setup do-sync *toppath*)) -;; 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 (db:get-db subdb #;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)) - (let* ((dbname (db:run-id->dbname run-id)) - (newdb (db:open-megatest-db path: (db:dbfile-path) - name: dbname))) - ;; NOTE: pushing on the stack only happens AFTER the handle has been used - ;; (stack-push! (dbr:dbstruct-dbstack dbstruct) newdb) - newdb) - (stack-pop! (dbr:subdb-dbstack subdb))) - (db:open-db subdb run-id))) ;; ) - -(define-inline (db:generic-error-printout exn . message) - (print-call-chain (current-error-port)) - (apply debug:print-error 0 *default-log-port* message) - (debug:print-error 0 *default-log-port* " params: " params - ", error: " ((condition-property-accessor 'exn 'message) exn) - ", arguments: " ((condition-property-accessor 'exn 'arguments) exn) - ", location: " ((condition-property-accessor 'exn 'location) exn) - )) - ;; looks up subdb and returns it, if not found then set up ;; and then return it. ;; (define (db:get-subdb dbstruct run-id) (let* ((res (dbfile:get-subdb dbstruct run-id))) @@ -178,10 +148,42 @@ res (let* ((newsubdb (make-dbr:subdb))) (db:open-db newsubdb run-id areapath: (dbr:dbstruct-areapath dbstruct) do-sync: #t) (hash-table-set! (dbr:dbstruct-subdbs dbstruct) (dbfile:run-id->key run-id) newsubdb) newsubdb)))) + +;; 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 db:get-db db:get-subdb) + +;; (define (db:get-db subdb #;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)) +;; (let* ((dbname (db:run-id->dbname run-id)) +;; (newdb (db:open-megatest-db path: (db:dbfile-path) +;; name: dbname))) +;; ;; NOTE: pushing on the stack only happens AFTER the handle has been used +;; ;; (stack-push! (dbr:dbstruct-dbstack dbstruct) newdb) +;; newdb) +;; (stack-pop! (dbr:subdb-dbstack subdb))) +;; (db:open-db subdb run-id))) ;; ) + +(define-inline (db:generic-error-printout exn . message) + (print-call-chain (current-error-port)) + (apply debug:print-error 0 *default-log-port* message) + (debug:print-error 0 *default-log-port* " params: " params + ", error: " ((condition-property-accessor 'exn 'message) exn) + ", arguments: " ((condition-property-accessor 'exn 'arguments) exn) + ", location: " ((condition-property-accessor 'exn 'location) exn) + )) ;; (db:with-db dbstruct run-id sqlite3:exec "select blah fgrom blaz;") ;; r/w is a flag to indicate if the db is modified by this query #t = yes, #f = no ;; (define (db:with-db dbstruct run-id r/w proc . params)