Subject | Re: The length of a VARCHAR in a UDF |
---|---|
Author | lutterot |
Post date | 2008-12-24T00:17:24Z |
--- In firebird-support@yahoogroups.com, "Ivan Prenosil"
<Ivan.Prenosil@...> wrote:
How can I get the parameter as a VRACHAR and not CHAR?
Cheers,
Christof
<Ivan.Prenosil@...> wrote:
>length
> > I am trying to get the length of a VARCHAR in a UDF that receives the
> > VARCHAR by descriptor using Firebird 2.1.1. From other UDF source code
> > (e.g. fbudf.cpp) I thought the following would work:
> >
> > DECLARE EXTERNAL FUNCTION MY_UDF
> > VARCHAR(32765) BY DESCRIPTOR
> > RETURNS ...etc
> >
> > #include "ibase.h"
> >
> > char* my_udf(PARAMDSC* par)
> > {
> > if(!par || (par->dsc_flags & DSC_null)) return NULL;
> >
> > PARAMVARY* value = (PARAMVARY*) par->dsc_address;
> > unsigned short length = value->vary_length; // <- the varchar
> >Thanks!
> > // ...
> > }
> >
> > However, it looks as if the varchar string seems to start at address
> > value (i.e. par->dsc_address), not at value->vary_string (which should
> > be par->dsc_address+2). The following seems to work:
> >
> > char* my_udf(PARAMDSC* par)
> > {
> > if(!par || (par->dsc_flags & DSC_null)) return NULL;
> >
> > unsigned short length = par->dsc_length; // <- the varchar length
> >
> > // ...
> > }
> >
>
> It is because your actual parameter is CHAR, not VARCHAR.
How can I get the parameter as a VRACHAR and not CHAR?
Cheers,
Christof