When you code host-variable declarations in C, you must comply with the following requirements:
Note: The SQLWAs and SQLCA are automatically generated after the first EXEC SQL BEGIN DECLARE SECTION in C.
Note: C does not support VARCHAR as in other languages where the length is specified in a 2-byte binary field in front of the actual value. Instead, C supports VARCHAR as a null-terminated string. This is true for input and output host variables in C. Null-terminated strings can also be used with CHAR columns in C.
C Data Types Compared to SQL Data Types
|
C Data Type |
Example |
SQL Data Type |
|---|---|---|
|
single char |
char x; |
CHAR |
|
char array |
char x[10] |
VARCHAR |
|
char structure containing exactly one short variable followed by exactly one char array. |
char struct { |
VARCHAR |
|
decimal(precision, scale) |
decimal(5,0) |
DECIMAL |
|
short or short int |
short hv1; |
SMALLINT |
|
int or long int |
int hv1; |
INTEGER |
|
float |
float hv1; |
FLOAT |
|
double |
double hv1; |
FLOAT |
|
char array |
char dateHv[11]; |
DATE |
|
char array |
char timeHv[9]; |
TIME |
|
char array |
char timeStampHv[23]; |
TIMESTAMP |
Comments on C Data Types
The C char array is treated as a null-terminated string.
char hv1[10] is equivalent to VARCHAR(9).
The VARCHAR length is set based on the number of bytes preceding the null-terminating byte.
Char arrays for DATE, TIME, and TIMESTAMP also need the null-terminating byte.
The char array for the text is not null terminated.
Use of decimal requires #include decimal.h (provided by the IBM C Compiler), and the compiler option must not be ANSI. Precision and scale is optional. To print decimal values, use (with printf):
%D(precision,scale)
In DATACOM mode, a host variable structure may be used. The host structure must be a C structure containing only valid host variables. The host structure must not be nested within another structure.
In DATACOM mode, a host indicator structure or array may be used. The structure or array must only contain short C variables. The indicator structure must not be nested within another structure.
INCLUDEs in the C language are basically the same as in PL/I except note the following:
|
Copyright © 2014 CA.
All rights reserved.
|
|