-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jean-Christophe Deschamps wrote:
> I feel the need to wrap an SQLite printf-like function into a scalar 
> function.

You can just do that sort of thing in your application.  There is no need to
do it via a SQL function.

> My question is slightly off topic but there are experienced users here 
> who have probably done it before.

You can retrieve any value as any type.  For example if an integer is
returned but you call column_text then it will be converted to text for you.

> In the scalar function (printf), I get arguments as the usual array of 
> pointers. How would you pass the variable list arguments to 
> sqlite3_mprintf()?
> Is there any nice way not imposing a limitation on n?

This kind of thing is extra-ordinarily tricky under C, error prone, easy to
crash and usually non-portable.  This is how you receive a variable number
of arguments:

  http://en.wikipedia.org/wiki/Stdarg.h

sqlite3_vmprintf can receive that.  GCC can do some variable argument
calling but not really useful here:

  http://gcc.gnu.org/onlinedocs/gcc/Constructing-Calls.html

But what you are really trying to do is take an arbitrary number of
parameters, unwrap them from SQLite types into native types and then compose
a call to sqlite3_mprintf.  The only way this is directly possible is using
a library that can do this for you at runtime which pretty much means this one:

  http://en.wikipedia.org/wiki/Libffi

You really don't want to go down this route.  If you do then you really
don't want to use C.  As an example your requirement is trivial to do in
Python - it would be a one liner using either wrapper.

Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkrfi+sACgkQmOOfHg372QTuhwCg3rYnGnuFi5SJexL4rpF+N09d
DvcAoMFzJymLEnTY2CQl0juFMQdoW+Y7
=jL1v
-----END PGP SIGNATURE-----
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to