SQL statements with distinct-type columns

For dynamic execution of distinct-type columns, the dynamic-management structures have been modified to hold the following information about a distinct type:
  • The data type constant (from sqltypes.h) for the source type of the distinct-type column
  • The extended identifier for the source type of the distinct-type column
These values are in the following fields of a dynamic-management structure.
Dynamic-management structure Source-type field Extended-identifier field
system-descriptor area SOURCETYPE field of an item descriptor SOURCEID field of an item descriptor
sqlda structure sqlsourcetype field of an sqlvar_struct structure sqlsourceid field of an sqlvar_struct structure

When the DESCRIBE statement describes a prepared statement, it stores information about columns of the statement in a dynamic-management structure. There is no special constant in the sqltypes.h file to indicate a distinct data type. Therefore, the type field of the dynamic-management structure cannot directly indicate a distinct type. (Type and length fields of dynamic-management structures shows the type fields of the dynamic-management structures.)

Instead, the type field in the dynamic-management structure has a special value to indicate that a distinct bit is set for a distinct-type column. The type field indicates the source type of the distinct data combined with the distinct bit. The sqltypes.h header file provides the following data type constants and macros to identify the distinct bit for a distinct column.
Source type Distinct-bit constant Distinct-bit macro
LVARCHAR SQLDLVARCHAR ISDISTINCTLVARCHAR(type_id)
BOOLEAN SQLDBOOLEAN ISDISTINCTBOOLEAN(type_id)
Any other data type SQLDISTINCT ISDISTINCTTYPE(type_id)
Use the following algorithm to determine if a column is a distinct type:
if (one of the distinct bits is set)
   {
   /* Have a distinct type, now find the source type */  
   if (ISDISTINCTLVARCHAR(sqltype))
      {
      /* Is a distinct of LVARCHAR:
       *   type field = SQLUDTVAR + SQLDLVARCHAR
       *   source-type field = 0
       *   source-id field = extended identifier of lvarchar
       */
      }
   else if (ISDISTINCTBOOLEAN(sqltype))
      {
      /* Is a distinct of BOOLEAN
       *   type field = SQLUDTFIXED + SQLDBOOLEAN
       *   source-type field = 0
       *   source-id field = extended id of boolean
       */
      }
   else 
      {
      /* SQLDISTINCT is set */
      if (ISUDTTYPE(sqltype))
         {
         /* Source type is either a built-in simple type or an
          * opaque data type
          */
         if (source-id field > 0)
            /* Is a distinct of an opaque type. 
             * Pick up the xtended identifier of the source type
             * from the source-id field
             */
         else
            /* Is a distinct of a built-in simple type.
             * Pick up the type id of the source type from the
             * source-type field
             */
         }
      else
         {
         /* Source type is a non-simple type, a complex type.
          * Both the source-type and source-id fields should be 0,
          * the source type is embedded in the type field:
          *     type = source type + SQLDISTINCT
          */
         }  
      }
   }
The following table summarizes the pseudo-code of the preceding algorithm.
Source type Type field Source-type field Extended-identifier field
Built-in data type SQLUDTVAR + SQLDISTINCT Data type constant of built-in data type 0
LVARCHAR SQLUDTVAR + SQLDLVARCHAR 0 Extended identifier of LVARCHAR
BOOLEAN SQLUDTFIXED + SQLDBOOLEAN 0 Extended identifier of BOOLEAN
All other data types source type + SQLDISTINCT 0 0