Host structure declarations in C and C++ applications that use SQL

These figures show the valid syntax for host structure declarations.

Host Structures

Read syntax diagramSkip visual syntax diagram
>>-+--------+--+----------+--+---------+--struct--+-----+--{---->
   +-auto---+  +-const----+  '-_Packed-'          '-tag-'      
   +-extern-+  '-volatile-'                                    
   '-static-'                                                  

   .----------------------------------------------------------------.      
   |                                               .-,-----.        |      
   V                                               V       |        |      
>----+-+-float----------------------------------+----var-1-+-- ; -+-+--}-->
     | +-double---------------------------------+                 |        
     | +-decimal (--precision--+----------+--)--+                 |        
     | |                       '-,--scale-'     |                 |        
     | |                              .-int-.   |                 |        
     | +-+-+--------+--+-long long-+--+-----+-+-+                 |        
     | | | '-signed-'  +-long------+          | |                 |        
     | | |             '-short-----'          | |                 |        
     | | +-sqlint32---------------------------+ |                 |        
     | | '-sqlint64---------------------------' |                 |        
     | +-varchar-structure----------------------+                 |        
     | +-vargraphic-structure-------------------+                 |        
     | +-lob------------------------------------+                 |        
     | +-SQL-varchar----------------------------+                 |        
     | +-rowid----------------------------------+                 |        
     | '-binary---------------------------------'                 |        
     |                     .-,-----------------------.            |        
     |                     V                         |            |        
     +-+----------+--char----var-2--+--------------+-+-- ; -------+        
     | +-signed---+                 '-[--length--]-'              |        
     | '-unsigned-'                                               |        
     |          .-,-----------------------.                       |        
     |          V                         |                       |        
     '-wchar_t----var-5--+--------------+-+-- ; ------------------'        
                         '-[--length--]-'                                  

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

varchar-structure

                                          .-int-.               
|--struct--+-----+--{--+--------+--short--+-----+--var-3-- ; --->
           '-tag-'     '-signed-'                               

>--+----------+--char--var-4--[--length--]-- ; --}--------------|
   +-signed---+                                      
   '-unsigned-'                                      

Host Structures (continued)

Read syntax diagramSkip visual syntax diagram
vargraphic-structure

                                          .-int-.   
|--struct--+-----+--{--+--------+--short--+-----+--------------->
           '-tag-'     '-signed-'                   

>--var-6-- ; --wchar_t--var-7--[--length--]-- ; --}-------------|

lob

|--SQL TYPE IS--+-+-CLOB---+--(--length--+---+--)-+-------------|
                | +-DBCLOB-+             +-K-+    |   
                | '-BLOB---'             +-M-+    |   
                |                        '-G-'    |   
                +-+-CLOB_LOCATOR---+--------------+   
                | +-DBCLOB_LOCATOR-+              |   
                | '-BLOB_LOCATOR---'              |   
                '-+-CLOB_FILE---+-----------------'   
                  +-DBCLOB_FILE-+                     
                  '-BLOB_FILE---'                     

SQL-varchar

|--VARCHAR--variable-name--[--length--]-------------------------|

rowid

|--SQL TYPE IS ROWID--------------------------------------------|

binary

|--SQL TYPE IS--+-BINARY---------+--(--length--)----------------|
                +-VARBINARY------+                 
                '-BINARY VARYING-'                 

Notes:
  1. For details on declaring numeric, character, graphic, LOB, ROWID, and binary host variables, see the notes under numeric, character, graphic, LOB, ROWID, and binary host variables.
  2. A structure of a short int followed by either a char or wchar_t array is always interpreted by the SQL C and C++ precompilers as either a VARCHAR or VARGRAPHIC structure.
  3. _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 {
           short myshort;
           long mylong;
           char mychar[5];
            } a_st;
    #pragma pack()
  4. If using sqlint32 or sqlint64, the header file sqlsystm.h must be included.