Serge Rielau wrote:
Maybe hooking up a LISP interpreter would be the easiest...
Cheers
Serge
PS: This goes way beyond "duck-typing" as I know it....
Actually, there is a quite simple way to do that with an external UDF. The
following (untested) C code is still missing proper error/NULL handling and
it assumes that "bc" is installed at the DB2 server.
void SQL_API_FN calculator(
SQLUDF_VARCHAR *formula,
SQLUDF_DOUBLE *result,
SQLUDF_NULLIND *formula_ind,
SQLUDF_NULLIND *result_ind,
SQLUDF_TRAIL_ARGS)
{
FILE *pipe = NULL;
char str[1000] = { '\0' };
sprintf(command, "echo \"%s\" | bc", formula);
pipe = popen("bc", "r");
fgets(str, sizeof str, pipe);
pclose(pipe);
*result = strtod(str);
*result_ind = 0;
}
Use this as entry point for an external UDF with a VARCHAR(980) as input
parameter and returning a DOUBLE. You can choose whichever maximum length
suits you - just adjust the size of the char array in the C code.
--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany