Re: DYNAMIC SQL Select on char or varchar column
Posted in 1998
Alex Molochnikov wrote:
>
> Everytime a dynamic sql select returns a char or varchar field that is the
> full length of the column, the last character will be missing; yet in the
> database itself I know that the column includes the last character.
>
> For Example:
> create table abc (a char(3))
> insert into table abc (a) values('one')>
> select * from abc where a = 'one'
> (1 row returned)>
> select * from abc where a = 'on'
> (0 rows returned)>
> BUT if I do the following dynamic sql query
>
> sqlCommand = "select a from abc"
>
> EXEC SQL prepare sqlcursor from :sqlCommand;
> EXEC SQL declare selectCursor cursor for sqlcursor;
> EXEC SQL describe sqlcursor into sqldaPtr;
> EXEC SQL open selectCursor;
> EXEC SQL fetch selectCursor using descriptor sqldaPtr;
>
> My sqldata will only have 'on' rather than 'one'. It is the same for
> varchar. All my other fields are totally fine.
>
> Any suggestions would be greatly appreciated!
You are not allowing an extra byte in your host variables for the
trailing NULL byte so Informix overwrites the last char with the NULL.
If you do not want the NULL declare the host variable type FIXCHAR
rather than CHAR, VARCHAR, or STRING. The differences in these four
host variable types is discussed at langth in TFM.
Art S. Kagel