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-12
Specifying Host Variables in SQL Statements
NonStop SQL/MX converts data between signed and unsigned numeric types and
between numeric types with different precisions. Note that if a signed numeric type has
a negative value, it cannot be converted.
If assignment would result in a loss of significant digits, NonStop SQL/MX returns a
data exception condition in SQLSTATE. For a description of SQLSTATE values, see
Table 13-1 on page 13-2.
Converting Character Types
Values of data types CHARACTER, PICTURE X’s, and CHARACTER VARYING are
character strings and are all mutually comparable and mutually assignable if both are
of the same character set. In addition, UCS2 host variables are mutually comparable
and assignable with ISO88591 nonhost variable objects.
For character strings of different lengths, NonStop SQL/MX pads the receiving string
variable on the right with blanks as necessary.
If the receiving string variable is too short, NonStop SQL/MX truncates the right part of
the string retrieved from the database and returns a data exception condition in
SQLSTATE. For a description of SQLSTATE values, see Table 13-1 on page 13-2.
Specifying Host Variables in SQL Statements
Use host language naming conventions for your host variable and indicator variable
names. For example, a name in a C program contains alphanumeric characters,
including the underscore (_), and begins with a letter or an underscore. To avoid
conflicts with system-generated names, do not begin your host variable names with
underscores.
After you declare a host variable, to specify it within an embedded SQL statement, use
this syntax:
variable-name
is the host variable name. It can be any valid host language identifier with a data
type that corresponds to an SQL data type. You must precede variable-name
with a colon (:) within an SQL statement.
INDICATOR
is a keyword that can precede indicator_variable.
Note. For optimal performance, declare host variables with corresponding data types and the
same lengths as their respective columns in SQL statements (with consideration for the extra
character required for the null terminator). This programming practice minimizes the data
conversion performed by NonStop SQL/MX and therefore can improve the performance of your
program.
:variable-name [[INDICATOR] :indicator_variable]