Re: user-func and char datatype
Posted in 1998
Philipp Gruenig (gruenig@tecnosoft.ch) wrote:
: I use already some c-user-functions, but none with char manipulations.
: Only long,Integer manipulation.
1. Upgrade to 9.14. Lots of bug fixes.
2. Check out the examples in the dbdk directory. The basic idea is
that the DataBlade API supports a structure called a mi_lvarchar.
This type has a number of SAPI functions defined for it.
(mi_lvarchar_to_string())
3. The ORDBMS passes string instances around as pointers to these
structures. i.e.
mi_lvarchar *
AddHello (
mi_lvarchar * plvArg,
MI_FPARAM * pfParam
)
{
mi_string * pchBuf;
pchBuf = (mi_string *)mi_alloc(mi_varlen(plvArg) + strlen("Hello "));
sprintf(pchBuf, "Hello %s", mi_lvarchar_to_string(plvArg);
/*
** NOTE: mi_lvarchar_to_string() returns a pointer to a null-terminated
** char array, which is what you expect in 'C'.
*/
return (mi_string_to_lvarchar(pchBuf));
}
Compile in the usual Blade way. The CREATE uses lvarchar as a the arg.
CREATE FUNCTION AddHello( lvarchar )
RETURNING lvarchar
WITH ( not variant )EXTERNAL NAME "$INFORMIXDIR/extend/hello/bin/hello.bld(AddHello)"
LANGUAGE C;
The:
SELECT AddHEllo(E.Nam) FROM Emps;