Commit e23b605c authored by Dave Griffiths's avatar Dave Griffiths
Browse files

android fixes

parent 5aa083a2
......@@ -158,7 +158,10 @@
;; getting data out
(define (entity-exists? db table unique-id)
(not (null? (select-first db (string-append "select * from " table "_entity where unique_id = '" unique-id "';")))))
(not (null? (select-first
db (string-append
"select * from " table "_entity where unique_id = ?")
unique-id))))
(define (get-entity-type db table entity-id)
(select-first
......@@ -290,12 +293,14 @@
;; versioning
(define (get-entity-version db table entity-id)
(select-first db (string-append "select version from " table "_entity where entity_id = ?")
entity-id))
(select-first
db (string-append "select version from " table "_entity where entity_id = ?")
entity-id))
(define (get-entity-dirty db table entity-id)
(select-first db (string-append "select dirty from " table "_entity where entity_id = ?")
entity-id))
(select-first
db (string-append "select dirty from " table "_entity where entity_id = ?")
entity-id))
(define (update-entity-changed db table entity-id)
(db-exec
......@@ -307,7 +312,7 @@
(db-exec
db (string-append
"update " table "_entity set dirty=?, version=? where entity_id = ?")
1 entity-id version))
1 version entity-id))
(define (update-entity-clean db table unique-id)
(db-exec
......@@ -334,7 +339,7 @@
(cdr (vector->list i))
;; data entries (todo - only dirty values!)
(get-entity-plain db table (vector-ref i 0))))
de))))
(cdr de)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; syncing
......@@ -357,7 +362,7 @@
(lambda (i r)
(string-append
r "\n" (vector-ref i 0) " " (vector-ref i 1) " "
(stringify-ktvlist (get-entity db table (string->number (vector-ref i 0))))))
(stringify-ktvlist (get-entity db table (vector-ref i 0)))))
""
(cdr (db-select
db (string-append "select * from " table "_entity where dirty=1;")))))
......@@ -368,7 +373,7 @@
(lambda (i)
(list
(vector->list i)
(get-entity db table (string->number (vector-ref i 0)))))
(get-entity db table (vector-ref i 0))))
(cdr (db-select
db (string-append "select * from " table "_entity where dirty=1;")))))
......
......@@ -89,12 +89,13 @@
"&table=" table
"&entity-type=" (list-ref (car e) 0)
"&unique-id=" (list-ref (car e) 1)
"&dirty=" (list-ref (car e) 2)
"&version=" (list-ref (car e) 3)
"&dirty=" (number->string (list-ref (car e) 2))
"&version=" (number->string (list-ref (car e) 3))
(build-url-from-ktvlist (cadr e))))
;; spit all dirty entities to server
(define (spit-dirty db table)
(msg "hello")
(map
(lambda (e)
(http-request
......@@ -105,7 +106,7 @@
(if (equal? (car v) "inserted")
(update-entity-clean db table (cadr v))
(display "somefink went wrong")(newline)))))
(dirty-entities db table)))
(dbg (dirty-entities db table))))
(define (suck-entity-from-server db table unique-id exists)
(msg "suck-entity-from-server" unique-id)
......@@ -154,8 +155,9 @@
(exists (entity-exists? db table unique-id))
(old
(if exists
(> version (string->number
(dbg (get-entity-version db table unique-id))))
(> version (dbg (get-entity-version
db table
(get-entity-id db table unique-id))))
#f)))
;; if we don't have this entity or the version on the server is newer
(if (or (not exists) old)
......@@ -667,8 +669,8 @@
(stream (get-dirty-stats db "stream")))
(msg sync stream)
(dbg (string-append
"Pack data: " (car sync) "/" (cadr sync) " "
"Focal data: " (car stream) "/" (cadr stream)))))))
"Pack data: " (number->string (car sync)) "/" (number->string (cadr sync)) " "
"Focal data: " (number->string (car stream)) "/" (number->string (cadr stream))))))))
(activity
"sync"
(vert
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment