Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Wierd problem? Does C pad a host variable in embedded SQL with spaces?

Re: Wierd problem? Does C pad a host variable in embedded SQL with spaces?

From: <laz777_at_semaphore.com>
Date: 1998/04/07
Message-ID: <6gej5h$pbu$1@nnrp1.dejanews.com>#1/1

>
> I am using C on a Sun Unix Enterprise Server with embedded sql.
>
> A select statement is used as follows
>
> select laborcode, craft fro labor into :laborcode, craft when la2 =
> :empnum
>
> Then an
> insert into labtrans (laborcode, craft) values (:laborocode,
:craft);
>
> :laborcode is defined as char laborcode[17] in the program;
>
> The laborcode field in the labor table is a variable (VAR_CHAR) field in
> Oracle of up to 16 characters.
>
> The problem is that the resulting laborcode in labtrans is always 16
> characters long. If the selected laborcode from labor is less (i.e. JEDRF)
> then it padds the field with spaces to equal 16 characters. Is this a
> function of the embedded sql in C? Or of Oracle
>

The problem is what in your 'select into' statement. When Pro*C fills a C variable from a cursor, it doesn't null terminate it. Instead, it pads it out to the size of the VARCHAR. In your case it is padding the string out to a full 16 chars. One way to fix this is use the host-variable structure provided by Pro*C. Here's an example of how to use them.

put a line like this above your main.

EXEC SQL BEGIN DECLARE SECTION; VARCHAR vcLABORCODE[17];
short indLABORCODE;

EXEC SQL END DECLARE SECTION; you would then change your code to:
  select laborcode, craft fro labor into :vcLABORCODE, craft when la2 = :empnum.

then you manually null terminte the string by doing this vcLABORCODE.arr[vcLABORCODE.len] = '\0';

the finish off your sql statemnt like this.

insert into labtrans (laborcode, craft) values (:vcLABORCODE, :craft);

Good luck-       



Todd Marshall
Senior Developer
Semaphore Corp
2001 6th Ave Suite 400		(ph) 206-443-0651
Seattle, WA			(fx) 206-443-0718

98121

I am not a vegetarian because I love animals; I am a vegetarian because I hate plants. -- A. Whitney Brown

-----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/ Now offering spam-free web-based newsreading Received on Tue Apr 07 1998 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US