In article <47040019@hpcc01.corp.hp.com> dallara@hpcc01.corp.hp.com (Jon Dallara) writes:
>
>Hello Problem Solvers,
>
>I have encountered a problem with esql/c and
>haven't been able to solve it. :-(
>
>PROBLEM: Data looks fine in isql (key3).
> When 'fetched' from esql/c
> it returns only 1 byte from a 2 byte field.
<stuff deleted>
>key3 char(2) yes
>
<stuff deleted>
>#include <stdio.h>
>
>$char csKey3[2];
This should be $char csKey3[3]; You need 1 extra byte to hold the '\\0'
>
>main()
>{
> $DATABASE oedlamp;
>
> $DECLARE c CURSOR
> FOR SELECT key3
> INTO $csKey3
> FROM results_keys
> WHERE key1 = "1BEVA-3300";
>
> $OPEN c;
>
> $FETCH c;
>
> printf("key3 = |%.*s|\\n", sizeof(csKey3), csKey3);
printf("key3 = |%s|\\n",csKey3); should work.
You might want to be concerned with NULL since csKey3 allows for them.
if (!risnull(CCHARTYPE,csKey3))
printf("key3 = |%s|\\n",csKey3); should work.
else
printf(("key3 = ||\\n");
>
> $CLOSE c;
> $CLOSE database;
>}
>
>
>**** bad-prog output: notice that only a "P" was returned, instead of "PA" ****
>
>key3 = |P|
>/* good-prog.ec -- esql test program */
>$char csKey2[16];
>
>key2 = |EVA-3300 |
^^^^^^^^^^^^^^^
123456789012345
Here you define 16, but only 15 print. The 16th is '\\0'. Try having key2
16 characters long and you'll see this program has the exact same problem
as the first: Key2 should be defined char(17).
Bob
--
-------------------------------------------------------------------
* Bob Beaulieu (bobb@netcom.com) eztravel@netcom.com *
* Tel: 408-978-0808 Fax: 408-978-7024 *
* Corporate Travel Services *
-------------------------------------------------------------------