Reading and Processing the Blob Data

From InterBase

Go Up to Reading Data from a Blob

To read and process the Blob data:

  1. Declare and initialize a Blob handle:
    isc_blob_handle blob_handle; /* Declare a Blob handle. */
    blob_handle = NULL; /* Set handle to NULL before using it */
  2. Create a buffer for holding each Blob segment as it is read. Its size should be the maximum size segment your program expects to be read from the Blob.
    char blob_segment[80];
  3. Declare an unsigned short variable into which InterBase will store the actual length of each segment read:
    unsigned short actual_seg_len;
  4. Open the Blob with the fetched blob_id:
    isc_open_blob2( status_vector, &db_handle, &trans,
    &blob_handle, /* set by this function to refer to the Blob */
    &blob_id, /* Blob ID put into out_sqlda by isc_dsql_fetch() */
    0, /* BPB length = 0; no filter will be used */
    NULL ); /* NULL BPB, since no filter will be used */
  5. Read all the Blob data by calling isc_get_segment() repeatedly to get each Blob segment and its length. Process each segment read. In the following example, “processing” consists of printing each Blob as it is read:
    blob_stat = isc_get_segment( status_vector,
    &blob_handle, /* set by isc_open_blob2()*/
    &actual_seg_len, /* length of segment read */
    sizeof(blob_segment), /* length of segment buffer */
    blob_segment ); /* segment buffer */
    while (blob_stat == 0 || status_vector[1] == isc_segment) {
    /* isc_get_segment returns 0 if a segment was successfully read. */
     * status_vector[1] is set to isc_segment if only part of a */
     * segment was read due to the buffer (blob_segment) not being */
     * large enough. In that case, the following calls to */
     * isc_get_segment() read the rest of the buffer. */
    printf("%*.*s", actual_seg_len, actual_seg_len, blob_segment);
    blob_stat = isc_get_segment(status_vector, &blob_handle,
    &actual_seg_len, sizeof(blob_segment), blob_segment);
  6. Close the Blob:
    isc_close_blob(status_vector, &blob_handle);

Advance To: