Megatest

Diff
Login

Differences From Artifact [2b5e880cc2]:

To Artifact [33e8e7f1ab]:


556
557
558
559
560
561
562
563

564
565

566
567
568
569
570
571
572
556
557
558
559
560
561
562

563
564

565
566
567
568
569
570
571
572







-
+

-
+







	       (cons todb slave-dbs))
     
     0)
   ;; this is the work to be done
   (cond
    ((not fromdb) (debug:print 3 *default-log-port* "WARNING: db:sync-tables called with fromdb missing") -1)
    ((not todb)   (debug:print 3 *default-log-port* "WARNING: db:sync-tables called with todb missing") -2)
    ((not (eq? 'sqlite3 (dbi:db-dbtype fromdb)))
    ((not (dbi:database? (db:dbdat-get-db fromdb)))
     (debug:print-error 0 *default-log-port* "db:sync-tables called with fromdb not a database " fromdb) -3)
    ((not (eq? 'sqlite3 (dbi:db-dbtype todb)))
    ((not (dbi:database? (db:dbdat-get-db todb)))
     (debug:print-error 0 *default-log-port* "db:sync-tables called with todb not a database " todb) -4)
    (else
     (let ((stmts       (make-hash-table)) ;; table-field => stmt
	   (all-stmts   '())              ;; ( ( stmt1 value1 ) ( stml2 value2 ))
	   (numrecs     (make-hash-table))
	   (start-time  (current-milliseconds))
	   (tot-count   0))
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
594
595
596
597
598
599
600

601
602
603
604
605
606
607







-







				   " VALUES ( " (string-intersperse (make-list num-fields "?") ",") " );"))
		 (fromdat    '())
		 (fromdats   '())
		 (totrecords 0)
		 (batch-len  (string->number (or (configf:lookup *configdat* "sync" "batchsize") "10")))
		 (todat      (make-hash-table))
		 (count      0))

	    ;; set up the field->num table
	    (for-each
	     (lambda (field)
	       (hash-table-set! field->num field count)
	       (set! count (+ count 1)))
	     fields)

624
625
626
627
628
629
630
631

632
633
634
635
636
637
638
623
624
625
626
627
628
629

630
631
632
633
634
635
636
637







-
+








	    (if (common:low-noise-print 120 "sync-records")
		(debug:print-info 4 *default-log-port* "found " totrecords " records to sync"))

	    ;; read the target table
	    (dbi:for-each-row
        (lambda (output)
	       (hash-table-set! todat a (apply vector a b)))
	       (hash-table-set! todat (vector-ref output 0) output))
	     (db:dbdat-get-db todb)
	     full-sel)

	    ;; first pass implementation, just insert all changed rows
	    (for-each 
	     (lambda (targdb)
	       (let* ((db     (db:dbdat-get-db targdb))
653
654
655
656
657
658
659
660

661
662
663
664
665
666
667
652
653
654
655
656
657
658

659
660
661
662
663
664
665
666







-
+







				      (not (equal? (vector-ref fromrow i)(vector-ref curr i))))
				  (set! same #f))
			      (if (and same
				       (< i (- num-fields 1)))
				  (loop (+ i 1))))
			    (if (not same)
				(begin
				  (apply dbi:exec stmth (vector->list fromrow))
				  (dbi:exec stmth (vector->list fromrow))
				  (hash-table-set! numrecs tablename (+ 1 (hash-table-ref/default numrecs tablename 0)))))))
			fromdat-lst))
		  ))
		  fromdats)
		 (dbi:close stmth)))
	     (append (list todb) slave-dbs))))
	tbls)