Index: dbfile.scm ================================================================== --- dbfile.scm +++ dbfile.scm @@ -92,11 +92,15 @@ (if (sqlite3:database? db) (let* ((stmts (and stmt-cache (hash-table-ref/default stmt-cache db #f)))) (if stmts (map sqlite3:finalize! (hash-table-values stmts))) (sqlite3:finalize! db) #t) - #f)))) + (begin + (dbfile:print-err "db:safely-close-sqlite3-db: " db " is not an sqlite3 db") + #f + ) + )))) ;; close all opened run-id dbs (define (db:close-all dbstruct) (if (dbr:dbstruct? dbstruct) ;; (handle-exceptions @@ -115,14 +119,19 @@ (map (lambda (dbdat) (let* ((stmt-cache (dbr:dbdat-stmt-cache dbdat)) (dbh (dbr:dbdat-dbh dbdat))) (db:safely-close-sqlite3-db dbh stmt-cache))) tdbs) - (db:safely-close-sqlite3-db mtdbdat #f) ;; stmt-cache) ;; (if (sqlite3:database? mdb) (sqlite3:finalize! mdb)) + (db:safely-close-sqlite3-db mtdbdat (dbr:dbdat-stmt-cache (dbr:subdb-mtdbdat subdb))) + ;; (if (sqlite3:database? mdb) (sqlite3:finalize! mdb)) #;(db:safely-close-sqlite3-db rdb #f))) ;; stmt-cache))))) ;; (if (sqlite3:database? rdb) (sqlite3:finalize! rdb)))))) - subdbs)))) -;; ) + subdbs) + #t + ) + #f + ) +) ;; ;; set up a single db (e.g. main.db, 1.db ... etc.) ;; ;; ;; (define (db:setup-db dbstruct areapath run-id) ;; (let* ((dbname (db:run-id->dbname run-id)) @@ -266,11 +275,10 @@ (init-proc db)) #;(dbfile:lock-create-open dbpath (lambda (db) (init-proc db)))) (write-access (file-write-access? dbpath))) - (dbfile:print-err "db:open-sqlite-db "dbpath " db: " db) #;(if (and dbexists (not write-access)) (set! *db-write-access* #f)) ;; (cons db dbpath))) (make-dbr:dbdat dbfile: dbpath dbh: db read-only: (not write-access)))) Index: tests/simplerun/thebeginning.scm ================================================================== --- tests/simplerun/thebeginning.scm +++ tests/simplerun/thebeginning.scm @@ -2,11 +2,11 @@ (import dbfile) (trace-call-sites #t) (trace ;; dbfile:setup - dbfile:open-sqlite3-db + ;; dbfile:open-sqlite3-db ;; dbfile:init-subdb ;; dbfile:add-dbdat ;; db:initialize-main-db ;; dbfile:set-subdb ;; db:with-db @@ -16,12 +16,12 @@ (define tmpdir (common:get-db-tmp-area)) (test #f #t (dbr:dbstruct? (dbfile:setup #t *toppath* tmpdir))) (test #f #t (dbr:dbstruct? (db:setup #t))) (define dbstruct *dbstruct-dbs*) (test #f #t (dbr:dbdat? (dbfile:open-db *dbstruct-dbs* #f db:initialize-main-db))) -(define mydbdat (dbfile:open-db *dbstruct-dbs* #f db:initialize-main-db)) -(dbfile:add-dbdat dbstruct #f mydbdat) +(define maindbdat (dbfile:open-db *dbstruct-dbs* #f db:initialize-main-db)) +(dbfile:add-dbdat dbstruct #f maindbdat) (test #f #t (dbr:subdb? (dbfile:get-subdb dbstruct #f))) (test #f #t (dbr:dbdat? (dbfile:get-dbdat dbstruct #f))) (test #f #f (dbr:dbdat? (dbfile:get-dbdat dbstruct #f))) ;; stack empty so should fail. (test #f #t (hash-table? (dbr:dbstruct-subdbs dbstruct))) @@ -33,5 +33,10 @@ (define rundbdat (dbfile:open-db dbstruct 1 db:initialize-main-db)) (dbfile:add-dbdat dbstruct 1 rundbdat) (test #f #t (dbr:subdb? (dbfile:get-subdb dbstruct 1))) (test #f #t (dbr:dbdat? (dbfile:get-dbdat dbstruct 1))) +(test #f #t (db:close-all dbstruct)) + +(test #f #t (db:safely-close-sqlite3-db (dbr:dbdat-dbh rundbdat) (dbr:dbdat-stmt-cache rundbdat))) +(test #f #t (db:safely-close-sqlite3-db (dbr:dbdat-dbh maindbdat) (dbr:dbdat-stmt-cache maindbdat))) +