FETCH (BLOB)

From InterBase

Go Up to Statement and Function Reference (Language Reference Guide)


Retrieves the next available segment of a Blob column and places it in the specified local buffer. Available in gpre.

FETCH cursor INTO 
[:buffer [[INDICATOR] :segment_length];
Argument Description

<cursor>

Name of an open Blob cursor from which to retrieve segments

<buffer>

Host-language variable for holding segments fetched from the Blob column; user must declare the buffer before fetching segments into it

INDICATOR

Optional keyword indicating that a host-language variable for indicating the number of bytes returned by the FETCH follows

<segment_length>

Host-language variable used to indicate the number of bytes returned by the FETCH

Description: FETCH retrieves the next segment from a Blob and places it into the specified buffer.

The host variable, segment_length, indicates the number of bytes fetched. This is useful when the number of bytes fetched is smaller than the host variable, for example, when fetching the last portion of a Blob.

FETCH can return two SQLCODE values:

  • SQLCODE = 100 indicates that there are no more Blob segments to retrieve.
  • SQLCODE = 101 indicates that a partial segment was retrieved and placed in the local buffer variable.
Note:
To ensure that a host variable buffer is large enough to hold a Blob segment buffer during FETCH operations, use the SEGMENT option of the BASED ON statement.

To ensure that a host variable buffer is large enough to hold a Blob segment buffer during FETCH operations, use the SEGMENT option of the BASED ON statement.

Example: The following code, from an embedded SQL application, performs a BLOB FETCH:

while (SQLCODE != 100)
{
EXEC SQL
OPEN BLOB_CUR USING :blob_id;
EXEC SQL
FETCH BLOB_CUR INTO :blob_segment :blob_seg_len;
while (SQLCODE !=100 || SQLCODE == 101)
{
blob_segment{blob_seg_len + 1] = '\0';
printf("%*.*s",blob_seg_len,blob_seg_len,blob_segment);
blob_segment{blob_seg_len + 1] =  ;
EXEC SQL
FETCH BLOB_CUR INTO :blob_segment :blob_seg_len;
}
. . .
}

See Also

Advance To: