304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
(for-each
(lambda (dat)
(let ((tblname (car dat))
(count (cdr dat)))
(set! tot-count (+ tot-count count))))
(sort (hash-table->alist numrecs)(lambda (a b)(> (cdr a)(cdr b))))))
tot-count))
;;======================================================================
;; Moved from dbfile
;;======================================================================
)
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
(for-each
(lambda (dat)
(let ((tblname (car dat))
(count (cdr dat)))
(set! tot-count (+ tot-count count))))
(sort (hash-table->alist numrecs)(lambda (a b)(> (cdr a)(cdr b))))))
tot-count))
;; direction = fromdest, todest
;; mode = 'full, 'incr
;;
(define (dbmod:attach-sync tables dbh destdbfile direction #!key (mode 'full))
(let* ((dest-exists (file-exists? destdbfile)))
(assert dest-exists "FATAL: sync called with non-existant file, "destdbfile)
;; attach the destdbfile
;; for each table
;; insert into dest.<table> select * from src.<table> where last_update>last_update
;; done
(sqlite3:execute dbh "ATTACH ? AS auxdb;" destdbfile)
(for-each
(lambda (table)
(let* ((dir (eq? direction 'todest))
(fromdb (if dir "" "auxdb."))
(todb (if dir "auxdb." ""))
(stmt1 (conc "INSERT OR IGNORE INTO "todb table
" SELECT * FROM "fromdb table";"))
(stmt2 (conc "INSERT OR REPLACE INTO "todb table
" SELECT * FROM "fromdb table" WHERE "
fromdb table".last_update > "
todb table".last_update;"))
(stmt3 (conc "INSERT OR REPLACE INTO "todb"."table
" SELECT * FROM "fromdb table";"))
(stmt4 (conc "DELETE FROM "todb table" WHERE "fromdb
"tests.last_update > "todb table".last_update;")))
;; (print "stmt1: "stmt1)
;; (print "stmt2: "stmt2)
;; (print "stmt3: "stmt4)
;; (print "stmt1: "stmt1)
(sqlite3:execute dbh stmt4)
(sqlite3:execute dbh stmt1)
;; (sqlite3:execute dbh stmt1)
;; (sqlite3:execute dbh stmt2)
(sqlite3:execute dbh "DETACH auxdb;")))
tables)))
;;======================================================================
;; Moved from dbfile
;;======================================================================
)
|