Index: api.scm ================================================================== --- api.scm +++ api.scm @@ -65,12 +65,15 @@ ((get-steps-data) (apply db:get-steps-data dbstruct params)) ;; MISC ((login) (apply db:login dbstruct params)) ((general-call) (let ((stmtname (car params)) - (realparams (cdr params))) - (db:general-call dbstruct stmtname realparams))) + (run-id (cadr params)) + (realparams (cddr params))) + (db:with-db dbstruct run-id #t ;; these are all for modifying the db + (lambda (db) + (db:general-call db stmtname realparams))))) ((sync-inmem->db) (db:sync-back)) ((kill-server) (db:sync-tables (db:tbls *inmemdb*) *inmemdb* *db*) ;; (db:sync-to *inmemdb* *db*) (let ((hostname (car *runremote*)) (port (cadr *runremote*)) Index: dashboard.scm ================================================================== --- dashboard.scm +++ dashboard.scm @@ -1219,11 +1219,11 @@ (iup:attribute-set! obj "TITLE" (if *hide-not-hide* "HideTests" "NotHide")) (mark-for-update))))) (set! *hide-not-hide-button* hideit) hideit)) (iup:hbox - (iup:button "Quit" #:action (lambda (obj)(if *db* (sqlite3:finalize! *db*))(exit))) + (iup:button "Quit" #:action (lambda (obj)(if *db* (db:close-all *db*))(exit))) (iup:button "Refresh" #:action (lambda (obj) (mark-for-update))) (iup:button "Collapse" #:action (lambda (obj) (let ((myname (iup:attribute obj "TITLE"))) (if (equal? myname "Collapse") @@ -1490,11 +1490,11 @@ (let ((runid (string->number (args:get-arg "-run")))) (if runid (begin (lambda (x) (on-exit (lambda () - (if *db* (sqlite3:finalize! *db*)))) + (if *db* (db:close-all *db*)))) (examine-run *db* runid))) (begin (print "ERROR: runid is not a number " (args:get-arg "-run")) (exit 1))))) ((args:get-arg "-test") @@ -1525,6 +1525,6 @@ (set! *update-is-running* #f) (mutex-unlock! *update-mutex*)))) 1)))) (iup:main-loop) -(sqlite3:finalize! *db*) +(db:close-all *db*) Index: db.scm ================================================================== --- db.scm +++ db.scm @@ -121,11 +121,11 @@ (set! *db-write-access* #f)) ;; only unset so other db's also can use this control (if write-access (begin (sqlite3:set-busy-handler! db handler) (sqlite3:execute db "PRAGMA synchronous = 0;"))) - (if (not dbexists)(db:initialize-run-id-db db run-id)) + (if (not dbexists)(db:initialize-run-id-db db)) (dbr:dbstruct-set-runvec! dbstruct run-id 'rundb db) (dbr:dbstruct-set-runvec! dbstruct run-id 'inuse #t) (if local db (begin @@ -186,11 +186,11 @@ (hash-table-values (vector-ref dbstruct 1)))) (define (open-inmem-db) (let* ((db (sqlite3:open-database ":memory:")) (handler (make-busy-timeout 3600))) - (db:initialize db) + (db:initialize-run-id-db db) (sqlite3:set-busy-handler! db handler) (set! sdb:qry (make-sdb:qry)) ;; we open the normalization helpers here (set! *fdb* (filedb:open-db (conc *toppath* "/db/paths.db"))) db)) @@ -470,11 +470,11 @@ ;;====================================================================== ;; R U N S P E C I F I C D B ;;====================================================================== -(define (db:initialize-run-id-db db run-id) +(define (db:initialize-run-id-db db) (sqlite3:execute db "CREATE TABLE IF NOT EXISTS tests (id INTEGER PRIMARY KEY, run_id INTEGER DEFAULT -1, testname TEXT DEFAULT 'noname', host TEXT DEFAULT 'n/a', Index: db_records.scm ================================================================== --- db_records.scm +++ db_records.scm @@ -26,13 +26,13 @@ (define (dbr:dbstruct-get-rundb-rec vec run-id) (let* ((dbhash (vector-ref vec 1)) (runvec (hash-table-ref/default dbhash run-id #f))) (if runvec runvec - (begin - (hash-table-set! dbhash run-id (vector #f #f -1 -1 -1 #f)) - (dbr:dbstruct-get-rundb-rec vec run-id))))) + (let ((nvec (vector #f #f -1 -1 -1 #f))) + (hash-table-set! dbhash run-id nvec) + nvec)))) ;; [ rundb inmemdb last-mod last-read last-sync ] (define-inline (dbr:dbstruct-field-name->num field-name) (case field-name ((rundb) 0) ;; the on-disk db @@ -42,11 +42,11 @@ ((stime) 4) ;; last sync time ((inuse) 5) ;; is the db currently in use (else -1))) ;; get/set rundb fields -(define (dbr:dbstruct-get-runrec vec run-id field-name) +(define (dbr:dbstruct-get-runvec vec run-id field-name) (let ((runvec (dbr:dbstruct-get-rundb-rec vec run-id)) (fieldnum (dbr:dbstruct-field-name->num field-name))) ;; (vector-set! runvec (dbr:dbstruct-field-name->num 'inuse) #t) (vector-ref runvec fieldnum))) Index: http-transport.scm ================================================================== --- http-transport.scm +++ http-transport.scm @@ -431,11 +431,11 @@ (let ((start-time (current-milliseconds)) (sync-time #f) (rem-time #f)) (if *inmemdb* (db:sync-touched *inmemdb*)) (set! sync-time (- (current-milliseconds) start-time)) - (debug:print 0 "SYNC: time= " sync-time) + ;; (debug:print 0 "SYNC: time= " sync-time) (set! rem-time (quotient (- 4000 sync-time) 1000)) (if (and (< rem-time 4) (> rem-time 0)) (thread-sleep! rem-time))) Index: rmt.scm ================================================================== --- rmt.scm +++ rmt.scm @@ -81,12 +81,14 @@ (define (rmt:kill-server) (rmt:send-receive 'kill-server '())) ;; hand off a call to one of the db:queries statements -(define (rmt:general-call stmtname . params) - (rmt:send-receive 'general-call (append (list stmtname) params))) +;; added run-id to make looking up the correct db possible +;; +(define (rmt:general-call stmtname run-id . params) + (rmt:send-receive 'general-call (append (list stmtname run-id) params))) (define (rmt:sync-inmem->db) (rmt:send-receive 'sync-inmem->db '())) ;;====================================================================== ADDED tests/unittests/dbrdbstruct.scm Index: tests/unittests/dbrdbstruct.scm ================================================================== --- /dev/null +++ tests/unittests/dbrdbstruct.scm @@ -0,0 +1,21 @@ +;;====================================================================== +;; S E R V E R +;;====================================================================== + +;; Run like this: +;; +;; (cd ..;make && make install) && ./rununittest.sh server 1;(cd simplerun;megatest -stop-server 0) + +(test #f #t (vector? (make-dbr:dbstruct "/tmp"))) + +(define dbstruct (make-dbr:dbstruct "/tmp")) + +(test #f #t (begin (dbr:dbstruct-set-main! dbstruct "blah") #t)) +(test #f "blah" (dbr:dbstruct-get-main dbstruct)) +(test #f #t (vector? (dbr:dbstruct-get-rundb-rec dbstruct 1))) + +(for-each + (lambda (k) + (test #f #t (begin (dbr:dbstruct-set-runvec! dbstruct 1 k (conc k)) #t)) + (test #f k (dbr:dbstruct-get-runvec dbstruct 1 k))) + '(rundb inmem mtime rtime stime inuse))