-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.scm
41 lines (37 loc) · 1.16 KB
/
session.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(define session-get-sid
(lambda (sid field)
(let ((res
(db-query
(format #f "SELECT ~a FROM sessions WHERE sid='~a'" field sid))))
(cond
((null? res) "")
(else (cdr (car (car res))))))))
(define session-set-sid
(lambda (sid field value)
(if (null? (db-query
(format
#f "SELECT ~a FROM sessions WHERE sid='~a'"
field sid)))
(db-query (format
#f
"INSERT INTO sessions (sid,~a) VALUES ('~a','~a')"
field sid value)))
(let ((res
(db-query
(format #f "UPDATE sessions SET ~a='~a' WHERE sid='~a'"
field value sid))))
(cond
((null? res) res)
(else (cdr (car (car res))))))))
(define session-get
(lambda (rc field)
(session-get-sid (session-sid rc) field)))
(define session-set
(lambda (rc field value)
(session-set-sid (session-sid rc) field value)))
(define session-sid
(lambda (rc)
(let ((s (:session rc 'check-and-spawn)))
(cond
((string? s) (format #t "session-sid: ~a~%" s) s)
(else "")))))