Re: How to preserve trailing space(variable number of)
Posted in 1997
>From: fjin@vtex.com
>Date: Mon, 06 Jan 1997 22:28:53 GMT
>X-Informix-List-Id: <news.32274>
>
>I am running into this problem and not sure how to solve it:
>
>1. Have a varchar(20) column
>2. insert value 'name " into the column. Notice three trailing
>spaces.
>3. when i retrive the column in my esql program, I can
> manage to get either no trailing space or all of them. i.e. I can
>get either 'name' or 'name '. second one with
>spaces padd until the column width.
>
>Anyone out there has run into the same problem?
No. The following code works correctly for me. Tested on Solaris 2.5.1
and OnLine and ESQL/C 7.21.UC1. The key point is the declaration of
variable as varchar!
Yours succinctly,
Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>
# rmk is an educated version of make which knows how to compile ESQL/C programs.
$ rmk kk && ./kk
esql -O kk.ec -o kk
rm -f kk.[co]
<<ABC3 >>
<<ABC4 >>
<<ABC5 >>
$ cat kk.ec
#include <stdio.h>
int main(int argc, char **argv)
{
EXEC SQL BEGIN DECLARE SECTION;
varchar variable[31];
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER ERROR STOP;
EXEC SQL DATABASE Stores;
EXEC SQL CREATE TEMP TABLE SomeTable (SomeColumn VARCHAR(30) NOT NULL);
EXEC SQL INSERT INTO SomeTable VALUES("ABC3 ");
EXEC SQL INSERT INTO SomeTable VALUES("ABC4 ");
EXEC SQL INSERT INTO SomeTable VALUES("ABC5 ");
EXEC SQL DECLARE c CURSOR FOR
SELECT SomeColumn INTO :variable FROM SomeTable;
EXEC SQL OPEN c;
while (sqlca.sqlcode == 0)
{
EXEC SQL FETCH c;
if (sqlca.sqlcode != 0)
break;
printf("<<%s>>\\n", variable);
}
EXEC SQL CLOSE c;
EXEC SQL FREE c;
return(0);
}
$