Megatest

Diff
Login

Differences From Artifact [fad48edea3]:

To Artifact [d9c8f8574a]:


1640
1641
1642
1643
1644
1645
1646




















































1647
1648
1649
1650
1651
1652
1653
		    qryvals)
	     (sqlite3:execute db "UPDATE runs SET state=?,status=?,event_time=strftime('%s','now') WHERE id=? AND state='deleted';" state status res)
	     res))) 
	(begin
	  (debug:print-error 0 *default-log-port* "Called without all necessary keys")
	  #f))))





















































;; replace header and keystr with a call to runs:get-std-run-fields
;;
;; keypatts: ( (KEY1 "abc%def")(KEY2 "%") )
;; runpatts: patt1,patt2 ...
;;
(define (db:get-runs dbstruct runpatt count offset keypatts)
  (let* ((res       '())







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
		    qryvals)
	     (sqlite3:execute db "UPDATE runs SET state=?,status=?,event_time=strftime('%s','now') WHERE id=? AND state='deleted';" state status res)
	     res))) 
	(begin
	  (debug:print-error 0 *default-log-port* "Called without all necessary keys")
	  #f))))

(define (db:get-run-id dbstruct runname target)
  (let ((runs (db:simple-get-runs dbstruct runname #f #f target #f))) ;; runpatt count offset target last-update
    (if (null? runs)
	#f
	(simple-run-id (car runs)))))

(define (db:insert-run dbstruct target runname run-meta)
  (let* ((keys    (db:get-keys dbstruct)))
    (if (null? runs)
	;; need to insert run based on target and runname
	(let* ((targvals (string-split target "/"))
	       (keystr   (string-intersperse keys ","))
	       (key?str  (string-intersperse (make-list (length targvals) "?") ","))
	       (qrystr   (conc "INSERT INTO runs (runname,"keystr") VALUES (?,"key?str")"))
	       (get-var  (lambda (db qrystr)
			   (let* ((res #f))
			     (sqlite3:for-each-row
			      (lambda row
				(set res (car row)))
			      db qrystr)
			     res))))
	  (db:create-initial-run-record dbstruct runname target)
    	  (let* ((run-id (db:get-run-id dbstruct runname target)))
	    (for-each
	     (lambda (keyval)
	       (let* ((fieldname (car keyval))
		      (getqry    (conc "SELECT "fieldname" FROM runs WHERE id=?;"))
		      (setqry    (conc "UPDATE runs SET "fieldname"=? WHERE id=?;"))
		      (val       (cdr keyval))
		      (valnum    (if (number? val)
				     val
				     (if (string? val)
					 (string->number val)
					 #f))))
		 (if (not (member fieldname (cons "runname" keys))) ;; don't attempt to tweak these
		     (let* ((curr-val (get-var db getqry))
			    (have-it  (or (equal? curr-val val)
					  (equal? curr-val valnum))))
		       (if (not have-it)
			   (sqlite3:execute db setqry (or valnum val) run-id))))))
	     run-meta))))))
  
(define (db:create-initial-run-record dbstruct runname target)	  
  (let* ((targvals (string-split target "/"))
	 (keystr   (string-intersperse keys ","))
	 (key?str  (string-intersperse (make-list (length targvals) "?") ","))
	 (qrystr   (conc "INSERT INTO runs (runname,"keystr") VALUES (?,"key?str")")))
    (db:with-db
     dbstruct #f #f
     (lambda (dbdat db)
       (apply sqlite3:execute db qrystr runname targvals)))))

;; replace header and keystr with a call to runs:get-std-run-fields
;;
;; keypatts: ( (KEY1 "abc%def")(KEY2 "%") )
;; runpatts: patt1,patt2 ...
;;
(define (db:get-runs dbstruct runpatt count offset keypatts)
  (let* ((res       '())
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696


1697
1698
1699
1700
1701
1702
1703
		     (set! res (cons (apply vector a x) res)))
		   db
		   qrystr
		   )))
    (debug:print-info 11 *default-log-port* "db:get-runs END qrystr: " qrystr " keypatts: " keypatts " offset: " offset " limit: " count)
    (vector header res)))


(define-record simple-run target id runname state status owner event_time)
(define-record-printer (simple-run x out)
  (fprintf out "#,(simple-run ~S ~S ~S ~S)"
	   (simple-run-target x) (simple-run-id x) (simple-run-runname x) (time->string (seconds->local-time (simple-run-event_time x) ))))

;; simple get-runs


;;
(define (db:simple-get-runs dbstruct runpatt count offset target last-update)
    (let* ((res       '())
	   (keys       (db:get-keys dbstruct))
	   (runpattstr (db:patt->like "runname" runpatt))
	   (remfields  (list "id" "runname" "state" "status" "owner" "event_time"))
	   (targstr    (string-intersperse keys "||'/'||"))







<
<
<
<
<
<

>
>







1735
1736
1737
1738
1739
1740
1741






1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
		     (set! res (cons (apply vector a x) res)))
		   db
		   qrystr
		   )))
    (debug:print-info 11 *default-log-port* "db:get-runs END qrystr: " qrystr " keypatts: " keypatts " offset: " offset " limit: " count)
    (vector header res)))







;; simple get-runs
;;
;;  records used defined in dbfile
;;
(define (db:simple-get-runs dbstruct runpatt count offset target last-update)
    (let* ((res       '())
	   (keys       (db:get-keys dbstruct))
	   (runpattstr (db:patt->like "runname" runpatt))
	   (remfields  (list "id" "runname" "state" "status" "owner" "event_time"))
	   (targstr    (string-intersperse keys "||'/'||"))