Today I published a revamped version of the plugin, still at:
https://github.com/abiliojr/sqlite-lua.

This version allows the user to define a function. For example, cosine
function would be defined like:

SELECT createlua('cos', 'return math.cos(arg[1])');

After that, the function cos is available for general use, like a regular
SQLite function:

CREATE TABLE t(angle NUMERIC);
INSERT INTO t(angle) VALUES (0),(1.571),(3.1416);

SELECT cos(angle) FROM t;




On Wed, Aug 26, 2015 at 11:33 AM, Nelson, Erik - 2 <
erik.l.nelson at bankofamerica.com> wrote:

> Abilio Marques wrote on Sunday, August 23, 2015 4:42 PM
> >
> > 3. Lua can return arrays. Also, Lua can return multiple values. Tried
> > to take advantage of those facts, but while reading the SQLite API
> > documentation, found no function where I could map multiple values as
> > the return of a function. Am I wrong? For example:
> >
> > select * from table t where fieldA in (lua('return 1,2,3'));
> >
> > Could be a useful feat in real scripts with real code.
>
> Something that I've done that's similar-but-different is to use a C
> preprocessor to preprocess the query, evaluating the Lua prior to the query
> being prepared in sqlite.
>
> In that case (slightly adapted from your example, assuming a lua function
> named 'csv')
>
> select * from table t where fieldA in (lua('return csv(1,2,3)'));
>
> resolves to
>
> select * from table t where fieldA in (1,2,3);
>
> that's still a single return value, but the ability to programmatically
> manipulate the query prior to execution has been useful to me, particularly
> being able to write things like
>
> select * from lua('most_recent_table()') t where fieldA in (1,2,3);
>
> or
>
> attach database lua('get_right_dbfile()') as "db1";
>
> assuming that LuaSqlite3 is available, the Lua functions can inspect the
> database in order to implement their logic.  LuaFileSystem can be useful as
> well.
>
> ----------------------------------------------------------------------
> This message, and any attachments, is for the intended recipient(s) only,
> may contain information that is privileged, confidential and/or proprietary
> and subject to important terms and conditions available at
> http://www.bankofamerica.com/emaildisclaimer.   If you are not the
> intended recipient, please delete this message.
> _______________________________________________
> sqlite-users mailing list
> sqlite-users at mailinglists.sqlite.org
> http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
>

Reply via email to