On 2019/02/18 12:06 PM, Arun - Siara Logics (cc) wrote:
Yes it is possible, but then your UDF is unlikely to be *Deterministic*.
By design, I intend to make sure that for any given input the function always
returns the same value.
If the dependent rows are missing or change over time, then it would be an
error condition.
What Dominique referred to is not so much the your intent, but an actual
specification on a UDF (when added) to let the query planner know it is
Deterministic or not, simply informing the QP that: "If you have
computed me once for f(x) --> y then for every next same value of x you
will always receive the same value of y, so that you can assume the
output and need not call me again."
This is undesirable if the function needs to log something, for
instance, or if the value of f(x) --> y over time can change for the
same values of x. Non-deterministic functions are obviously slower in
large queries, but there is nothing wrong with it, you CAN do it -
Dominic simply pointed out that what you wish to do implies
non-determinism (though you can force it otherwise if you can guarantee
conformance and the consequences are acceptable, as it would seem from
your explanation).
Is there an API to read a table row using RowID? Or should I traverse the
BTree pages using my own code? Thanks!
You should use a query and the standard API. This is pretty
straight-forward and conforms to the most basic use of the SQLite API
(no real need for examples). It probably goes without saying, but you
need to obviously get and release all used API resources within your
UDF, regardless of error conditions.
Note that in a transaction without WAL mode (and enabled/disabled
READ_UNCOMMITTED) your query may or may not "see" data that is older, at
least from before any current transaction(s) - which can be made to play
exactly into your hand by controlling said journal mode. The question
you need to answer is - will you be controlling the Journal mode?
Cheers!
Ryan
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users