Treatment In C Statements; Varchar Data Type - HP NonStop SQL/MP Programming Manual

For c
Table of Contents

Advertisement

Host Variables

Treatment in C Statements

A C statement treats a host variable declared with the CHARACTER SET clause as if
the host variable had been declared without the clause. A C statement also treats the
host variable length as the specified length multiplied by the number of bytes per
character plus the null terminator if the SQL pragma specifies the CHAR_AS_STRING
option (the default). These examples show this treatment for single-byte and double-
byte character set declarations:
Host Variable Declaration
char CHARACTER SET ISO88591 hostv1[5]
char CHARACTER SET KANJI hostv2[10]

VARCHAR Data Type

If you specify the CHARACTER SET clause with a host variable declared as a
VARCHAR data type, you must set the length data item (len in the next example) of
the VARCHAR group item to the host variable length in bytes and not characters.
For example, this host variable declaration specifies the double-byte KANJI character
set for emp_name. The C assignment statement sets the length (emp_name.len) of
the host variable name to 16 characters because the name (emp_name.val) contains
8 double-byte characters (which are represented as "c1c2c3c4c5c6c7c8").
EXEC SQL BEGIN DECLARE SECTION;
struct {
short len;
char CHARACTER SET KANJI val[10];
} emp_name;
EXEC SQL END DECLARE SECTION;
...
/* Insert data into the data base. */
strcpy (emp_name.val, "c1c2c3c4c5c6c7c8");
emp_name.len = strlen(emp_name.val);
EXEC SQL
INSERT INTO =employee VALUES (:emp_name);
...
/* Select data from the data base. */
EXEC SQL
SELECT employee_name INTO :emp_name FROM =employee;
emp_name.val[emp_name.len] = '\0';
...
The last C assignment statement sets the null terminator after the SELECT statement
returns the employee name from the EMPLOYEE table.
HP NonStop SQL/MP Programming Manual for C—429847-008
Treatment in C Statements
char hostv1[5]
char hostv2[20]
2-25
Treatment in C Statements

Advertisement

Table of Contents
loading

Table of Contents