|
From: | John Cowan |
Subject: | Re: How best to get a default result from sqlite3, or to use or not use first-result? |
Date: | Wed, 8 Jun 2022 19:25:33 -0400 |
The problem: retrieve one value from a query, if there is no matching
row return a default.
Method 1: use for-each-row, overwrite the default with found values
Method 2: use first-result, on exception return the default
Method 3: use fold-row (wasn't an option when I first wrote the code)
My question is, which of these is the "right" way to do what I want? Is
there another, better, way? Note that method #2 has problems in my
program but it might be due to my using chicken 4.10 (for now).
==additional details==
Method 1, for-each-row, was my original approach and seemed to work
fine.
Then, in the midst of a major rewrite I tried to use first-result. It
seemed odd to me to use an exception this way but I assumed (wrongly?)
it was a fancy software engineery way to do things since the sqlite3
egg did not provide any direct way to do what I want.
However I hit a strange scalability issue with database locks happening
only a few hours into a run. After a lot of fruitless debug and on a
hunch, I replaced the first-result with a for-each-row and now am able
to run ten of thousands of tests over many hours (still not perfect,
work progresses).
I plan to replace use of for-each-row with something like:
(define (get-id db name default)
(fold-row (lambda (row)
(car row))
#f
db "SELECT id FROM tests WHERE testname=?" name))
Thanks.
[Prev in Thread] | Current Thread | [Next in Thread] |