The raw data object

If the class factory for a specific server type is not registered, the automatically creates an object that exposes both an ITValue interface and an ITDatum interface. To obtain a pointer to the binary data of the object, use the ITDatum::Data method. The resulting pointer can be used to access the data structure that corresponds to the object.

This approach violates the principle of information hiding. By accessing the structure through a pointer, the user of the object creates a dependency on the particular implementation of an object. If that implementation changes, the applications that use the object can cease to function. The interface approach to object encapsulation ensures that an application cannot create a dependency on a particular implementation of an object.

The rawval.cpp example shows how an application can use the ITDatum interface to extract a data structure from the value object returned from the Object Interface for C++ when no specific value object constructor is found for the server type. This example application retrieves a pointer to a sequence of bytes from the server. The following code excerpts point out use of the raw data interface.
  1. Issue a query to return an array and extract the value from the row.
    ITQuery q(conn);
    
    ITRow *row = 
        q.ExecOneRow("select byte_val from regresstab;");
    // Extract the column
    ITValue *v;
    v = row->Column(0);
  2. Extract the ITDatum interface from the object.
    ITDatum *rv;
    if (v->QueryInterface(ITDatumIID, (void **) &rv) ==
        IT_QUERYINTERFACE_SUCCESS)
        {
  3. Extract the data pointer from the object into an application pointer.
    char *pch = (char *)rv->Data();
  4. Search the data types for a match.
    char match[] = "Informix";
    
    char *found = strstr(pch, match);
  5. Release the ITDatum interface.
    rv->Release();