Open Client user-defined datatypes

If an application that needs to use a datatype that is not included in the standard Open Client datatypes, you can create a user-defined datatype. For example, you might create a user-defined datatype that represents encrypted character data. To create a user-defined datatype:

  1. Create the new datatype name. For example:

    typedef char ENCRYPTED_CHAR;
    
  2. Define a type constant that represents the datatype. For example:

    #define ENCRYPTED_TYPE      CS_USERTYPE + 2;
    

    Because the Open Client routines ct_bind and cs_set_convert use symbolic type constants to identify datatypes, you must define a type constant for each user-defined type. User-defined type constants must be greater than or equal to CS_USERTYPE.

  3. Call cs_set_convert to install custom conversion routines to convert between standard Open Client datatypes and the user-defined datatype. For the ENCRYPTED_CHAR user-defined datatype in the example above, you might define and install custom conversion routines that encrypt and decrypt character data. You might, for example, install an encryption routine for conversions from CS_CHAR_TYPE to ENCRYPTED_TYPE, and install a decryption routine for conversions from ENCRYPTED_TYPE to CS_CHAR_TYPE.

  4. Call cs_setnull to define a null substitution value for the user-defined datatype.

After conversion routines are installed, an application can bind server results to a user-defined datatype:

mydatafmt.datatype = ENCRYPTED_CHAR;
 ct_bind(cmd, 1, &mydatafmt, mycodename, NULL,
 NULL);

Custom conversion routines are called transparently, whenever required, by ct_bind and cs_convert.

NoteDo not confuse Open Client user-defined datatypes with Adaptive Server user-defined datatypes. Open Client user-defined datatypes are C-language types, declared within an application. ASE user-defined datatypes are database column datatypes, created with the system stored procedure sp_addtype.