@@ -82,21 +82,39 @@ #f) ;; Is there a cheaper single line operation that will check for existance of a table ;; and raise an exception ? (sqlite3:execute db "SELECT id FROM test_data LIMIT 1;")) db) - (begin + (let ((baddb (sqlite3:open-database ":memory:"))) (debug:print-info 11 "open-test-db END (unsucessful)" work-area) - #f))) + ;; provide an in-mem db (this is dangerous!) + (tdb:testdb-initialize baddb) + baddb))) ;; find and open the testdat.db file for an existing test (define (tdb:open-test-db-by-test-id test-id #!key (work-area #f)) (let* ((test-path (if work-area work-area (rmt:test-get-rundir-from-test-id test-id)))) (debug:print 3 "TEST PATH: " test-path) (open-test-db test-path))) + +;; find and open the testdat.db file for an existing test +(define (tdb:open-test-db-by-test-id-local test-id #!key (work-area #f)) + (let* ((test-path (if work-area + work-area + (open-run-close db:test-get-rundir-from-test-id #f test-id)))) + (debug:print 3 "TEST PATH: " test-path) + (open-test-db test-path))) + +;; find and open the testdat.db file for an existing test +(define (tdb:open-run-close-db-by-test-id-local test-id work-area proc . params) + (let* ((test-path (if work-area + work-area + (open-run-close db:test-get-rundir-from-test-id #f test-id))) + (tdb (open-test-db test-path))) + (apply proc tdb params))) (define (tdb:testdb-initialize db) (debug:print 11 "db:testdb-initialize START") (for-each (lambda (sqlcmd) @@ -167,11 +185,11 @@ ;; T E S T D A T A ;;====================================================================== (define (tdb:csv->test-data test-id csvdata #!key (work-area #f)) (debug:print 4 "test-id " test-id ", csvdata: " csvdata) - (let ((tdb (tdb:open-test-db-by-test-id test-id work-area: work-area))) + (let ((tdb (tdb:open-test-db-by-test-id-local test-id work-area: work-area))) (if (sqlite3:database? tdb) (let ((csvlist (csv->list (make-csv-reader (open-input-string csvdata) '((strip-leading-whitespace? #t) (strip-trailing-whitespace? #t)) )))) ;; (csv->list csvdata))) @@ -225,23 +243,23 @@ (sqlite3:execute tdb "INSERT OR REPLACE INTO test_data (test_id,category,variable,value,expected,tol,units,comment,status,type) VALUES (?,?,?,?,?,?,?,?,?,?);" test-id category variable value expected tol units (if comment comment "") status type))) csvlist) (sqlite3:finalize! tdb))))) -;; get a list of test_data records matching categorypatt -(define (tdb:read-test-data test-id categorypatt #!key (work-area #f)) - (let ((tdb (tdb:open-test-db-by-test-id test-id work-area: work-area))) - (if (sqlite3:database? tdb) - (let ((res '())) - (sqlite3:for-each-row - (lambda (id test_id category variable value expected tol units comment status type) - (set! res (cons (vector id test_id category variable value expected tol units comment status type) res))) - tdb - "SELECT id,test_id,category,variable,value,expected,tol,units,comment,status,type FROM test_data WHERE test_id=? AND category LIKE ? ORDER BY category,variable;" test-id categorypatt) - (sqlite3:finalize! tdb) - (reverse res)) - '()))) +;; ;; get a list of test_data records matching categorypatt +;; (define (tdb:read-test-data test-id categorypatt #!key (work-area #f)) +;; (let ((tdb (tdb:open-test-db-by-test-id test-id work-area: work-area))) +;; (if (sqlite3:database? tdb) +;; (let ((res '())) +;; (sqlite3:for-each-row +;; (lambda (id test_id category variable value expected tol units comment status type) +;; (set! res (cons (vector id test_id category variable value expected tol units comment status type) res))) +;; tdb +;; "SELECT id,test_id,category,variable,value,expected,tol,units,comment,status,type FROM test_data WHERE test_id=? AND category LIKE ? ORDER BY category,variable;" test-id categorypatt) +;; (sqlite3:finalize! tdb) +;; (reverse res)) +;; '()))) ;; NOTE: Run this local with #f for db !!! (define (tdb:load-test-data test-id #!key (work-area #f)) (let loop ((lin (read-line))) (if (not (eof-object? lin)) @@ -257,11 +275,11 @@ ;; Roll up test_data pass/fail results ;; look at the test_data status field, ;; if all are pass (any case) and the test status is PASS or NULL or '' then set test status to PASS. ;; if one or more are fail (any case) then set test status to PASS, non "pass" or "fail" are ignored (define (tdb:test-data-rollup test-id status #!key (work-area #f)) - (let ((tdb (tdb:open-test-db-by-test-id test-id work-area: work-area)) + (let ((tdb (tdb:open-test-db-by-test-id-local test-id work-area: work-area)) (fail-count 0) (pass-count 0)) (if (sqlite3:database? tdb) (begin (sqlite3:for-each-row @@ -311,11 +329,11 @@ (define (tdb:step-get-time-as-string vec) (seconds->time-string (tdb:step-get-event_time vec))) ;; db-get-test-steps-for-run (define (tdb:get-steps-for-test test-id #!key (work-area #f)) - (let* ((tdb (tdb:open-test-db-by-test-id test-id work-area: work-area)) + (let* ((tdb (tdb:open-test-db-by-test-id-local test-id work-area: work-area)) (res '())) (if (sqlite3:database? tdb) (handle-exceptions exn (begin @@ -480,11 +498,11 @@ #f)) (string