Re: C datatypes VS Oracle datatypes
Date: 1996/02/17
Message-ID: <3125B8AE.3CF2_at_softwind.se>#1/1
Tomas Zakrzewski wrote:
>
> Hi!
>
> I am new to Oracle.
>
> I am programming in C using PRO*C.
> I have problem to handle data retrieved from Oracle.
> Example:
> datatype in Oracle of the field is varchar2[5].
>
> Retrieved data from Oracle are 5 characters long therefore they takes the
> whole space of the array. If I declare array size of 6 bytes then I can manipulate array with C library functions, but I can not update or
insert back to Oracl
> that array. If I declare array of five bytes there is no problem with Oracle, but
> the string in C is not terminated by NULL.
>
> How this problem is handled. Do I have to maintain two copies of each string in case I want to
> update the Oracle. (one of the same size and second 1 byte larger for NULL use in C).
>
> Please share with your experience.
>
> Thanks.
>
> Tom Z.
>
> .
> The host variable should be declared one pos. longer then the database
field.
Table
EMP
ename varchar(10)
C
varchar ename[11]; This is actually a structure and
pro*c will declare arr and len as
members of structure ename.
Take a look in the .c-file
produced by pro*c.
select ename into :ename from emp;
ename.arr[ename.len] = '\0';
Now the hostvariable is nullterminated and can be used in C.
strcpy(ename.arr,"FRED");
ename.len = strlen(ename.arr);
The length of the string has to be calculated before the string
is used in a SQL statment
insert into emp (ename) values (:ename);
In C the strings has to be nullterminated. Oracle looks for the length of the string when inserting/updating.
/JanH Received on Sat Feb 17 1996 - 00:00:00 CET
