Fetch and insert with an ANSI-compliant database
For an ANSI-compliant database, when you use a character
host variable in an INSERT statement or in the WHERE clause of an
SQL statement (SELECT, UPDATE, or DELETE), the character value in
the host variable must be null terminated. Therefore, use the following
data types for character host variables:
- char, string, or varchar
- lvarchar
For example, the following insertion is valid because
the first and last host variables are of type char,
which is null terminated:
EXEC SQL BEGIN DECLARE SECTION;
char first[16], last[16];
EXEC SQL END DECLARE SECTION;
;
stcopy("Dexter", first);
stcopy("Haven", last);
EXEC SQL insert into customer (fname, lname)
values (:first, :last);
The stcopy() function copies the null terminator into the host variable and the char data type retains the null terminator.
Do not use the fixchar data type for host variables
because it does not include a null terminator on the string. For an
ANSI-compliant database, the database server generates an error under
either of the following conditions:
- If you try to insert a string that is not null terminated.
- If you use a string that is not null terminated in a WHERE clause.