Add checks to guard against null data

Signed-off-by: Christopher Baines <mail@cbaines.net>
This commit is contained in:
Danjela Lura 2020-05-28 22:27:48 +02:00 committed by Christopher Baines
parent f67bea719d
commit b8abe38352
2 changed files with 29 additions and 23 deletions

View file

@ -36,20 +36,22 @@
(define (insert-guix-revision-lint-warnings conn (define (insert-guix-revision-lint-warnings conn
guix-revision-id guix-revision-id
lint-warning-ids) lint-warning-ids)
(exec-query (if (null? lint-warning-ids)
conn '()
(string-append (exec-query
"INSERT INTO guix_revision_lint_warnings (lint_warning_id, guix_revision_id) " conn
"VALUES " (string-append
(string-join "INSERT INTO guix_revision_lint_warnings (lint_warning_id, guix_revision_id) "
(map (lambda (lint-warning-id) "VALUES "
(simple-format (string-join
#f (map (lambda (lint-warning-id)
"(~A, ~A)" (simple-format
lint-warning-id #f
guix-revision-id)) "(~A, ~A)"
lint-warning-ids) lint-warning-id
", ")))) guix-revision-id))
lint-warning-ids)
", ")))))
(define* (lint-warnings-for-guix-revision conn commit-hash (define* (lint-warnings-for-guix-revision conn commit-hash
#:key #:key

View file

@ -317,10 +317,12 @@ WHERE table_name = $1"
"ANALYZE " temp-table-name)) "ANALYZE " temp-table-name))
;; Populate the temporary table ;; Populate the temporary table
(with-time-logging (string-append "populating " temp-table-name) (if (null? data)
(exec-query conn '()
(insert-sql data (with-time-logging (string-append "populating " temp-table-name)
#:table-name temp-table-name))) (exec-query conn
(insert-sql data
#:table-name temp-table-name))))
;; Use the temporary table to find the existing values ;; Use the temporary table to find the existing values
(let ((result (let ((result
(with-time-logging (with-time-logging
@ -336,11 +338,13 @@ WHERE table_name = $1"
result)) result))
;; If not using a temporary table, just do a single SELECT query ;; If not using a temporary table, just do a single SELECT query
(exec-query->vhash conn (if (null? data)
select-query '()
cdr (exec-query->vhash conn
(lambda (result) select-query
(string->number (first result)))))) cdr
(lambda (result)
(string->number (first result)))))))
(missing-entries (missing-entries
(filter (lambda (field-values) (filter (lambda (field-values)
(not (vhash-assoc (not (vhash-assoc