Commit eaea8805 authored by Dave Griffiths's avatar Dave Griffiths

ids fixed

parent 3ba3f7ee
......@@ -41,8 +41,6 @@
(list
(ktv "user-id" "varchar" "not set")
(ktv "language" "int" 0)
(ktv "house-id" "int" 0)
(ktv "photo-id" "int" 0)
(ktv "current-village" "varchar" "none")))
(define (get-setting-value name)
......@@ -483,6 +481,11 @@
(define button-size (list (inexact->exact (round (* 192 0.9)))
(inexact->exact (round (* 256 0.9)))))
(define (get-next-id db table type parent)
(+ 1 (length (filter-entities-inc-deleted
db table type
(list (list "parent" "varchar" "=" parent))))))
(define (make-photo-button-title e)
(string-append
......@@ -850,7 +853,7 @@
(ktv-get (get-entity-by-unique db "sync" (get-setting-value "current-village")) "name")
":"
(get-setting-value "user-id") ":"
(number->string (get/inc-setting "house-id"))))))
(number->string (get-next-id db "sync" "household" (get-setting-value "current-village")))))))
;; autogenerate the name from the current ID
(ktvlist-merge
household-ktvlist
......@@ -859,10 +862,6 @@
(mbutton 'villages (lambda () (list (start-activity "villages" 0 ""))))
(mbutton 'sync (lambda () (list (start-activity "sync" 0 ""))))
(horiz
(medit-text 'house-id "numeric" (lambda (v) (set-setting! "house-id" "int" (string->number v)) (list)))
(medit-text 'photo-id "numeric" (lambda (v) (set-setting! "photo-id" "int" (string->number v)) (list))))
)
(lambda (activity arg)
......@@ -877,8 +876,6 @@
(update-top-bar)
(list
(update-widget 'edit-text (get-id "user-id") 'text (get-setting-value "user-id"))
(update-widget 'edit-text (get-id "house-id") 'text (get-setting-value "house-id"))
(update-widget 'edit-text (get-id "photo-id") 'text (get-setting-value "photo-id"))
(update-widget 'spinner (get-id "languages-spinner") 'selection
(get-setting-value "language"))
(gps-start "gps" (lambda (loc)
......@@ -1012,7 +1009,7 @@
(string-append
(ktv-get (get-entity-by-unique db "sync" (get-setting-value "current-village")) "name")
(get-setting-value "user-id")
(number->string (get/inc-setting "house-id")))))))))
(number->string (get-next-id db "sync" "household" (get-setting-value "current-village"))))))))))
(lambda (activity arg)
(activity-layout activity))
(lambda (activity arg)
......@@ -1050,7 +1047,7 @@
db "sync" 'individuals (list "name" "first-name" "family") "individual" "individual"
(lambda () (get-current 'household #f))
(lambda ()
(let ((photo-id (get/inc-setting "photo-id"))
(let ((photo-id (get-next-id db "sync" "individual" (get-current 'household #f)))
(household-name (ktv-get (get-entity-by-unique db "sync" (get-current 'household #f)) "name")))
(ktvlist-merge
individual-ktvlist
......
......@@ -26,7 +26,7 @@
(list 'individual (list "Individual" "" ))
(list 'individuals (list "Individuals" "" ))
(list 'add-item-to-list (list "0" "" ))
(list 'default-village-name (list "New village" "" ))
(list 'default-village-name (list "village" "" ))
(list 'title (list "Symbai" "Symbai" "Symbai" "" ))
(list 'sync (list "Sync" "Sync" "Sync" "" ))
(list 'languages (list "Choose language" "Choose language" "Choose language" "" ))
......@@ -204,7 +204,7 @@
(list 'mobile (list "Mobile phone" "" ))
(list 'visit-market (list "How many times do you visit the tribal market?" "" ))
(list 'town-sell (list "How many times a month do you visit your nearest city or town to buy or sell something?" "" ))
(list 'default-crop-name (list "A crop" "" ))
(list 'default-crop-name (list "crop" "" ))
(list 'crop-name (list "Crop name" "" ))
(list 'crop-unit (list "Crop unit" "" ))
(list 'crop-used (list "Used or eaten" "" ))
......@@ -252,7 +252,7 @@
(list 'child-age (list "Age" ))
(list 'child-home (list "Lives at home" ))
(list 'child-alive (list "Alive" ))
(list 'default-child-name (list "A child" ))
(list 'default-child-name (list "child" ))
(list 'move-button (list "Move household" ))
(list 'move-household (list "Pick a new household" ))
(list 'house-id (list "House ID" ))
......
......@@ -76,6 +76,29 @@
filter)
"where e.entity_type = ? order by n.value"))
(define (build-query-inc-deleted table filter)
(alog "build-query start")
(string-append
(foldl
(lambda (i r)
(let ((var (string-append (filter-key i) "_var")))
;; add a query chunk
(string-append
r "join " table "_value_" (filter-type i) " "
"as " var " on "
var ".entity_id = e.entity_id and " var ".attribute_id = '" (filter-key i) "' and "
var ".value " (filter-op i) " ? ")))
;; boilerplate query start
(string-append
"select e.entity_id from " table "_entity as e "
;; order by name
"join " table "_value_varchar "
"as n on n.entity_id = e.entity_id and n.attribute_id = 'name' ")
filter)
"where e.entity_type = ? order by n.value"))
(define (build-args filter)
(map
(lambda (i)
......@@ -100,3 +123,22 @@
(lambda (i)
(vector-ref i 0))
(cdr s))))))
(define (filter-entities-inc-deleted db table type filter)
(let ((q (build-query-inc-deleted table filter)))
(alog q)
(alog "filter-entities start")
(let ((s (apply
db-select
(append
(list db q)
(build-args filter)
(list type)))))
(alog "filter-entities end")
(msg (db-status db))
(if (null? s)
'()
(map
(lambda (i)
(vector-ref i 0))
(cdr s))))))
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