On Fri, Mar 7, 2014 at 11:51 PM, Dominique Devienne <ddevie...@gmail.com> wrote: > > basically register_function('rpad', 'x', 'y', 'printf(''%-*s'', y, > x)') would register a 2-arg function (register_function's argc-2) > named $argv[0], which executes the following statement > > with args($argv[1], $argv[2], ... $argv[argc-2]) as (VALUES(?, ?)) > select $argv[argc-1) from args; >
Dominique, your variant is even better than using numbered parameters. If you use named ones supported by sqlite (:VVV) then sqlite will do the job of the textual replacement with bind api itself ( 'printf(''%-*s'', :y,> :x)' ) The small problem in this case is that there are two ways (times) to check whether named parameter exists in the expression. Either when the registered function executed (and report error about lacking some parameters only here) or make a test call with some test parameters at the time of registration. The latter allows revealing errors earlier, but it has no knowledge about the expression so might fire strange run-time errors (division by zero etc). If we omit execution and leave only binding, we might miss the case when not all binding variables mentioned in the expression, actually provided (example ... 'somefunc', 'x', 'y', ':x + :y + :z') Max _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users