Subject | The length of a VARCHAR in a UDF |
---|---|
Author | lutterot |
Post date | 2008-12-23T23:06:51Z |
Hi!
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 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 this how it should be? Is the struct PARAMVARY deprecated?
Cheers,
Christof
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 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 this how it should be? Is the struct PARAMVARY deprecated?
Cheers,
Christof