Host structures in C and C++

A C host structure contains an ordered group of data fields.

Host structures

The following diagram shows the syntax for declaring host structures.

Read syntax diagramSkip visual syntax diagramautoexternstaticconstvolatilepackedstructtag{floatdoubleshortintsqlint32longintlong longintdecimal(precision,scale)_Decimal32_Decimal64_Decimal128varchar structurebinary structurevargraphic structureSQL TYPE IS ROWIDLOB data typevar-1;unsignedcharvar-2[length];sqldbcharvar-5[length];} variable-name= expression ;

VARCHAR structures

The following diagram shows the syntax for VARCHAR structures that are used within declarations of host structures.

Read syntax diagramSkip visual syntax diagramstructtag{ signedshortintvar-3; unsignedcharvar-4 [length];}

VARGRAPHIC structures

The following diagram shows the syntax for VARGRAPHIC structures that are used within declarations of host structures.

Read syntax diagramSkip visual syntax diagramstructtag{ signedshortintvar-6;sqldbchar var-7[length]; }

Binary structures

The following diagram shows the syntax for binary structures that are used within declarations of host structures.

Read syntax diagramSkip visual syntax diagramSQL TYPE IS BINARYVARBINARYBINARY VARYING ( length)

LOB data types

The following diagram shows the syntax for LOB data types that are used within declarations of host structures.

Read syntax diagramSkip visual syntax diagramSQL TYPE IS BINARY LARGE OBJECTBLOBCHARACTER LARGE OBJECTCHAR LARGE OBJECTCLOBDBCLOB(lengthKMG)BLOB_LOCATORCLOB_LOCATORDBCLOB_LOCATOR

LOB data types for XML data

The following diagram shows the syntax for LOB data types that are used within declarations of host structures for XML data.

Read syntax diagramSkip visual syntax diagramSQL TYPE IS XML AS BINARY LARGE OBJECTBLOBCHARACTER LARGE OBJECTCHAR LARGE OBJECTCLOBDBCLOB(lengthKMG)BLOB_FILECLOB_FILEDBCLOB_FILE

Example

In the following example, the host structure is named target, and it contains the fields c1, c2, and c3. c1 and c3 are character arrays, and c2 is a host variable that is equivalent to the SQL VARCHAR data type. The target host structure can be part of another host structure but must be the deepest level of the nested structure.
struct {char  c1[3];
        struct {short len;
                char  data[5];
               }c2;
        char  c3[2];
       }target;