On Thu, 6 Mar 2014 22:41:31 -0500 Gabor Grothendieck <ggrothendi...@gmail.com> wrote:
> On Thu, Mar 6, 2014 at 8:41 PM, RSmith <rsm...@rsweb.co.za> wrote: > > > > On 2014/03/07 01:59, Gabor Grothendieck wrote: > >> > >> > >>> > >>>> > >>>>> A small enhancement request: > >>>>> > >>>>> It would be great if the RPAD and LPAD functions could be > >>>>> implemented in > >>>>> sqlite. > >>>>> > >>>> The SQLite you can get the effect of RPAD(x,y) using PRINTF > >>>> ('%-*s',y,x). See > >>>> http://www.sqlite.org/lang_corefunc.html#printf for details. > >>> > >>> Thanks, but you snipped the relevant part of my post: > >>> "I know I can easily achieve the equivalent ... but if the > >>> functions were available natively it would avoid the need to hack > >>> third party SQL scripts." > >>> > >> I have also found that it was tedious to retarget MySQL scripts to > >> SQLite because many of the function calls are different. Its not > >> just rpad and lpad but other functions too. > > > > > > Speaking as someone who retargets (nice word btw.) SQL scripts > > often, yes I agree, it's a bit of a chore to retarget SQL scripts > > to SQLite sometimes, but not really moreso than retargeting a > > script from MSSQL to PostGres or > > I have also retargeted MySQL scripts to H2 and it was easier than to > SQLite. Creating extensions in SQLite is not difficult nor hard. You can define yours with this line: sqlite3_create_function(db, "RPAD", SQLITE_UTF8, SQLITE_ANY||SQLITE_DETERMINISTIC, 0, sqlcmd_rpad, 0, 0); And create your function with: static void sqlcmd_rpad(sqlite3_context *context, int argc,sqlite3_value **argv){ // argc has number of parameters in **argv // parse them as you do within C main // sqlite3_result_text(context, char_to_return, length_char_to_return, SQLITE_TRANSIENT); } Some weeks ago, there was a mail collecting several sites where find usefule functions && extensions. HTH --- --- Eduardo Morras <emorr...@yahoo.es> _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users