From 3c32182d51aaf7f224254a81ab2b6f8bbe6bda4e Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 5 Dec 2018 08:39:10 -0800 Subject: [PATCH] blobby --- fontland/fontland/db.rkt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fontland/fontland/db.rkt b/fontland/fontland/db.rkt index ef6ac6c2..7a62add7 100644 --- a/fontland/fontland/db.rkt +++ b/fontland/fontland/db.rkt @@ -18,20 +18,19 @@ (begin (log-query q) (query-rows (current-dbc) q arg ...))) (define (add-record! rec) - (define recstring (format "(~a, '~a')" (car rec) (bytes->hex-string (cdr rec)))) - (query-exec-logging (format "insert or replace into layouts (crc, layout) values ~a" recstring))) + (query-exec-logging "insert or replace into layouts (crc, layout) values ($1, $2)" (car rec) (cdr rec))) (define/caching (get-layout-from-db which) - (match (query-rows-logging (format "select layout from layouts where crc==~a" which)) - [(list (vector val)) (hex-string->bytes val)] + (match (query-rows-logging "select layout from layouts where crc==$1" which) + [(list (vector val)) val] [_ #false])) (define (init-db) - (query-exec-logging "create table if not exists layouts (crc INTEGER UNIQUE, layout TEXT)") + (query-exec-logging "create table if not exists layouts (crc INTEGER UNIQUE, layout BLOB)") (query-exec-logging "create index if not exists layout_crcs ON layouts (crc); ")) (module+ main (init-db) - (add-record! (cons 42 #"01234")) + (add-record! (cons 42 (bytes 0 1 0 2 3 4))) (get-layout-from-db 42)) \ No newline at end of file