Re: [sqlite] Function context

2012-02-13 Thread Steinar Midtskogen
[Simon Slavin] > On 13 Feb 2012, at 7:51pm, Steinar Midtskogen wrote: > >> One should think that the ability to calculate a moving average would >> be a pretty common request. But people do it in their application >> code instead? > > Actually, my expectation is the other way. I'm continually su

Re: [sqlite] Function context

2012-02-13 Thread Marc L. Allen
> More generally, I *often* see good C++ programmers pushing application > logic into SQL, and getting it wrong because they don't really know > SQL. As a result, my rule of thumb is to make the separation between > application code and SQL code based on whether the code is filtering > result sets

Re: [sqlite] Function context

2012-02-13 Thread Scott Hess
On Mon, Feb 13, 2012 at 12:28 PM, Simon Slavin wrote: > On 13 Feb 2012, at 7:51pm, Steinar Midtskogen wrote: >> One should think that the ability to calculate a moving average would >> be a pretty common request.  But people do it in their application >> code instead? > > Actually, my expectation

Re: [sqlite] Function context

2012-02-13 Thread Marc L. Allen
> Actually, my expectation is the other way. I'm continually surprised > by posts on this list that people expect to be able to use SQLite with > no external programming at all. I often see complicated compound JOIN > and sub-SELECT SQL commands here which can be replaced by four lines in > any p

Re: [sqlite] Function context

2012-02-13 Thread Scott Hess
On Mon, Feb 13, 2012 at 11:51 AM, Steinar Midtskogen wrote: > [Scott Hess] >> Unfortunately, I can't offhand think of a reasonable solution for you, >> I think I'd just use the SELECT to generate the data, while >> calculating the moving average in my application code. > > Yes, but that reduces sq

Re: [sqlite] Function context

2012-02-13 Thread Simon Slavin
On 13 Feb 2012, at 7:51pm, Steinar Midtskogen wrote: > One should think that the ability to calculate a moving average would > be a pretty common request. But people do it in their application > code instead? Actually, my expectation is the other way. I'm continually surprised by posts on thi

Re: [sqlite] Function context

2012-02-13 Thread Steinar Midtskogen
[Scott Hess] > I think you're making unwarranted assumptions about the order your > custom function will be called. Even if you added "ORDER BY" to the > end of the query, that wouldn't necessarily order the calls to your > custom function. Even if you find a workaround which allows you to > imp

Re: [sqlite] Function context

2012-02-13 Thread Scott Hess
On Mon, Feb 13, 2012 at 9:24 AM, Steinar Midtskogen wrote: > [Peter Aronson] >> (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 >

Re: [sqlite] Function context

2012-02-13 Thread Peter Aronson
cial answer.  I aggree that the documentation isn't very clear. Best regards, Peter From: Steinar Midtskogen To: General Discussion of SQLite Database Sent: Mon, February 13, 2012 10:24:56 AM Subject: Re: [sqlite] Function context [Peter Aronson] > (2)

Re: [sqlite] Function context

2012-02-13 Thread Steinar Midtskogen
[Peter Aronson] > (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

Re: [sqlite] Function context

2012-02-13 Thread Peter Aronson
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 regul

[sqlite] Function context

2012-02-13 Thread Steinar Midtskogen
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 ca