Sample code to select an existing smart large object
Suppose you want to select the following data from a smart
large object that was inserted into a CLOB column named cat_descr in
the catalog2 table:
The rain in Spain stays mainly in the plain. In Hartford, Hereford, and
Hampshire, hurricanes hardly happen.
The following code fragment assumes that the descrip LO
handle identifies the smart large object that was selected from the
CLOB column. This LO handle was obtained with the SELECT statement
on the cat_descr column.
#include "int8.h"
#include "mi.h"
#define BUFSZ 1000
{
MI_CONNECTION *conn;
MI_LO_HANDLE *descrip;
MI_LO_FD lofd;
char buf[BUFSZ];
mi_integer buflen = BUFSZ;
mi_int8 offset;
mi_integer numbytes;
...
/* Use the LO handle to identify the smart large object
* to open and get an LO file descriptor.
*/
lofd = mi_lo_open(conn, descrip, MI_LO_RDONLY);
if ( lofd < 0 )
handle_lo_error("mi_lo_open()");
/* Use the LO file descriptor to read the data of the
* smart large object.
*/
ifx_int8cvint(0, &offset);
strcpy(buf, "");
numbytes = mi_lo_readwithseek(conn, lofd, buf, buflen,
&offset, MI_LO_SEEK_CUR);
if ( numbytes == 0 )
handle_lo_error("mi_lo_readwithseek()");
/* Close the smart large object */
mi_lo_close(lofd);
}
The mi_lo_readwithseek() function reads 1000 bytes of data from the smart large object that lofd identifies to the buf user-defined buffer.