2017-11-17 13:51 GMT+01:00 Peter Da Silva <[email protected]>:
> Sqlite will perform the substitution of Tcl variables in a query. You can
> flag the variable with a ‘$’ or with a ‘:’ (which makes it more like other
> SQL APIs).
>
Yes, I found that. The disadvantage is that you have to have a variable
with the correct name, but I do not mind.
>
> So you can write:
>
> $db eval {
> SELECT Tea
> FROM teaInStock
> ORDER BY LastUsed DESC
> LIMIT :nrToFetch;
> } {
> ...
> }
>
I always want to define my queries in one place. So I have:
proc getTeaList {{limitNr 5}} {
global getTeasToDrinkStr
set teaList []
db eval ${getTeasToDrinkStr} {
And the definition:
set getTeasToDrinkStr "
SELECT *
FROM (
SELECT *
, abs(random()) / CAST(1.4E18 AS INTEGER) AS Randomiser
FROM teaInStock
ORDER BY LastUsed
)
ORDER BY randomiser + IFNULL(JULIANDAY(LastUsed), 0) ASC
LIMIT :limitNr
"
--
Cecil Westerhof
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users