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

C and C++ do not have variables that correspond to the SQL data types for LOBs (large objects). 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.

LOB Host Variable

Read syntax diagramSkip visual syntax diagram
>>-+--------+--+----------+--SQL TYPE IS--+-CLOB---+------------>
   +-auto---+  +-const----+               +-DBCLOB-+   
   +-extern-+  '-volatile-'               '-BLOB---'   
   '-static-'                                          

>--(--length--+---+--)------------------------------------------>
              +-K-+      
              +-M-+      
              '-G-'      

   .-,----------------------------------------------------.        
   V                                                      |        
>----variable-name--+-----------------------------------+-+-- ; -><
                    +- = --{--init-len,"init-data"--}---+          
                    +- = --SQL_CLOB_INIT("init-data")---+          
                    +- = --SQL_DBCLOB_INIT("init-data")-+          
                    '- = --SQL_BLOB_INIT("init-data")---'          

Notes:
  1. K multiplies length by 1024. M multiplies length by 1 048 576. G multiplies length by 1 073 741 824.
  2. For BLOB and CLOB, 1 ≤ length ≤ 2 147 483 647
  3. For DBCLOB, 1 ≤ length ≤ 1 073 741 823
  4. SQL TYPE IS, BLOB, CLOB, DBCLOB, K, M, G can be in mixed case.
  5. The maximum length allowed for the initialization string is 32 766 bytes.
  6. The initialization length, init-len, must be a numeric constant (that is, it cannot include K, M, or G).
  7. If the LOB is not initialized within the declaration, then no initialization will be done within the precompiler generated code.
  8. The precompiler generates a structure tag which can be used to cast to the host variable's type.
  9. Pointers to LOB host variables can be declared, with the same rules and restrictions as for pointers to other host variable types.
  10. CCSID processing for LOB host variables will be the same as the processing for other character and graphic host variable types.
  11. If a DBCLOB is initialized, it is the user's responsibility to prefix the string with an 'L' (indicating a wide-character string).

CLOB example

The following declaration:

SQL TYPE IS CLOB(128K) var1, var2 = {10, "data2data2"};

The precompiler will generate for C:

_Packed struct var1_t { 
 unsigned long length; 
 char data[131072]; 
 } var1,var2={10,"data2data2"};

DBCLOB example

The following declaration:

SQL TYPE IS DBCLOB(128K) my_dbclob;

The precompiler will then generate:

_Packed struct my_dbclob_t {
 unsigned long length;
 wchar_t data[131072]; } my_dbclob;

BLOB example

The following declaration:

static SQL TYPE IS BLOB(128K) 
  my_blob=SQL_BLOB_INIT("mydata");

Results in the generation of the following structure:

static struct my_blob_t {
   unsigned long length;
   char          data[131072];
} my_blob=SQL_BLOB_INIT("my_data");

LOB Locator

Read syntax diagramSkip visual syntax diagram
>>-+--------+--+----------+--SQL TYPE IS--+-CLOB_LOCATOR---+---->
   +-auto---+  +-const----+               +-DBCLOB_LOCATOR-+   
   +-extern-+  '-volatile-'               '-BLOB_LOCATOR---'   
   '-static-'                                                  

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

Notes:
  1. SQL TYPE IS, BLOB_LOCATOR, CLOB_LOCATOR, DBCLOB_LOCATOR can be in mixed case.
  2. init-value permits the initialization of pointer locator variables. Other types of initialization will have no meaning.
  3. Pointers to LOB Locators can be declared, with the same rules and restrictions as for pointers to other host variable types.

CLOB Locator Example

The following declaration:

static SQL TYPE IS CLOB_LOCATOR my_locator;

Results in the following generation:

static long int unsigned my_locator;

BLOB and DBCLOB locators have similar syntax.

LOB file reference variable

Read syntax diagramSkip visual syntax diagram
>>-+--------+--+----------+--SQL TYPE IS--+-CLOB_FILE---+------->
   +-auto---+  +-const----+               +-DBCLOB_FILE-+   
   +-extern-+  '-volatile-'               '-BLOB_FILE---'   
   '-static-'                                               

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

Notes:
  1. SQL TYPE IS, BLOB_FILE, CLOB_FILE, DBCLOB_FILE can be in mixed case.
  2. Pointers to LOB File Reference Variables can be declared, with the same rules and restrictions as for pointers to other host variable types.

CLOB File Reference Example

The following declaration:

static SQL TYPE IS CLOB_FILE my_file;

Results in the generation of the following structure:

static _Packed struct {
     unsigned long    name_length;
     unsigned long    data_length;
     unsigned long    file_options;
              char    name[255];
} my_file;

BLOB and DBCLOB file reference variables have similar syntax.

The precompiler will generate declarations for the following file option constants. You can use these constants to set the file_options variable when you use File Reference host variables.

Related information
LOB file reference variables