Subject Re: [firebird-support] reading varchar length via API
Author Dimitry Sibiryakov
On 20 Aug 2003 at 1:33, Francesco Lamonica wrote:

>isc_dsql_prepare(status_vector,&trans,&stmt,0,query,1,NULL);
>isc_dsql_describe(status_vector,&stmt,1,out_sqlda);
>
>then there should be the coerction of data
>should i do it?

If you wish. I prefer not to do it.

> i think so since i have to allocate memry for the
>sqldata but then i'll allocate as much memory as needed by the
>CHAR(100) not the VARCHAR(100).

At first, the buffer for varchar must have length = sqllen + 2.
Where 2 is sizeof(short int) - length of length.

> Also the allocation of memory for the
>sqlind should be done?

Yes. But you don't have to allocate dynamic memory for that. You
can set sqlind to an address of any appropriate variable.

>So, where should i look for the _real_ length of the retrieved field?
>i read that it is stored in the first 2 bytes of the char* but trying
>to read them ended with ridiculously high numbers.

If you don't do datatype coercing, length of actual varchar string
is stored as int16 in first two bytes of buffer. More exactly buffer
for varchar contain PARAMVARY structure after fetch.

>Can u point me to a tutorial/piece of code where this topic is covered
>with a lil bit more of detail? (i would not mind if u r willing to
>give me a ready-made solution ;-) )

Look at existing libraries. I can't remember exact name, something
like ibpp.

>P.S. on the dox the test to see if we're encountering a NULL value is
>if ((var->sqltype & 1) && (*(var->sqlind)=-1))
>
>shouldnt it be
>
>if ((var->sqltype & 1) && (*(var->sqlind)==-1))
> ^^^

Sure, it should. Any documentation consists mistakes. It is one of
them.

SY, Dimitry Sibiryakov.