Re: problem with characters in dynamic ESQL
Posted in 1998
On Tue, 7 Jul 1998 apatnaik@aircom.com wrote:
> I am using dynamic ESQL select statements to
> fetch an unsigned char(1) into my host variables.
So, you are remembering to use either a fixchar data type or at least
char(2) -- sorry...char value[2] -- aren't you?
> Now with dyn ESQL, all the data returned from the DESCRIBE (via DATA)
> comes back to me as strings.
We're talking about an SQL DESCRIPTOR, yes?
> 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.
That's probably related to problems during INSERT where the data is not
being handled correctly. You are unlucky that the dereferencing process is
not crashing your program and is inserting gibberish into the database --
stray pointers can be cruel, sometimes.
> Is there a known problem with character arrays that contain one byte only
> when using Dyn. ESQL?
You cannot reliably use one character arrays in ESQL/C. All strings are
strings, and (unless you're into sado-masochistic coding practices) all
those strings are null terminated. Therefore, to get data into a string,
it has to be an array of at least 2 bytes.
> It appears to me that the data is somewhat encoded with the DESCRIBE
> statement. How do I decode it to print it???
With some difficulty... If you're using sqlda structures, I have code
which I can make available. If you're using SQL DESCRIPTOR for your
DESCRIBE, I don't have a ready-made solution. However, a general solution
should be possible since you can pass the descriptor name into the
descriptor dumping routine. Most of the type information is in sqltypes.h.
Have you read the manual?
Yours,
Jonathan Leffler (jleffler@informix.com) #include <witticism.h>
Guardian of DBD::Informix -- see http://www.perl.com/CPAN