EasyManua.ls Logo

HP NonStop SQL/MP

HP NonStop SQL/MP
331 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Host Variables
HP NonStop SQL/MP Programming Manual for C429847-008
2-7
Declaring and Using Host Variables
TYPE AS
specifies that the host variable will have the specified date-time (DATETIME,
DATE, TIME, or TIMESTAMP) or INTERVAL data type. If a host variable must
contain date-time or INTERVAL values, define it as a character data type. To cause
NonStop SQL/MP to handle the host variable as a scaled value, either use the
SETSCALE function or define the variable as C data type fixed.
Declaring and Using Host Variables
You can declare and use these data types as host variables:
Fixed and variable length character data types (CHAR and VARCHAR)
Structures
Decimal data types
Fixed-point data types
Date-time and INTERVAL data types
Fixed-Length Character Data
The C language uses a character array plus a null terminator (\0) to store a string
literal. Most C string-handling routines (for example, strlen and printf) require the
null terminator. Follow these guidelines when you use character arrays as host
variables for string literals.
Declaring a Character Array
When you declare a character array as a host variable, the C compiler reserves the
last byte of the array as a place holder for a null terminator. Therefore, declare a
character array one byte longer than the actual number of characters. (The INVOKE
directive automatically appends an extra byte to a character array, provided you do not
specify the CHAR_AS_ARRAY option in the SQL pragma.) This declaration is for an SQL
column up to 20 bytes long:
EXEC SQL BEGIN DECLARE SECTION;
char last_name[21]; /* 20-byte last name */
EXEC SQL END DECLARE SECTION;
...
Selecting Character Data
When selecting character data from a database to return to a host variable array,
NonStop SQL/MP does not append a null terminator to the data. Therefore, before
using the array in a C string-handling routine that requires a null terminator, you must
append a null terminator to the array. This example selects character data from the

Table of Contents

Related product manuals