[sqlite] Virtual tables and table-valued functions

2015-12-05 Thread Charles Leifer
In working on a Python wrapper around virtual tables, I thought it might be
beneficial if SQLite provided an official C API for creating simple
table-valued functions. The wrapper could build on the existing virtual
table APIs and would consist of:

* user supplied list of parameters, which would be converted to HIDDEN
columns in a virtual table.
* user supplied list of column names, which would constitute the return
values of the table-valued function
* user supplied initialization function which would accept the parameters
passed, i.e. SELECT * FROM user_func(p1, p2, p3), the init function would
receive (p1, p2, p3).
* user supplied iterate function which would accept a zero-based index and
a result context, returning 1 to indicate EOF and 0 to indicate more
results exist.

I think this might lead to a larger ecosystem of quality open-source
table-valued functions. Given the fact that creating even a simple vtable
is cumbersome, providing an API that required the bare minimum seems like a
good idea to me.

Thoughts?

PS if you're curious about the Python wrapper, I posted on it a day or two
ago.


[sqlite] Virtual tables and table-valued functions

2015-12-12 Thread E.Pasma
6 dec 2015, Charles Leifer:

> In working on a Python wrapper around virtual tables, I thought it  
> might be
> beneficial if SQLite provided an official C API for creating simple
> table-valued functions. The wrapper could build on the existing  
> virtual
> table APIs and would consist of:
>
> * user supplied list of parameters, which would be converted to HIDDEN
> columns in a virtual table.
> * user supplied list of column names, which would constitute the  
> return
> values of the table-valued function
> * user supplied initialization function which would accept the  
> parameters
> passed, i.e. SELECT * FROM user_func(p1, p2, p3), the init function  
> would
> receive (p1, p2, p3).
> * user supplied iterate function which would accept a zero-based  
> index and
> a result context, returning 1 to indicate EOF and 0 to indicate more
> results exist.
>
> I think this might lead to a larger ecosystem of quality open-source
> table-valued functions. Given the fact that creating even a simple  
> vtable
> is cumbersome, providing an API that required the bare minimum seems  
> like a
> good idea to me.
>
> Thoughts?
>
> PS if you're curious about the Python wrapper, I posted on it a day  
> or two
> ago.
One thought that is only a change in the current class, is to have a  
default xBestIndex method. This would just optimize for plans with the  
highest number of usable parameter values, starting from number 1..  
The function may then become optional. In xFIlter the number of  
parameters is still available from the argc argument.
The xBestIndex is rather verbose and it looks that in most cases it  
should do just the above.