Binary host variables in C and C++ applications that use SQL

C and C++ do not have variables that correspond to the SQL binary data types. To create host variables that can be used with these data types, use the SQL TYPE IS clause. The SQL precompiler replaces this declaration with a C language structure in the output source member.

BINARY

Read syntax diagramSkip visual syntax diagram
>>-+--------+--+----------+--SQL TYPE IS--BINARY--(length)------>
   +-auto---+  +-const----+                                  
   +-extern-+  '-volatile-'                                  
   '-static-'                                                

   .-,---------------------------------.        
   V                                   |        
>----variable-name--+----------------+-+-- ; ------------------><
                    '- = --init-data-'          

VARBINARY

Read syntax diagramSkip visual syntax diagram
>>-+--------+--+----------+--SQL TYPE IS--+-VARBINARY------+---->
   +-auto---+  +-const----+               '-BINARY VARYING-'   
   +-extern-+  '-volatile-'                                    
   '-static-'                                                  

>--(length)----------------------------------------------------->

   .-,-------------------------------------------------------.   
   V                                                         |   
>----variable-name--+--------------------------------------+-+-->
                    +- = --{--init-len,"init-data"--}------+     
                    '- = --SQL_VARBINARY_INIT("init-data")-'     

>-- ; ---------------------------------------------------------><

Note:
  1. For BINARY host variables, the length must be in the range 1 to 32766.
  2. For VARBINARY and BINARY VARYING host variables, the length must in the range 1 to 32740.
  3. SQL TYPE IS, BINARY, VARBINARY, and BINARY VARYING can be in mixed case.

BINARY Example

The following declaration:

SQL TYPE IS BINARY(4) myBinField;

Results in the generation of the following code:

unsigned char myBinField[4];

VARBINARY Example

The following declaration:

SQL TYPE IS VARBINARY(12) myVarBinField;

Results in the generation of the following structure:

_Packed struct myVarBinField_t {
	short length;
	char  data[12]; }
myVarBinField;