pref-matrix

Web interface to coordinate preferences
git clone https://git.instinctive.eu/pref-matrix.git
Log | Files | Refs | README | LICENSE

commit 7cba7dee207b65d9a4d8efe83859053a3741ae1d
parent e7eef508fffab7402df8f08fa462a214db414afa
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Thu, 18 Jan 2024 18:34:51 +0000

Subject and object names are validated before use
Diffstat:
Msrc/pref-matrix.scm | 41++++++++++++++++++++++-------------------
1 file changed, 22 insertions(+), 19 deletions(-)

diff --git a/src/pref-matrix.scm b/src/pref-matrix.scm @@ -268,26 +268,29 @@ key val)) -; (define-half-traced (set-pref subject-name object-name value) -; (exec (sql db "INSERT OR REPLACE INTO pref(sub_id,obj_id,val) VALUES -; ((SELECT id FROM subject WHERE name=?), -; (SELECT id FROM object WHERE name=?), -; ?);") -; subject-name object-name value)) - -(define-half-traced (set-subject-pref subject-name alist) +(define (set-pref sub-id object-name value) + (let ((obj-id (object-id object-name))) + (if obj-id + (begin + (exec (sql db "INSERT OR REPLACE INTO pref(sub_id,obj_id,val) + VALUES (?,?,?);") + sub-id + obj-id + value) + (last-insert-rowid db)) + #f))) + +(define-traced (set-subject-pref subject-name alist) (let ((sub-id (subject-id subject-name))) - (for-each - (lambda (pair) - (exec (sql db "INSERT OR REPLACE INTO pref(sub_id,obj_id,val) - VALUES (?,(SELECT id FROM object WHERE name=?),?);") - sub-id - (if (string? (car pair)) - (car pair) - (symbol->string (car pair))) - (string->number (cdr pair)))) - alist)) - (unless replaying? (generate-json))) + (if sub-id + (let ((result + (map + (lambda (pair) + (set-pref sub-id (car pair) (string->number (cdr pair)))) + alist))) + (unless replaying? (generate-json)) + result) + #f))) ;;;;;;;;;;; ;; Replay