Declare var binary host variables

To declare a var binary host variable, use the following syntax.

1 (1)  var binary?  ’ opaque typestructure name + , variable name  ;
Notes:
  • 1 HCL OneDB™ extension
Element Purpose Restrictions SQL syntax
opaque type Name of the opaque data type whose internal format is to be stored in the var binary variable. Must already be defined in the database Identifier segment in the HCL OneDB Guide to SQL: Syntax
variable name Name of the ESQL/C variable to declare as a var binary variable Name must conform to language-specific rules for variable names.
The following figure shows declarations for three var binary variables.
Figure 1: Sample var binary host variables
#include <shape.h>;
#include <image.h>;

EXEC SQL BEGIN DECLARE SECTION;
   var binary polygon1;
   var binary 'shape' polygon2, a_circle;
   var binary 'image' an_image;
EXEC SQL END DECLARE SECTION;
In the declaration of a var binary host variable, the name of the opaque type must be a quoted string.
Important: Both the quotation mark (') and the quotation mark (") are valid quote characters. However, the beginning quote and ending quote characters must match.
The opaque type name is optional; it affects the declaration as follows:
  • When you omit opaque type from the var binary declaration, the database server attempts to identify the appropriate support functions to use when the application receives the internal data structure from the opaque-type column in a database.

    The advantage of the omission of opaque type is that you can use the var binary host variable to hold data that was selected from several different opaque types (as long as the database server is able to find the appropriate support functions).

    The disadvantage of the omission of opaque type is that host variables declared in this way cannot be used as parameters to user defined routines (UDRs).

  • When you specify opaque type in the var binary declaration, the database server knows precisely which support functions to use when it sends the internal data structure to the database server for storage in the opaque-type column.

    The loss of ambiguity that the opaque type name provides can make data conversion more efficient. However, in this case, the var binary host variable can only hold data from the specified opaque type data type.

You can declare several var binary variables in a single declaration line. However, all variables must have the same opaque type, as Sample var binary host variables shows.