Megatest

Check-in [0e9ad025c4]
Login
Overview
Comment:Fixed dbfile:close-all and added tests
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | v1.7001-multi-db-rb01
Files: files | file ages | folders
SHA1: 0e9ad025c4cb6c591995f1ea976ef003f511beca
User & Date: mmgraham on 2022-04-05 21:33:51
Other Links: branch diff | manifest | tags
Context
2022-04-06
07:24
Fixed few issues in db.scm. NOTE: these might also be problems in v1.65 check-in: adfcb732f5 user: matt tags: v1.7001-multi-db-rb01
2022-04-05
21:33
Fixed dbfile:close-all and added tests check-in: 0e9ad025c4 user: mmgraham tags: v1.7001-multi-db-rb01
20:29
Lots of db adjustments made check-in: 162676ba8d user: matt tags: v1.7001-multi-db-rb01
Changes

Modified dbfile.scm from [1261c08c5d] to [95ef66d677].

90
91
92
93
94
95
96




97

98
99
100
101
102
103
104
90
91
92
93
94
95
96
97
98
99
100

101
102
103
104
105
106
107
108







+
+
+
+
-
+







	  (sqlite3:interrupt! db)
	  (db:safely-close-sqlite3-db db stmt-cache try-num: (- try-num 1)))
	(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)
            (begin
             (dbfile:print-err "db:safely-close-sqlite3-db: " db " is not an sqlite3 db")
	     #f
            )
	    #f))))
        ))))

;; close all opened run-id dbs
(define (db:close-all dbstruct)
  (if (dbr:dbstruct? dbstruct)
;; (handle-exceptions
;; 	  exn
;; 	  (begin
113
114
115
116
117
118
119

120

121
122

123





124
125
126
127
128
129
130
117
118
119
120
121
122
123
124

125
126

127

128
129
130
131
132
133
134
135
136
137
138
139







+
-
+

-
+
-
+
+
+
+
+







		    #;(rdb        (dbr:dbdat-dbh (dbr:subdb-refndb subdb))))
		    
	       (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 (dbr:dbdat-stmt-cache  (dbr:subdb-mtdbdat subdb))) 
	       (db:safely-close-sqlite3-db mtdbdat #f) ;; stmt-cache)     ;; (if (sqlite3:database? mdb) (sqlite3:finalize! mdb))
               ;; (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))
;; 	 (dbstruct (hash-table-ref/default dbstructs dbname #f)))
;;     (if dbstruct
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
273
274
275
276
277
278
279

280
281
282
283
284
285
286







-







	  (let* ((db (sqlite3:open-database dbpath)))
	    (sqlite3:set-busy-handler! db (sqlite3:make-busy-timeout 10000))
	    (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))))

(define (dbfile:print-and-exit . params)
  (with-output-to-port

Modified tests/simplerun/thebeginning.scm from [9beea9f91a] to [1e352e44dc].

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37





1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
19
20


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42






-
+













-
-
+
+















+
+
+
+
+
(use trace test (prefix sqlite3 sqlite3:))
(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
 ;; dbfile:get-subdb
 )

(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)))
(test #f #t (stack? (dbr:subdb-dbstack (dbfile:get-subdb dbstruct #f))))
(test #f '("SYSTEM" "RELEASE") (db:get-keys *dbstruct-dbs*))


(test #f #t (dbr:dbdat? (dbfile:open-db dbstruct 1 db:initialize-main-db)))
(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)))