You can't call sqlite3_aggregate_context() in a non-aggregate function.
However, there *are* a couple of other things you can do.
(1) All forms of sqlite3_create_function() take as 5th argument a void
pointer to an arbitrary user data structure. This data structure can be
accessed in a regular user-defined function by calling
sqlite3_user_data(). The difficultly with this approach is initializing
this information for a scan. There are a number of approaches you could
take there. One possibility is to pass the same argument in as user
data into sqlite3_set_authorizer(), and have your authorizer function
clear it whenever a SELECT is checked.
(2) You can associate data with an argument to a regular user-defined
function using sqlite3_set_auxdata() and sqlite3_get_auxdata() as long
as the value of the argument is static. If you don't normally have a
static argument to your function, you can add one (say a string
'MAVG'). I actually used this approach with some application generated
SQL in my current project at one point.
Best regards,
Peter
On 2/13/2012 7:48 AM, Steinar Midtskogen wrote:
Hello
Is it possible to have a context for a custom SQL function that is NOT
an aggregate function? It might sound silly, but if a SELECT
statement with this function causes the function to be called in a
defined order (as with the step function of an aggregate function),
this can be useful to calculate the moving average. That is, in its
simplest form, to return the average of the N last values.
sqlite spiral to a crash if I call sqlite3_aggregate_context() when I
don't have a finalise function.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users