SQL/MX 2.x Database and Application Migration Guide (G06.23+, H06.04+, J06.03+)

Converting SQL/MP Applications to SQL/MX
Applications
HP NonStop SQL/MX Database and Application Migration Guide540435-005
10-43
Host Variable Declarations
Declaration of Character Host Variables
NonStop SQL/MP allows the declaration of character host variables by using arithmetic
operations to determine the size of the host variable array. NonStop SQL/MX does not
allow arithmetic operations to determine the size of the array. In NonStop SQL/MX,
host variables must have constants specifying the size of the array.
Variable-Length Character Data in Embedded SQL C
Programs
In NonStop SQL/MP, the VARCHAR data type defined for a column represents one
data element. However, suppose the column CUSTNAME is defined as VARCHAR(26)
in NonStop SQL/MP. The SQL/MP INVOKE directive generates a structure of the form:
struct
{
short len;
char val[27];
} custname; /* SQL/MP variable-length character data */
where len is a numeric data item that represents the length, and val is a fixed-length
character data item for the string plus an extra byte for the null terminator. In NonStop
SQL/MP, you can also explicitly declare a structure of the preceding form as a host
variable for a VARCHAR column.
In NonStop SQL/MX, in addition to the
char data type, you can declare the VARCHAR
data type for host variables within embedded SQL C programs (SQL:1999 provides the
VARCHAR data type for C programs). For example, this declaration is for a column up
to 26 bytes:
VARCHAR custname[27];/* SQL/MX variable-length character data */
As in NonStop SQL/MP, the last byte of the array is for the null terminator. You must
declare the array one byte larger to allow for the null terminator. The null terminator
follows the data inserted, so if you insert a six-character string into a VARCHAR host
variable specified as 27 characters, the null terminator is the seventh character.
INVOKE Directive
In NonStop SQL/MP, use the INVOKE directive interactively through SQLCI to create
host variable declarations in an EDIT file. You can then include the EDIT file in an
embedded SQL program.
In NonStop SQL/MX, use the INVOKE directive to create host variable declarations
only directly in an embedded SQL program. Use the INVOKE command in MXCI to
display the table and column names and data types associated with the columns; you
cannot invoke the format of another language (such as COBOL).
For either kind of table, INVOKE does not support the DATEFORMAT clause. INVOKE
returns the ANSI DATETIME data type. The SQL DATEFORMAT function returns a
character string. They are not compatible and cannot be used interchangeably.