Mapping Character Datatypes

You can declare character datatypes as host variables with a fixed maximum length by explicitly supplying the length of the character array or by declaring the host variable with an initial value. For example:


EXEC SQL BEGIN DECLARE SECTION;
char var1[18];
char var2[] = "Initialized string";
EXEC SQL END DECLARE SECTION;

In the example, two host variables are declared, each with a maximum length of 18 bytes.

Host variables that are declared as single-byte characters with no explicit length or initial values (for example, char var3) are treated as 1-byte integer datatypes.

The following table shows how C character datatypes are mapped to or from the SQL Server char, varchar, or text datatype.

Mapped datatypes

When converted

From C character to SQL Server char, varchar, or text

Data is copied and truncated or padded with blanks if the SQL Server table that is receiving the columns is set to a fixed length.

To C character from SQL Server char, varchar, or text

Data is copied and, if necessary, truncated to the length of the receiving field and is terminated with a NULL. If data is truncated, the SQLWARN1 field of the SQLCA data structure is set.