Access smart large objects

In a database, smart large objects are in columns with the data type CLOB or BLOB. A smart-large-object column contains an LO handle that describes the smart large object, including the location of its data in an sbspace. This LO handle does not contain the actual smart-large-object data.

When a query retrieves a smart large object (a BLOB or CLOB column), the mi_value() and mi_value_by_name() functions return the MI_NORMAL_VALUE value status. For a BLOB or CLOB column, the MI_DATUM structure that these functions pass back contains the LO handle for the smart large object. The control mode of the query data determines whether this LO handle is in text or binary representation, as follows.
Query control mode Contents of value buffer
Text representation Character string that contains the hexadecimal dump of the LO-handle structure
Binary representation Pointer to an LO-handle structure (MI_LO_HANDLE *)

When query data is in binary representation, the mi_value() and mi_value_by_name() functions pass back the LO handle by reference. Regardless of whether you obtain a smart large object in a C UDR or a client LIBMI application, the MI_DATUM structure that these functions pass back contains a pointer to an LO handle (MI_LO_HANDLE *).

To make a copy of the LO handle within your DataBlade® API module, you can copy the contents of the value buffer, as follows:
MI_LO_HANDLE *blob_col, my_LO_hdl;
...
switch ( mi_value(row, i, col_id, &blob_col, &length) )
   {
   ...
   case MI_NORMAL_VALUE:

      my_LO_hdl = *blob_col;

To obtain the smart-large-object data, use the binary representation of the LO handle with the functions of the smart-large-object interface. The smart-large-object interface allows you to access smart-large-object data through its LO handle. You access the smart-large-object data with read, write, and seek operations similar to an operating-system file.

The following code fragment implements the get_smart_large_object() function, which reads smart-large-object data in 4,000-byte chunks:
#define BUFSIZE 4000;

mi_integer get_smart_large_object(conn, LO_hndl)
   MI_CONNECTION *conn;
   MI_LO_HANDLE *LO_hndl;
{
   MI_LO_FD LO_fd;
   mi_char read_buf[BUFSIZE];

/* Open the selected smart large object */
LO_fd = mi_lo_open(conn, LO_hndl, MI_LO_RDONLY);
if ( LO_fd == MI_ERROR )
   /* handle error */
   return (-1);
else
   {
   while ( mi_lo_read(conn, LO_fd, read_buf, BUFSIZE) 
         != MI_ERROR )
      {
      /* perform processing on smart-large-object data */
      ...
      }
   mi_lo_close(conn, LO_fd);
   return ( 0 );
   }
}