Re: problem with characters in dynamic ESQL
Posted in 1998
apatnaik@aircom.com wrote:
>
> Hello,
>
> I am using dynamic ESQL select statements to
> fetch an unsigned char(1) into my host variables.
>
> Now with dyn ESQL, all the data returned from the
> DESCRIBE (via DATA) comes back to me as
> strings.
>
> When I try to print this value, I get nothing, When
> I use the dbaccess tool to view this value, sometimes
> I see an alphanumeric Beta in it.
>
> Is there a known problem with character arrays
> that contain one byte only when using Dyn. ESQL?
>
> It appears to me that the data is somewhat encoded
> with the DESCRIBE statement. How do I decode it to
> print it???
You either have to declare the host variable as:
fixchar hvar[1];
OR as any of:
char hvar[2];
string hvar[2];
varchar hvar[2];
This is probably your problem. Declaring a host variable as char you
MUST allow an extra character for the trailing NULL. The fetch code
will try put the null into the last character position of the host
variable which, for a char[1] will overwrite the data byte. The
typedef fixchar is for strings that are space filled and NOT NULL
terminated. Each of the other string types is NULL terminated and will
exhibit the same problem if you do not declare them AT LEAST length 2.
If you declared an indicator variable for the char(1) column it would
probably show a truncation warning.
Art S. Kagel