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

There are three valid forms for graphic host variables.

Single-graphic form

Read syntax diagramSkip visual syntax diagram
>>-+--------+--+----------+--wchar_t---------------------------->
   +-auto---+  +-const----+            
   +-extern-+  '-volatile-'            
   '-static-'                          

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

NUL-Terminated graphic form

Read syntax diagramSkip visual syntax diagram
>>-+--------+--+----------+--wchar_t---------------------------->
   +-auto---+  +-const----+            
   +-extern-+  '-volatile-'            
   '-static-'                          

   .-,------------------------------------------------.        
   V                                                  |        
>----variable-name--[--length--]--+-----------------+-+-- ; ---><
                                  '- = --expression-'          

Notes:
  1. length must be an integer constant that is greater than 1 and not greater than 16371.
  2. If the *CNULRQD option is specified on the CRTSQLCI or CRTSQLCPPI command, then input host variables must contain the graphic NUL-terminator (/0/0). Output host variables are padded with DBCS blanks, and the last character is the graphic NUL-terminator. If the output host variable is too small to contain both the data and the NUL-terminator, the following actions are taken:
    • The data is truncated
    • The last character is the graphic NUL-terminator
    • SQLWARN1 is set to 'W'
    If the *NOCNULRQD option is specified on the CRTSQLCI or CRTSQLCPPI command, the input host variables do not need to contain the graphic NUL-terminator. The following is true for output host variables.
    • If the host variable is large enough to contain the data and the graphic NUL-terminator, the following actions are taken:
      • The data is returned, but is not padded with DBCS blanks
      • The graphic NUL-terminator immediately follows the data
    • If the host variable is large enough to contain the data but not the graphic NUL-terminator, the following actions are taken:
      • The data is returned
      • A graphic NUL-terminator is not returned
      • SQLWARN1 is set to 'N'
    • If the host variable is not large enough to contain the data, the following actions are taken:
      • The data is truncated
      • A graphic NUL-terminator is not returned
      • SQLWARN1 is set to 'W'

VARGRAPHIC structured form

Read syntax diagramSkip visual syntax diagram
>>-+--------+--+----------+------------------------------------->
   +-auto---+  +-const----+   
   +-extern-+  '-volatile-'   
   '-static-'                 

>--+---------+--struct--+-----+-- { ---------------------------->
   '-_Packed-'          '-tag-'        

                      .-int-.               
>--+--------+--short--+-----+--var-1-- ; ----------------------->
   '-signed-'                               

>--wchar_t--var-2--[--length--]-- ; -- } ----------------------->

   .-,----------------------------------------------------.      
   V                                                      |      
>----variable-name--+-----------------------------------+-+--;-><
                    '-=--{--expression ,--expression--}-'        

Notes:
  1. length must be an integer constant that is greater than 0 and not greater than 16370.
  2. var-1 and var-2 must be simple variable references and cannot be used as host variables.
  3. The struct tag can be used to define other data areas, but these cannot be used as host variables.
  4. _Packed must not be used in C++. Instead, specify #pragma pack(1) prior to the declaration and #pragma pack() after the declaration.
    #pragma pack(1)
     struct VARGRAPH {
          short len;
          wchar_t s[10];
          } vstring;
    #pragma pack()

Example

EXEC SQL BEGIN DECLARE SECTION;
 
  /* valid declaration of host variable graphic string */
 
  struct VARGRAPH {
     short len;
     wchar_t s[10];
     } vstring;
 
  /* invalid declaration of host variable wstring */
 
  struct VARGRAPH wstring;