Download Precompiler User`s Manual - ALTIBASE Customer Support
Transcript
Extended Data Type
Extended Data Type
The embedded SQL statement provides extended datatypes besides those that C or C++ supports.
This extended datatype can be used as a datatype of the host variable. The following describes the
extended datatypes and how to use them.
VARCHAR
varchar
Both varchar and VARCHAR are allowed, and it is internally a structure type. For example,
If it is declared as following:
varchar a[10];
It has the structure as following:
struct { int len; char arr[10] ;}a;
Therefore, to refer to the variable of the varchar type, indicate the component of the varchar type
like a.arr.
The varchar type internally includes the indicator variable. The component, len, functions as an indicator variable. Therefore, when an indicator variable is necessary, the user does not need to specify a
separate indicator variable by using a varchar type.
The varchar type internally includes an indicator variable, but a separate indicator variable can be
specified. In this way, the user can specify the indicator variable that corresponds to the varchar type
when declaring the indicator variable in the structure type in case the varchar type is one of structure components.
Advantages
This type includes the indicator variable so that the user does not need to specify a separate indicator variable. Therefore, it is convenient when the indicator variable is necessary.
Restrictions
Unless a separate indicator variable is specified for this type, len, one of the components, will function as the indicator variable. Therefore, if a separate indicator variable has not been specified when
this is used as an input host variable, len must be specified. If NULL data is set as len, it will be "-1."
Otherwise, it will be the input value (arr value.)
Example) EXEC SQL BEGIN DECLARE SECTION;
varchar var1;
EXEC SQL END DECLARE SECTION;
strcpy(var1.arr, “ABC”);
var1.len = strlen(var1.arr);
EXEC SQL INSERT INTO T1(I1)
VALUES (:var1);(O)
64
Datatypes of Host Variables