Subject | Re: [firebird-support] The length of a VARCHAR in a UDF |
---|---|
Author | Ivan Prenosil |
Post date | 2008-12-24T00:12:36Z |
> I am trying to get the length of a VARCHAR in a UDF that receives theIt is because your actual parameter is CHAR, not VARCHAR.
> 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 length
>
> // ...
> }
>
> 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
>
> // ...
> }
>
> Is the struct PARAMVARY deprecated?No.
Ivan