53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
(dbi:exec sdb "INSERT OR IGNORE INTO strs (str) VALUES (?);" str))
(define (sdb:string->id sdb str-cache str)
(let ((id (hash-table-ref/default str-cache str #f)))
(if (not id)
(dbi:for-each-row
(lambda (sid)
(set! id sid)
(hash-table-set! str-cache str id))
sdb
"SELECT id FROM strs WHERE str=?;" str))
id))
(define (sdb:id->string sdb id-cache id)
(let ((str (hash-table-ref/default id-cache id #f)))
(if (not str)
(dbi:for-each-row
(lambda (istr)
(set! str istr)
(hash-table-set! id-cache id str))
sdb
"SELECT str FROM strs WHERE id=?;" id))
str))
;; Numbers get passed though in both directions
;;
|
|
|
|
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
(dbi:exec sdb "INSERT OR IGNORE INTO strs (str) VALUES (?);" str))
(define (sdb:string->id sdb str-cache str)
(let ((id (hash-table-ref/default str-cache str #f)))
(if (not id)
(dbi:for-each-row
(lambda (sid)
(set! id (vector-ref sid 0))
(hash-table-set! str-cache str id))
sdb
"SELECT id FROM strs WHERE str=?;" str))
id))
(define (sdb:id->string sdb id-cache id)
(let ((str (hash-table-ref/default id-cache id #f)))
(if (not str)
(dbi:for-each-row
(lambda (istr)
(set! str (vector-ref istr 0))
(hash-table-set! id-cache id str))
sdb
"SELECT str FROM strs WHERE id=?;" id))
str))
;; Numbers get passed though in both directions
;;
|