SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Host Variables in C/C++ Programs
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
3-13
Using Host Variables in a C/C++ Program
indicator_variable
is an indicator variable of exact numeric data type. You must declare the indicator
variable as type short in C. You must precede indicator_variable with a
colon (:) in an SQL statement.
If data returned in the host variable is null, the indicator variable is less than zero. If
character data returned is truncated, the indicator variable is set to the length of
the string in the database. Otherwise, the value of the indicator variable is zero. To
insert null into the database, set the indicator variable to a value less than zero.
Using Host Variables in a C/C++ Program
As a C/C++ programmer, you need to know how to declare and use host variables to
retrieve and insert data with these SQL data types:
•
Fixed-Length Character Data on page 3-14
•
Variable-Length Character Data on page 3-16
•
Numeric Data on page 3-18
•
Date-Time and Interval Data on page 3-23
In a C program, you can use structures for host variables. When you refer to a single
field name in the structure, you must include the structure name with the field name.
In a C++ program, you can use a data member of a class as a host variable.
References to host variables declared within a class definition must be within member
functions of the class. See Host Variables as Data Members of a C++ Class on
page 3-29.
Character Set Data
These guidelines apply for NonStop SQL/MX Release 1.8 and NonStop SQL/MX
Release 2.x character sets:
•
ISO88591 character set: An SQL/MX Release 1.8 application can be run under
SQL/MX Release 2.x without application recompilation, if the application contains
ISO88591 character data only.
•
KANJI and KSC5601 character set: If KANJI or KSC5601 character set host
variables are contained in the application, the application must be carefully
rewritten and recompiled. KANJI and KSC5601 host variables in C applications are
translated as single-byte arrays in SQL/MX Release 1.8 and as double-byte arrays
in SQL/MX Release 2.x. If the application is not rewritten, SQL errors might be
emitted, corruption of data might occur, and the application might crash.
Host variable source code in SQL/MX Release 1.8:
char a[100]; /* Host variable stores KANJI character strings */
Host variable source code in SQL/MX Release 2.x:
char CHARACTER SET IS KANJI a[100];