Improve null handling
This commit is contained in:
parent
bb84e45c42
commit
b128e9bd7a
4 changed files with 17 additions and 14 deletions
|
|
@ -41,6 +41,8 @@
|
|||
with-advisory-session-lock/log-time
|
||||
obtain-advisory-transaction-lock
|
||||
|
||||
NULL
|
||||
NULL?
|
||||
exec-query-with-null-handling))
|
||||
|
||||
;; TODO This isn't exported for some reason
|
||||
|
|
@ -279,6 +281,10 @@
|
|||
"SELECT pg_advisory_xact_lock($1)"
|
||||
(list lock-number))))
|
||||
|
||||
(define NULL (make-symbol "null"))
|
||||
|
||||
(define NULL? (lambda (s) (eq? s NULL)))
|
||||
|
||||
(define squee/libpq
|
||||
(@@ (squee) libpq))
|
||||
|
||||
|
|
@ -304,7 +310,7 @@
|
|||
((string-null? val)
|
||||
(if (eq? 1 (%PQgetisnull
|
||||
(squee/unwrap-result-ptr result-ptr) row-i col-i))
|
||||
'()
|
||||
NULL
|
||||
val))
|
||||
(else val))))
|
||||
cols-range))
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
#:use-module (ice-9 match)
|
||||
#:use-module (squee)
|
||||
#:use-module (guix inferior)
|
||||
#:use-module (guix-data-service database)
|
||||
#:use-module (guix-data-service model utils)
|
||||
#:export (inferior-packages->license-id-lists
|
||||
inferior-packages->license-data))
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
#:use-module (guix i18n)
|
||||
#:use-module (guix inferior)
|
||||
#:use-module (guix-data-service utils)
|
||||
#:use-module (guix-data-service database)
|
||||
#:use-module (guix-data-service model location)
|
||||
#:use-module (guix-data-service model utils)
|
||||
#:export (select-package-metadata-by-revision-name-and-version
|
||||
|
|
|
|||
|
|
@ -23,8 +23,7 @@
|
|||
#:use-module (squee)
|
||||
#:use-module (guix-data-service database)
|
||||
#:use-module (guix-data-service utils)
|
||||
#:export (NULL
|
||||
quote-string
|
||||
#:export (quote-string
|
||||
value->quoted-string-or-null
|
||||
non-empty-string-or-false
|
||||
exec-query->vhash
|
||||
|
|
@ -36,15 +35,13 @@
|
|||
group-to-alist/vector
|
||||
insert-missing-data-and-return-all-ids))
|
||||
|
||||
(define NULL '())
|
||||
|
||||
(define (quote-string s)
|
||||
(string-append "$STR$" s "$STR$"))
|
||||
|
||||
(define (value->quoted-string-or-null value)
|
||||
(if (string? value)
|
||||
(string-append "$STR$" value "$STR$")
|
||||
"NULL"))
|
||||
NULL))
|
||||
|
||||
(define (non-empty-string-or-false s)
|
||||
(if (string? s)
|
||||
|
|
@ -189,6 +186,8 @@ WHERE table_name = $1"
|
|||
(match-lambda
|
||||
((? string? s)
|
||||
(string-append "$STR$" s "$STR$"))
|
||||
((? NULL?)
|
||||
"NULL")
|
||||
((? symbol? s)
|
||||
(string-append "$STR$"
|
||||
(symbol->string s)
|
||||
|
|
@ -197,8 +196,6 @@ WHERE table_name = $1"
|
|||
(number->string n))
|
||||
((? boolean? b)
|
||||
(if b "TRUE" "FALSE"))
|
||||
((? null?)
|
||||
"NULL")
|
||||
((cast . value)
|
||||
(string-append
|
||||
(value->sql value) "::" cast))
|
||||
|
|
@ -223,11 +220,11 @@ WHERE table_name = $1"
|
|||
((? symbol? val) (symbol->string val))
|
||||
(val val))))
|
||||
(cond
|
||||
((null? a-val)
|
||||
(if (null? b-val)
|
||||
((NULL? a-val)
|
||||
(if (NULL? b-val)
|
||||
(loop (cdr a) (cdr b))
|
||||
#t))
|
||||
((null? b-val)
|
||||
((NULL? b-val)
|
||||
#f)
|
||||
(else
|
||||
(match a-val
|
||||
|
|
@ -340,13 +337,11 @@ WHERE table_name = $1"
|
|||
(if b "t" "f"))
|
||||
((? number? n)
|
||||
(number->string n))
|
||||
((? NULL? n) n)
|
||||
((? symbol? s)
|
||||
(symbol->string s))
|
||||
((? string? s)
|
||||
s)
|
||||
((? null? n)
|
||||
;; exec-query-with-null-handling specifies NULL values as '()
|
||||
n)
|
||||
((cast . value)
|
||||
(if (string=? cast "jsonb")
|
||||
(format-json value)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue