See also: Host Variables, Creating an FESQLC Program
When your program accesses a database column you must declare a host variable of the appropriate FESQLC or C data type to hold the data.
For example:
EXEC SQL BEGIN DECLARE SECTION; varchar firstname[31]; int stateid; varchar statename[51]; decimal amount(6,2); datetime year to second tmstamp; interval day(5) to fraction duration; EXEC SQL END DECLARE SECTION;
The table below lists the relationship between supported SQL data types, and the recommended FESQLC host variable data types that correspond to the SQL types. Also included are the corresponding data type constants, required by some FESQLC functions:
SQL Data Type | C Data Type | Description | Type Constant |
char(n), character(n) |
char(n+1)
|
character data, padded with blanks; null-terminated, specify
database column length plus 1 character data, no trailing blanks; null-terminated, specify database column length plus 1 |
CCHARTYPE
|
date | date | 4-byte integer representing the date | CDATETYPE |
datetime | datetime (qualifiers) | calendar date and time of day; must specify accuracy as a qualifier such as year to day | CDTIMETYPE |
decimal, dec, numeric | decimal(p,s) | fixed point number; p (precision) and s (scale) must be defined | CDECIMALTYPE |
money | decimal(p,s) | fixed point number; p (precision) and s (scale) must be defined | CMONEYTYPE |
float, double precision | double | double-precision value with up to 17 significant digits | CDOUBLETYPE |
integer, int | int, long | 4-byte integer | CINTTYPE |
interval | interval(qualifiers) | a span of time; must specify accuracy as a qualifier such as day to second | CINVTYPE |
serial | int, long | 4-byte integer | CINTTYPE |
smallfloat, real | float | single-precision value with up to 9 significant digits | CFLOATTYPE |
smallint | short | 2-byte integer | CSHORTTYPE |
varchar(m,x) | varchar(m+1) string(n+1) |
variable length character data; null-terminated, specify
maximum length plus 1 character data, no trailing blanks; null-terminated, specify database column length plus 1 |
CVARCHARTYPE CSTRINGTYPE |
See Host Variables for additional information about the use of these data types.
These data types are not recommended for use in database operations, but may be used in FESQLC functions.
FESQLC Data Type |
Description | Data Type Constant |
fixchar(n) | character data, padded with blanks, no null terminator | CFIXCHARTYPE |
dec_t | decimal value; cannot have precision or scale | CDECIMALTYPE |
dtime_t | datetime value; cannot have qualifiers | CDTIMETYPE |
intrvl_t | interval value; cannot have qualifiers | CINVTYPE |
The following data types automatically map correctly for 32-bit and 64-bit platforms. Some FESQLC functions use these data types instead of int, short, and long.
FESQLC Data Type |
Description |
int1 | one-byte integer |
int2 | two-byte integer |
int4 | four-byte integer |
mint | native integer data type for machine |
mlong | native long integer data type for the machine |
MSHORT | native short integer data type for the machine |
MCHAR | native char data type for the machine |
SQL Data Type |
Description |
blob | binary large object; binary data in an undifferentiated byte stream |
boolean | data type with values limited to TRUE, FALSE, and NULL |
byte | binary data in an undifferentiated byte stream |
clob | character large object; text data |
int8 | 8-byte integer |
lvarchar | character data of varying length, no larger than 2 kilobytes |
list |
a collection of elements that can be duplicate values and have ordered positions |
multiset | a collection of elements that can be duplicate values and have no ordered positions |
opaque | user-defined data type |
row | complex data type with one or more members called fields |
serial8 | 8-byte serial data type |
set |
a collection of elements that are unique values and have no ordered positions |
text | any kind of text data |