aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm631
1 files changed, 251 insertions, 380 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index 81472ff..eab43b7 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -220,6 +220,16 @@
datastore))
+(define (sqlite-step-and-reset statement)
+ (let ((val (sqlite-step statement)))
+ (sqlite-reset statement)
+ val))
+
+(define (sqlite-step-and-finalize statement)
+ (let ((val (sqlite-step statement)))
+ (sqlite-finalize statement)
+ val))
+
(define* (db-optimize db db-filename metrics-registry
#:key (maybe-truncate-wal? #t))
(define (wal-size)
@@ -245,7 +255,7 @@
(sqlite-prepare
db
"PRAGMA wal_checkpoint(TRUNCATE);")))
- (match (sqlite-step statement)
+ (match (sqlite-step-and-finalize statement)
(#(blocked? modified-page-count pages-moved-to-db)
(if (= blocked? 1)
(begin
@@ -257,8 +267,7 @@
(current-error-port)
"wal checkpoint completed (~A, ~A)\n"
modified-page-count
- pages-moved-to-db))))
- (sqlite-finalize statement)))))
+ pages-moved-to-db))))))))
(call-with-duration-metric
metrics-registry
@@ -604,8 +613,7 @@ INSERT INTO dynamic_auth_tokens (token) VALUES (:token)"
statement
#:token token)
- (sqlite-step statement)
- (sqlite-reset statement)))))
+ (sqlite-step-and-reset statement)))))
(define-method (datastore-dynamic-auth-token-exists?
(datastore <sqlite-datastore>)
@@ -726,8 +734,7 @@ UPDATE agents SET active = :active WHERE id = :uuid"
#:uuid agent-uuid
#:active (if active? 1 0))
- (sqlite-step statement)
- (sqlite-finalize statement))))
+ (sqlite-step-and-finalize statement))))
active?)
(define-method (datastore-find-agent-status
@@ -749,11 +756,9 @@ WHERE agent_id = :agent_id"
statement
#:agent_id agent-id)
- (match (sqlite-step statement)
+ (match (sqlite-step-and-reset statement)
(#(status 1min_load_average timestamp
processor_count)
- (sqlite-reset statement)
-
`((status . ,status)
(1min_load_average . ,1min_load_average)
(timestamp . ,timestamp)
@@ -778,8 +783,7 @@ DELETE FROM agent_status WHERE agent_id = :uuid"
(sqlite-bind-arguments statement
#:uuid agent-uuid)
- (sqlite-step statement)
- (sqlite-reset statement))
+ (sqlite-step-and-reset statement))
(let ((statement
(sqlite-prepare
@@ -795,8 +799,7 @@ INSERT INTO agent_status (agent_id, status, load_average_1min, processor_count)
#:load 1min-load-average
#:processor_count processor-count)
- (sqlite-step statement)
- (sqlite-reset statement))))
+ (sqlite-step-and-reset statement))))
#t)
@@ -830,13 +833,9 @@ WHERE agent_id = :agent_id AND password = :password"
#:agent_id uuid
#:password password)
- (let ((result
- (match (sqlite-step statement)
- (#f #f)
- (#(1) #t))))
- (sqlite-reset statement)
-
- result)))))
+ (match (sqlite-step-and-reset statement)
+ (#f #f)
+ (#(1) #t))))))
(define-method (datastore-agent-list-passwords
(datastore <sqlite-datastore>)
@@ -899,31 +898,24 @@ INSERT INTO agent_tags (agent_id, tag_id) VALUES (:agent_id, :tag_id)"
(sqlite-bind-arguments find-tag-statement
#:tag_key key
#:tag_value value)
- (let ((result
- (match (sqlite-step find-tag-statement)
- (#(id) id)
- (#f
- (sqlite-bind-arguments insert-tag-statement
- #:tagkey key
- #:tagvalue value)
- (sqlite-step insert-tag-statement)
- (sqlite-reset insert-tag-statement)
- (last-insert-rowid db)))))
- (sqlite-reset find-tag-statement)
-
- result))
+ (match (sqlite-step-and-reset find-tag-statement)
+ (#(id) id)
+ (#f
+ (sqlite-bind-arguments insert-tag-statement
+ #:tagkey key
+ #:tagvalue value)
+ (sqlite-step-and-reset insert-tag-statement)
+ (last-insert-rowid db))))
(define (insert-tag key value)
(sqlite-bind-arguments agent-tags-statement
#:agent_id agent-id
#:tag_id (tag->id key value))
- (sqlite-step agent-tags-statement)
- (sqlite-reset agent-tags-statement))
+ (sqlite-step-and-reset agent-tags-statement))
(sqlite-bind-arguments delete-agent-tags-statement
#:agent_id agent-id)
- (sqlite-step delete-agent-tags-statement)
- (sqlite-reset delete-agent-tags-statement)
+ (sqlite-step-and-reset delete-agent-tags-statement)
(for-each
(match-lambda
((('key . key)
@@ -979,12 +971,9 @@ WHERE derivation_outputs.derivation_id = :derivation_id
statement
#:derivation_id (db-find-derivation-id db derivation))
- (let ((result (sqlite-step statement)))
- (sqlite-reset statement)
-
- (if result
- #t
- #f))))))
+ (if (sqlite-step-and-reset statement)
+ #t
+ #f)))))
(define-method (datastore-build-required-by-another?
(datastore <sqlite-datastore>)
@@ -1019,12 +1008,9 @@ WHERE builds.uuid = :uuid
statement
#:uuid uuid)
- (let ((result (sqlite-step statement)))
- (sqlite-reset statement)
-
- (if result
- #t
- #f))))))
+ (if (sqlite-step-and-reset statement)
+ #t
+ #f)))))
(define-method (datastore-list-related-derivations-with-no-build-for-outputs
(datastore <sqlite-datastore>)
@@ -1084,11 +1070,8 @@ SELECT name FROM derivations WHERE id = :id"
statement
#:id derivation-id)
- (let ((result (match (sqlite-step statement)
- (#(name) name))))
- (sqlite-reset statement)
-
- result)))
+ (match (sqlite-step-and-reset statement)
+ (#(name) name))))
(call-with-worker-thread
(slot-ref datastore 'worker-reader-thread-channel)
@@ -1270,19 +1253,14 @@ INSERT INTO build_tags (build_id, tag_id) VALUES (:build_id, :tag_id)"
(sqlite-bind-arguments find-tag-statement
#:tag_key key
#:tag_value value)
- (let ((result
- (match (sqlite-step find-tag-statement)
- (#(id) id)
- (#f
- (sqlite-bind-arguments insert-tag-statement
- #:tagkey key
- #:tagvalue value)
- (sqlite-step insert-tag-statement)
- (sqlite-reset insert-tag-statement)
- (last-insert-rowid db)))))
- (sqlite-reset find-tag-statement)
-
- result))
+ (match (sqlite-step-and-reset find-tag-statement)
+ (#(id) id)
+ (#f
+ (sqlite-bind-arguments insert-tag-statement
+ #:tagkey key
+ #:tagvalue value)
+ (sqlite-step-and-reset insert-tag-statement)
+ (last-insert-rowid db))))
(for-each
(match-lambda
@@ -1290,8 +1268,7 @@ INSERT INTO build_tags (build_id, tag_id) VALUES (:build_id, :tag_id)"
(sqlite-bind-arguments build-tags-statement
#:build_id (db-find-build-id db build-uuid)
#:tag_id (tag->id key value))
- (sqlite-step build-tags-statement)
- (sqlite-reset build-tags-statement)))
+ (sqlite-step-and-reset build-tags-statement)))
(if (vector? tags)
(vector->list tags)
tags)))))
@@ -1312,8 +1289,7 @@ UPDATE builds SET canceled = 1 WHERE uuid = :uuid"
statement
#:uuid uuid)
- (sqlite-step statement)
- (sqlite-reset statement))
+ (sqlite-step-and-reset statement))
(let ((statement (sqlite-prepare
db
@@ -1327,8 +1303,7 @@ DELETE FROM unprocessed_builds_with_derived_priorities
statement
#:uuid uuid)
- (sqlite-step statement)
- (sqlite-reset statement))))
+ (sqlite-step-and-reset statement))))
#t)
(define (db-get-build-priority db build-id)
@@ -1343,12 +1318,8 @@ SELECT priority FROM builds WHERE id = :build_id"
statement
#:build_id build-id)
- (let ((result
- (vector-ref (sqlite-step statement)
- 0)))
- (sqlite-reset statement)
-
- result)))
+ (vector-ref (sqlite-step-and-reset statement)
+ 0)))
(define (get-derived-priority db build-id)
(let ((statement
@@ -1378,13 +1349,11 @@ WHERE builds.id = :build_id"
statement
#:build_id build-id)
- (let ((result (match (sqlite-step statement)
- (#(#f)
- (db-get-build-priority db build-id))
- (#(derived-priority) derived-priority))))
- (sqlite-reset statement)
-
- result)))
+ (match (sqlite-step-and-reset statement)
+ (#(#f)
+ (db-get-build-priority db build-id))
+ (#(derived-priority)
+ derived-priority))))
(define (update-unprocessed-builds-with-higher-derived-priorities
db
@@ -1450,8 +1419,8 @@ WHERE build_id = :build_id"
(sqlite-bind-arguments update-derived-priority-statement
#:build_id id
#:derived_priority derived-priority)
- (sqlite-step update-derived-priority-statement)
- (sqlite-reset update-derived-priority-statement))
+ (sqlite-step-and-reset
+ update-derived-priority-statement))
builds-to-update))))
(define (datastore-update-unprocessed-builds-with-lower-derived-priorities
@@ -1540,8 +1509,7 @@ WHERE build_id = :build_id"
(sqlite-bind-arguments statement
#:build_id build-id
#:derived_priority new-derived-priority)
- (sqlite-step statement)
- (sqlite-reset statement)))))
+ (sqlite-step-and-reset statement)))))
builds-to-consider))
@@ -1564,10 +1532,8 @@ WHERE build_id = :build_id"
statement
#:build_id build-id)
- (match (sqlite-step statement)
+ (match (sqlite-step-and-reset statement)
(#(derived-priority all-inputs-built)
- (sqlite-reset statement)
-
(values derived-priority
(= 1 all-inputs-built))))))
@@ -1586,8 +1552,7 @@ WHERE id = :build_id"
#:priority new-priority
#:build_id build-id)
- (sqlite-step statement)
- (sqlite-reset statement))
+ (sqlite-step-and-reset statement))
#t)
(define (db-update-build-derived-priority db build-id new-derived-priority)
@@ -1605,8 +1570,7 @@ WHERE build_id = :build_id"
#:derived_priority new-derived-priority
#:build_id build-id)
- (sqlite-step statement)
- (sqlite-reset statement))
+ (sqlite-step-and-reset statement))
#t)
(apply
@@ -1701,8 +1665,7 @@ DELETE FROM build_allocation_plan WHERE build_id = :build_id"
statement
#:build_id (db-find-build-id db uuid))
- (sqlite-step statement)
- (sqlite-reset statement)
+ (sqlite-step-and-reset statement)
(unless (= 0 (changes-count db))
(update-build-allocation-plan-metrics)))))
@@ -1757,9 +1720,7 @@ VALUES (:agent_id, :result, 1)"
#:agent_id agent-id
#:result result)
- (match (let ((res (sqlite-step statement)))
- (sqlite-reset statement)
- res)
+ (match (sqlite-step-and-reset statement)
(#(count) #t)
(#f
(sqlite-bind-arguments
@@ -1767,28 +1728,30 @@ VALUES (:agent_id, :result, 1)"
#:agent_id agent-id
#:result result)
- (sqlite-step insert-statement)
- (sqlite-reset insert-statement)
+ (sqlite-step-and-reset insert-statement)
#t))))
(call-with-worker-thread/delay-logging
(slot-ref datastore 'worker-writer-thread-channel)
(lambda (db)
- (sqlite-exec
- db
- (string-append
- "
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
INSERT INTO build_results (
build_id, agent_id, result, failure_reason
-) VALUES ("
- (number->string (db-find-build-id db build-uuid)) ", '"
- agent-id "', '"
- result "', "
- (if failure-reason
- (string-append "'" failure-reason "'")
- "NULL")
- ")"))
+) VALUES (:build_id, :agent_id, :result, :failure_reason)"
+ #:cache? #t)))
+
+ (sqlite-bind-arguments
+ statement
+ #:build_id (db-find-build-id db build-uuid)
+ #:agent_id agent-id
+ #:result result
+ #:failure_reason failure-reason)
+
+ (sqlite-step-and-reset statement))
(increment-count db)))
#t)
@@ -1817,12 +1780,9 @@ LIMIT 1"
statement
#:build_id build-id)
- (let ((result (match (sqlite-step statement)
- (#f #t)
- (#(1) #f))))
- (sqlite-reset statement)
-
- result)))
+ (match (sqlite-step-and-reset statement)
+ (#f #t)
+ (#(1) #f))))
(call-with-worker-thread/delay-logging
(slot-ref datastore 'worker-writer-thread-channel)
@@ -1865,9 +1825,9 @@ WHERE build_id = :build_id"
(match row
(#(build-id)
(when (all-inputs-built? db build-id)
- (sqlite-bind-arguments update-statement #:build_id build-id)
- (sqlite-step update-statement)
- (sqlite-reset update-statement))))
+ (sqlite-bind-arguments update-statement
+ #:build_id build-id)
+ (sqlite-step-and-reset update-statement))))
#f)
#f
builds-statement)
@@ -1879,15 +1839,21 @@ WHERE build_id = :build_id"
(call-with-worker-thread/delay-logging
(slot-ref datastore 'worker-writer-thread-channel)
(lambda (db)
- (sqlite-exec
- db
- (string-append
- "
-DELETE FROM allocated_builds WHERE build_id = "
- (number->string (db-find-build-id db build-uuid))
- " AND agent_id = '"
- agent-id
- "'"))))
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+DELETE FROM allocated_builds
+ WHERE build_id = :build_id
+ AND agent_id = :agent_id"
+ #:cache? #t)))
+
+ (sqlite-bind-arguments
+ statement
+ #:build_id (db-find-build-id db build-uuid)
+ #:agent_id agent-id)
+
+ (sqlite-step-and-reset statement))))
#t)
(define-method (datastore-mark-build-as-processed
@@ -1896,16 +1862,21 @@ DELETE FROM allocated_builds WHERE build_id = "
(call-with-worker-thread/delay-logging
(slot-ref datastore 'worker-writer-thread-channel)
(lambda (db)
- (sqlite-exec
- db
- (string-append
- "
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
UPDATE builds
-SET processed = 1 "
- (if end-time
- (string-append ", end_time = '" end-time "'")
- "") "
-WHERE id = " (number->string (db-find-build-id db build-uuid))))
+SET processed = 1, end_time = :end_time
+WHERE id = :build_id"
+ #:cache? #t)))
+
+ (sqlite-bind-arguments
+ statement
+ #:end_time (or end-time "")
+ #:build_id (db-find-build-id db build-uuid))
+
+ (sqlite-step-and-reset statement))
(let ((statement (sqlite-prepare
db
@@ -1919,8 +1890,7 @@ DELETE FROM unprocessed_builds_with_derived_priorities
statement
#:uuid build-uuid)
- (sqlite-step statement)
- (sqlite-reset statement))))
+ (sqlite-step-and-reset statement))))
#t)
(define-method (datastore-delete-relevant-outputs-from-unbuilt-outputs
@@ -1947,8 +1917,7 @@ WHERE output_id IN (
statement
#:build_id (db-find-build-id db build-uuid))
- (sqlite-step statement)
- (sqlite-reset statement)
+ (sqlite-step-and-reset statement)
#t))))
(define-method (datastore-store-output-metadata
@@ -1975,11 +1944,8 @@ WHERE builds.uuid = :build_uuid AND derivation_outputs.name = :name"
#:build_uuid build-uuid
#:name name)
- (match (sqlite-step statement)
- (#(id)
- (sqlite-reset statement)
-
- id))))
+ (match (sqlite-step-and-reset statement)
+ (#(id) id))))
(sqlite-exec
db
@@ -2250,13 +2216,9 @@ SELECT id FROM builds WHERE uuid = :uuid"
statement
#:uuid uuid)
- (let ((result
- (match (sqlite-step statement)
- (#f #f)
- (#(id) id))))
- (sqlite-reset statement)
-
- result)))
+ (match (sqlite-step-and-reset statement)
+ (#f #f)
+ (#(id) id))))
(define-method (datastore-find-build
(datastore <sqlite-datastore>)
@@ -2279,34 +2241,30 @@ WHERE uuid = :uuid"
statement
#:uuid uuid)
- (let ((result
- (match (sqlite-step statement)
- (#(uuid derivation_name priority processed canceled
- created_at end_time)
- `((uuid . ,uuid)
- (derivation-name . ,derivation_name)
- (priority . ,priority)
- (processed . ,(cond
- ((= 0 processed) #f)
- ((= 1 processed) #t)
- (else
- (error "unknown processed value"))))
- (canceled . ,(cond
- ((= 0 canceled) #f)
- ((= 1 canceled) #t)
- (else
- (error "unknown canceled value"))))
- (created-at . ,(if (string? created_at)
- (match (strptime "%F %T" created_at)
- ((parts . _) parts))
- #f))
- (end-time . ,(if (string? end_time)
- (match (strptime "%F %T" end_time)
- ((parts . _) parts))
- #f)))))))
- (sqlite-reset statement)
-
- result)))))
+ (match (sqlite-step-and-reset statement)
+ (#(uuid derivation_name priority processed canceled
+ created_at end_time)
+ `((uuid . ,uuid)
+ (derivation-name . ,derivation_name)
+ (priority . ,priority)
+ (processed . ,(cond
+ ((= 0 processed) #f)
+ ((= 1 processed) #t)
+ (else
+ (error "unknown processed value"))))
+ (canceled . ,(cond
+ ((= 0 canceled) #f)
+ ((= 1 canceled) #t)
+ (else
+ (error "unknown canceled value"))))
+ (created-at . ,(if (string? created_at)
+ (match (strptime "%F %T" created_at)
+ ((parts . _) parts))
+ #f))
+ (end-time . ,(if (string? end_time)
+ (match (strptime "%F %T" end_time)
+ ((parts . _) parts))
+ #f)))))))))
(define-method (datastore-list-builds
(datastore <sqlite-datastore>)
@@ -2348,18 +2306,15 @@ SELECT id FROM tags WHERE key = :key"
#:key key
#:value value)
- (let ((result (match (sqlite-step statement)
- (#(id)
- (simple-format
- #f "tag_string ~A '%,~A,%'"
- (if not?
- "NOT LIKE"
- "LIKE")
- id))
- (#f #f))))
- (sqlite-reset statement)
-
- result))
+ (match (sqlite-step-and-reset statement)
+ (#(id)
+ (simple-format
+ #f "tag_string ~A '%,~A,%'"
+ (if not?
+ "NOT LIKE"
+ "LIKE")
+ id))
+ (#f #f)))
(key
(sqlite-bind-arguments key-statement
#:key key)
@@ -2614,16 +2569,12 @@ WHERE build_id = :build_id"
statement
#:build_id (db-find-build-id db build-uuid))
- (let ((result
- (match (sqlite-step statement)
- (#(agent_id result failure_reason)
- `((agent_id . ,agent_id)
- (result . ,result)
- (failure_reason . ,failure_reason)))
- (#f #f))))
- (sqlite-reset statement)
-
- result)))))
+ (match (sqlite-step-and-reset statement)
+ (#(agent_id result failure_reason)
+ `((agent_id . ,agent_id)
+ (result . ,result)
+ (failure_reason . ,failure_reason)))
+ (#f #f))))))
(define-method (datastore-find-build-derivation-system
(datastore <sqlite-datastore>)
@@ -2646,18 +2597,14 @@ WHERE builds.id = :build_id"
statement
#:build_id (db-find-build-id db build-uuid))
- (let ((system
- (match (sqlite-step statement)
- (#(system) system)
- (#f
- (error
- (simple-format
- #f
- "no system for build ~A"
- build-uuid))))))
- (sqlite-reset statement)
-
- system)))))
+ (match (sqlite-step-and-reset statement)
+ (#(system) system)
+ (#f
+ (error
+ (simple-format
+ #f
+ "no system for build ~A"
+ build-uuid))))))))
(define-method (datastore-list-builds-for-output
(datastore <sqlite-datastore>)
@@ -2783,12 +2730,8 @@ WHERE derivations.name = :derivation"
statement
#:derivation derivation)
- (let ((result
- (match (sqlite-step statement)
- (#(x) x))))
- (sqlite-reset statement)
-
- result)))))
+ (match (sqlite-step-and-reset statement)
+ (#(x) x))))))
rest))
(define-method (datastore-update
@@ -2978,24 +2921,20 @@ ORDER BY deferred_until ASC
LIMIT 1"
#:cache? #t)))
- (let ((result
- (match (sqlite-step statement)
- (#(uuid derivation_name priority created_at deferred_until)
- `((uuid . ,uuid)
- (derivation-name . ,derivation_name)
- (priority . ,priority)
- (created-at . ,(if (string? created_at)
- (string->date created_at
- "~Y-~m-~d ~H:~M:~S")
- #f))
- (deferred-until . ,(if (string? deferred_until)
- (string->date deferred_until
- "~Y-~m-~d ~H:~M:~S")
- #f))))
- (#f #f))))
- (sqlite-reset statement)
-
- result)))))
+ (match (sqlite-step-and-reset statement)
+ (#(uuid derivation_name priority created_at deferred_until)
+ `((uuid . ,uuid)
+ (derivation-name . ,derivation_name)
+ (priority . ,priority)
+ (created-at . ,(if (string? created_at)
+ (string->date created_at
+ "~Y-~m-~d ~H:~M:~S")
+ #f))
+ (deferred-until . ,(if (string? deferred_until)
+ (string->date deferred_until
+ "~Y-~m-~d ~H:~M:~S")
+ #f))))
+ (#f #f))))))
(define-method (datastore-fetch-prioritised-unprocessed-builds
(datastore <sqlite-datastore>))
@@ -3060,8 +2999,7 @@ VALUES (:event, :arguments)"
(lambda (port)
(write arguments port))))
- (sqlite-step statement)
- (sqlite-reset statement))
+ (sqlite-step-and-reset statement))
#t)
(define-method (datastore-count-unprocessed-hook-events
@@ -3140,17 +3078,13 @@ WHERE id = :id"
statement
#:id id)
- (let ((result
- (match (sqlite-step statement)
- (#f #f)
- (#(event arguments)
- (list (string->symbol event)
- (call-with-input-string arguments
- (lambda (port)
- (read port))))))))
- (sqlite-reset statement)
-
- result)))))
+ (match (sqlite-step-and-reset statement)
+ (#f #f)
+ (#(event arguments)
+ (list (string->symbol event)
+ (call-with-input-string arguments
+ (lambda (port)
+ (read port))))))))))
(define-method (datastore-delete-unprocessed-hook-event
(datastore <sqlite-datastore>)
@@ -3169,8 +3103,7 @@ DELETE FROM unprocessed_hook_events WHERE id = :id"
statement
#:id id)
- (sqlite-step statement)
- (sqlite-reset statement))))
+ (sqlite-step-and-reset statement))))
#t)
(define-method (datastore-count-build-allocation-plan-entries
@@ -3424,14 +3357,12 @@ WHERE build_derivation_outputs.derivation_id = :derivation_id
#:agent_id agent-id
#:derivation_id derivation-id)
- (let ((result (sqlite-step output-conflicts-statement)))
- (sqlite-reset output-conflicts-statement)
-
- (if (eq? #f result)
- `((uuid . ,uuid)
- (derivation_name . ,derivation-name)
- (derived_priority . ,derived_priority))
- (loop (sqlite-step statement))))))))
+ (if (eq? (sqlite-step-and-reset output-conflicts-statement)
+ #f)
+ `((uuid . ,uuid)
+ (derivation_name . ,derivation-name)
+ (derived_priority . ,derived_priority))
+ (loop (sqlite-step statement)))))))
(sqlite-bind-arguments
statement
@@ -3615,13 +3546,9 @@ WHERE build_results.build_id = :build_id"
statement
#:build_id (db-find-build-id db build-uuid))
- (let ((result
- (match (sqlite-step statement)
- (#(agent-id) agent-id)
- (#f #f))))
- (sqlite-reset statement)
-
- result)))))
+ (match (sqlite-step-and-reset statement)
+ (#(agent-id) agent-id)
+ (#f #f))))))
(define* (db-open database
#:key (write? #t))
@@ -3676,13 +3603,9 @@ WHERE build_results.build_id = :build_id"
db
"SELECT changes();"
#:cache? #t)))
- (let ((count
- (vector-ref (sqlite-step statement)
- 0)))
-
- (sqlite-reset statement)
- count)))
+ (vector-ref (sqlite-step-and-reset statement)
+ 0)))
(define (last-insert-rowid db)
(let ((statement
@@ -3690,13 +3613,9 @@ WHERE build_results.build_id = :build_id"
db
"SELECT last_insert_rowid();"
#:cache? #t)))
- (let ((id
- (vector-ref (sqlite-step statement)
- 0)))
-
- (sqlite-reset statement)
- id)))
+ (vector-ref (sqlite-step-and-reset statement)
+ 0)))
(define (select-derivation-outputs db derivation-name)
(let ((statement
@@ -3731,13 +3650,9 @@ SELECT id FROM derivations WHERE name = :name"
statement
#:name name)
- (let ((result
- (match (sqlite-step statement)
- (#f #f)
- (#(id) id))))
- (sqlite-reset statement)
-
- result)))
+ (match (sqlite-step-and-reset statement)
+ (#f #f)
+ (#(id) id))))
(define (db-find-derivation db name)
(let ((statement
@@ -3755,18 +3670,14 @@ WHERE name = :name"
statement
#:name name)
- (let ((result
- (match (sqlite-step statement)
- (#f #f)
- (#(system fixed_output)
- `((system . ,system)
- (fixed-output? . ,(cond
- ((= fixed_output 0) #f)
- ((= fixed_output 1) #t)
- (else fixed_output))))))))
- (sqlite-reset statement)
-
- result)))
+ (match (sqlite-step-and-reset statement)
+ (#f #f)
+ (#(system fixed_output)
+ `((system . ,system)
+ (fixed-output? . ,(cond
+ ((= fixed_output 0) #f)
+ ((= fixed_output 1) #t)
+ (else fixed_output))))))))
(define-method (datastore-find-derivation
(datastore <sqlite-datastore>)
@@ -3949,13 +3860,9 @@ WHERE name = :name"
statement
#:name derivation-name)
- (let ((system
- (match (sqlite-step statement)
- (#f #f)
- (#(system) system))))
- (sqlite-reset statement)
-
- system)))))
+ (match (sqlite-step-and-reset statement)
+ (#f #f)
+ (#(system) system))))))
(define-method (datastore-find-derivation-inputs
(datastore <sqlite-datastore>)
@@ -4034,13 +3941,9 @@ WHERE derivation_outputs.output_id = :output_id
#:derivation_id (db-find-derivation-id db start-derivation-name)
#:output_id (db-output->output-id db output))
- (let ((result
- (match (sqlite-step statement)
- (#f #f)
- (#(derivation) derivation))))
- (sqlite-reset statement)
-
- result)))))
+ (match (sqlite-step-and-reset statement)
+ (#f #f)
+ (#(derivation) derivation))))))
(define (db-insert-system db system)
(let ((statement
@@ -4053,11 +3956,8 @@ INSERT INTO systems (system) VALUES (:system)"
statement
#:system system)
- (sqlite-step statement)
- (let ((id (last-insert-rowid db)))
- (sqlite-reset statement)
-
- id)))
+ (sqlite-step-and-reset statement)
+ (last-insert-rowid db)))
(define (db-system->system-id db system)
(let ((statement
@@ -4070,12 +3970,9 @@ SELECT id FROM systems WHERE system = :system"
statement
#:system system)
- (match (sqlite-step statement)
+ (match (sqlite-step-and-reset statement)
(#f #f)
- (#(id)
- (sqlite-reset statement)
-
- id))))
+ (#(id) id))))
(define (db-system-id->system db system-id)
(let ((statement
@@ -4088,12 +3985,9 @@ SELECT system FROM systems WHERE id = :id"
statement
#:id system-id)
- (match (sqlite-step statement)
+ (match (sqlite-step-and-reset statement)
(#f #f)
- (#(id)
- (sqlite-reset statement)
-
- id))))
+ (#(id) id))))
(define (insert-derivation-and-return-outputs db derivation)
(define derivation-name
@@ -4111,8 +4005,7 @@ UPDATE derivations SET fixed_output = :fixed_output WHERE name = :name"
(sqlite-bind-arguments statement
#:name derivation-name
#:fixed_output (if fixed-output? 1 0))
- (sqlite-step statement)
- (sqlite-reset statement)))))
+ (sqlite-step-and-reset statement)))))
(define (insert-derivation)
(let ((statement
@@ -4133,8 +4026,7 @@ INSERT INTO derivations (name, system_id, fixed_output)
(db-insert-system db system)))
#:fixed_output (if (fixed-output-derivation? derivation) 1 0))
- (sqlite-step statement)
- (sqlite-reset statement)
+ (sqlite-step-and-reset statement)
(last-insert-rowid db)))
@@ -4204,8 +4096,7 @@ VALUES (:derivation_id, :derivation_output_id)"
statement
#:derivation_id derivation-id
#:derivation_output_id derivation-output-id)
- (sqlite-step statement)
- (sqlite-reset statement))
+ (sqlite-step-and-reset statement))
derivation-output-ids)))))
(define (db-insert-output db output)
@@ -4218,11 +4109,9 @@ INSERT INTO outputs (output) VALUES (:output)"
(sqlite-bind-arguments statement #:output output)
- (sqlite-step statement)
- (let ((id (last-insert-rowid db)))
- (sqlite-reset statement)
+ (sqlite-step-and-reset statement)
- id)))
+ (last-insert-rowid db)))
(define (db-output->output-id db output)
(let ((statement
@@ -4234,12 +4123,9 @@ SELECT id FROM outputs WHERE output = :output"
(sqlite-bind-arguments statement #:output output)
- (let ((result (match (sqlite-step statement)
- (#f #f)
- (#(id) id))))
- (sqlite-reset statement)
-
- result)))
+ (match (sqlite-step-and-reset statement)
+ (#f #f)
+ (#(id) id))))
(define (insert-derivation-outputs db derivation-id derivation-outputs)
(define output-has-successful-build?
@@ -4282,8 +4168,7 @@ INSERT OR IGNORE INTO unbuilt_outputs (output_id) VALUES (:output_id)"
(sqlite-bind-arguments statement
#:output_id output-id)
- (sqlite-step statement)
- (sqlite-reset statement)
+ (sqlite-step-and-reset statement)
#t)))
(let ((derivation-outputs-with-ids
@@ -4321,8 +4206,7 @@ VALUES (:derivation_output_id, :hash_algorithm, :hash, :recursive)"
#:derivation_id derivation-id
#:name name
#:output_id output-id)
- (sqlite-step statement)
- (sqlite-reset statement)
+ (sqlite-step-and-reset statement)
(let ((derivation-output-id
(last-insert-rowid db)))
@@ -4339,8 +4223,7 @@ VALUES (:derivation_output_id, :hash_algorithm, :hash, :recursive)"
1
0))
- (sqlite-step output-details-statement)
- (sqlite-reset output-details-statement)
+ (sqlite-step-and-reset output-details-statement)
(cons name derivation-output-id))))
derivation-outputs-with-ids
@@ -4379,11 +4262,8 @@ RETURNING id"
(lambda (date)
(date->string date "~1 ~3"))))
- (match (sqlite-step statement)
- (#(id)
- (sqlite-reset statement)
-
- id))))
+ (match (sqlite-step-and-reset statement)
+ (#(id) id))))
(define (increment-builds-counts db system-id)
(let ((statement
@@ -4406,17 +4286,14 @@ INSERT INTO builds_counts (system_id, count) VALUES (:system_id, 1)"
statement
#:system_id system-id)
- (match (let ((res (sqlite-step statement)))
- (sqlite-reset statement)
- res)
+ (match (sqlite-step-and-reset statement)
(#(count) #t)
(#f
(sqlite-bind-arguments
insert-statement
#:system_id system-id)
- (sqlite-step insert-statement)
- (sqlite-reset insert-statement)
+ (sqlite-step-and-reset insert-statement)
#t))))
@@ -4441,12 +4318,9 @@ LIMIT 1"
statement
#:build_id build-id)
- (let ((result (match (sqlite-step statement)
- (#f #t)
- (#(1) #f))))
- (sqlite-reset statement)
-
- result)))
+ (match (sqlite-step-and-reset statement)
+ (#f #t)
+ (#(1) #f))))
(define (insert-unprocessed-builds-with-derived-priorities-entry
db
@@ -4467,8 +4341,7 @@ VALUES (:build_id, :derived_priority, :all_inputs_built)"
#:derived_priority derived-priority
#:all_inputs_built (if all-inputs-built? 1 0))
- (sqlite-step statement)
- (sqlite-reset statement)))
+ (sqlite-step-and-reset statement)))
(apply
(lambda* (uuid drv-name priority defer-until
@@ -4527,8 +4400,7 @@ VALUES (:id, :name, :description)"
#:name name
#:description description)
- (sqlite-step statement)
- (sqlite-reset statement)))
+ (sqlite-step-and-reset statement)))
(define (insert-agent-password db uuid password)
(let ((statement
@@ -4544,5 +4416,4 @@ VALUES (:agent_id, :password)"
#:agent_id uuid
#:password password)
- (sqlite-step statement)
- (sqlite-reset statement)))
+ (sqlite-step-and-reset statement)))