Random Bits of Open Code

Check-in [7e6abd32c5]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added get-runs-info
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:7e6abd32c5ffaa8b303052d1f8cd02f97347ad4c
User & Date: matt 2018-04-30 06:03:14
Context
2018-05-01
07:36
Capture area-ids into adat structs check-in: 7ac36960b6 user: matt tags: trunk
2018-04-30
06:03
Added get-runs-info check-in: 7e6abd32c5 user: matt tags: trunk
05:22
Partial fix/implementation of rget check-in: b8baf172bd user: matt tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to mtutils/mtdb/mtdb.scm.

60
61
62
63
64
65
66

67
68
69
70
71
72
73
...
499
500
501
502
503
504
505











506
507
508
509
510
511
512
...
814
815
816
817
818
819
820



821
822
823
824
825
826
827
....
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
     sync-tests-data
     sync-test-steps
     sync-test-gen-data
     init-cached-info
     
     ;; runs
     get-run-info

     insert-run
     get-run-name-from-id

     ;; tests
     get-test-info-by-id
     get-test-id
     
................................................................................
   ttype-id target run-name state status owner event-time comment fail-count pass-count area-id))

(define (get-run-name-from-id dbh run-id)
  (dbi:get-one
   dbh
   "SELECT runname FROM runs WHERE id=?;"
   run-id))












;;======================================================================
;;  T E S T - S T E P S
;;======================================================================

(define (get-test-step-id dbh test-id stepname state)
  (dbi:get-one
................................................................................
		"SELECT DISTINCT target FROM runs WHERE target LIKE ? AND ttype_id=?;" target-patt tt-id))
	 ))
     ttypes)))

(define (get-targets-of-type dbh ttype-id target-patt)
  (dbi:get-rows dbh "SELECT DISTINCT target FROM runs WHERE target LIKE ? AND ttype_id=?;" target-patt ttype-id))




(define (get-runs-by-target dbh targets run-patt)
  (dbi:get-rows dbh "SELECT r.run_name, t.test_name, t.status, t.item_path, t.id, t.rundir, t.final_logf FROM runs as r INNER JOIN tests AS t ON t.run_id=r.id  
                          WHERE t.state='COMPLETED' AND r.target like ? AND  r.run_name like ?;" targets run-patt)
  )

(define (get-test-by-id dbh id)
  (dbi:get-rows dbh "SELECT t.test_name, t.item_path, t.rundir, t.final_logf FROM runs as r INNER JOIN tests AS t ON t.run_id=r.id  
................................................................................
;;
(define (get-changed-record-ids adat since-time)
  (print "get-changed-record-ids called with since-time=" since-time)
  (with-megatest-db
   adat
   (lambda (db)
     (let ((backcons (lambda (lst item)(cons item lst)))
	   (conscar  (lambda (row lst)(cons (car row) lst))))
       `((runs       . ,(dbi:fold-row conscar '() db "SELECT id FROM runs  WHERE last_update>?;" since-time))
	 (tests      . ,(dbi:fold-row conscar '() db "SELECT id FROM tests WHERE last_update>?;" since-time))
	 (test_steps . ,(dbi:fold-row conscar '() db "SELECT id FROM test_steps WHERE last_update>?;" since-time))
	 (test_data  . ,(dbi:fold-row conscar '() db "SELECT id FROM test_data  WHERE last_update>?;" since-time))
	 (run_stats  . ,(dbi:fold-row conscar '() db "SELECT id FROM run_stats  WHERE last_update>?;" since-time))	
	 ;; (test_meta  . ,(fold-row backcons '() db "SELECT id FROM test_meta  WHERE last_update>?" since-time))
	 )))))







>







 







>
>
>
>
>
>
>
>
>
>
>







 







>
>
>







 







|







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
...
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
...
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
....
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
     sync-tests-data
     sync-test-steps
     sync-test-gen-data
     init-cached-info
     
     ;; runs
     get-run-info
     get-runs-info
     insert-run
     get-run-name-from-id

     ;; tests
     get-test-info-by-id
     get-test-id
     
................................................................................
   ttype-id target run-name state status owner event-time comment fail-count pass-count area-id))

(define (get-run-name-from-id dbh run-id)
  (dbi:get-one
   dbh
   "SELECT runname FROM runs WHERE id=?;"
   run-id))

;; given a run-id return all the run info
;;
(define (get-runs-info dbh target-patt run-name-patt area-patt) ;; to join ttype or not?
  (dbi:fold-row
   cons
   '()
   dbh   ;; 0    1       2       3      4     5      6       7        8         9         10          11         12
   "SELECT id,target,ttype_id,run_name,state,status,owner,event_time,comment,fail_count,pass_count,last_update,area_id
       FROM runs WHERE target LIKE ? AND run_name LIKE ? AND area_id IN (SELECT id FROM areas WHERE area_name LIKE ?);"
   target-patt run-name-patt area-patt))

;;======================================================================
;;  T E S T - S T E P S
;;======================================================================

(define (get-test-step-id dbh test-id stepname state)
  (dbi:get-one
................................................................................
		"SELECT DISTINCT target FROM runs WHERE target LIKE ? AND ttype_id=?;" target-patt tt-id))
	 ))
     ttypes)))

(define (get-targets-of-type dbh ttype-id target-patt)
  (dbi:get-rows dbh "SELECT DISTINCT target FROM runs WHERE target LIKE ? AND ttype_id=?;" target-patt ttype-id))


;; NB// this will not work on a Megatest 2.X database
;;
(define (get-runs-by-target dbh targets run-patt)
  (dbi:get-rows dbh "SELECT r.run_name, t.test_name, t.status, t.item_path, t.id, t.rundir, t.final_logf FROM runs as r INNER JOIN tests AS t ON t.run_id=r.id  
                          WHERE t.state='COMPLETED' AND r.target like ? AND  r.run_name like ?;" targets run-patt)
  )

(define (get-test-by-id dbh id)
  (dbi:get-rows dbh "SELECT t.test_name, t.item_path, t.rundir, t.final_logf FROM runs as r INNER JOIN tests AS t ON t.run_id=r.id  
................................................................................
;;
(define (get-changed-record-ids adat since-time)
  (print "get-changed-record-ids called with since-time=" since-time)
  (with-megatest-db
   adat
   (lambda (db)
     (let ((backcons (lambda (lst item)(cons item lst)))
	   (conscar  (lambda (row lst)(cons (car row) lst)))) ;; conscar should be cheaper than append
       `((runs       . ,(dbi:fold-row conscar '() db "SELECT id FROM runs  WHERE last_update>?;" since-time))
	 (tests      . ,(dbi:fold-row conscar '() db "SELECT id FROM tests WHERE last_update>?;" since-time))
	 (test_steps . ,(dbi:fold-row conscar '() db "SELECT id FROM test_steps WHERE last_update>?;" since-time))
	 (test_data  . ,(dbi:fold-row conscar '() db "SELECT id FROM test_data  WHERE last_update>?;" since-time))
	 (run_stats  . ,(dbi:fold-row conscar '() db "SELECT id FROM run_stats  WHERE last_update>?;" since-time))	
	 ;; (test_meta  . ,(fold-row backcons '() db "SELECT id FROM test_meta  WHERE last_update>?" since-time))
	 )))))