SQL/MX 3.1 Programming Manual for C and COBOL (H06.23+, J06.12+)
Host Variables in C/C++ Programs
HP NonStop SQL/MX Release 3.1 Programming Manual for C and COBOL—663854-001
3-17
Variable-Length Character Data
Example
This example uses a declaration for an SQL column up to 20 characters in length:
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR last_name[21]; /* 20-character last name */
EXEC SQL END DECLARE SECTION;
...
Follow the guidelines outlined in Fixed-Length Character Data on page 3-14 for
handling the null terminator when you declare and use VARCHAR arrays as host
variables for variable-length string literals.
Using the VARCHAR compatible structure to hold VARCHAR
data
In addition to the VARCHAR data type, you can use the following structure to store
VARCHAR data. You can use the structure as the input and the output host variable
instead of the varchar variable:
Struct{
short len;
char val[size];
}<struct name>;
where:
len is a numeric data item that represents the length.
val is a fixed-length character data item for the string.
The following is a declaration of the VARCHAR compatible structure:
EXEC SQL BEGIN DECLARE SECTION;
struct
{
short len;
char val[20];
}test1;
EXEC SQL END DECLARE SECTION;
The following examples use the VARCHAR compatible structure as a host variable in
the SELECT, INSERT, and UPDATE statements:
SELECT
EXEC SQL SELECT name INTO :test1 FROM t1;
C










