Accessing the Value of a Large Object | Teradata Vantage - Accessing the Value of a Large Object - Advanced SQL Engine - Teradata Database

SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
qwr1571437338192.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1147
lifecycle
previous
Product Category
Teradata Vantage™
Teradata provides the following library functions for accessing the value of a large object:
  • FNC_LobOpen
  • FNC_LobRead
  • FNC_LobClose

To access the value of a large object, follow these steps:

  1. Call FNC_LobOpen to establish a read context for the large object.

    FNC_LobOpen returns a read context handle for the large object through an output argument of type LOB_CONTEXT_ID. The sqltypes_td.h header file defines LOB_CONTEXT_ID like this:

    typedef long LOB_CONTEXT_ID;

  2. Call FNC_LobRead to read the large object and place the data into a BYTE buffer.

    One of the input arguments to FNC_LobRead is the read context handle that was returned by FNC_LobOpen.

  3. Call FNC_Close to release all resources associated with the read context.

For detailed information on each function, see C Library Functions.

Here is a code excerpt that shows how to access the value of a large object:

#define BUFFER_SIZE 500
   
void do_something ( LOB_LOCATOR *a,
                    LOB_RESULT_LOCATOR *result,
                    char sqlstate[6] )
{
   BYTE            buffer[BUFFER_SIZE];
   FNC_LobLength_t actlen;
   LOB_CONTEXT_ID  id;

   /* Establish a read context for the LOB input argument */
   FNC_LobOpen(*a, &id, 0, BUFFER_SIZE);
   
   /* Read the LOB and place the data into a BYTE buffer */
   FNC_LobRead(id, buffer, BUFFER_SIZE, &actlen);
   
   /* Release the resources associated with the read context */
   FNC_LobClose(id);
   
    ...
  
}

For a complete example, see C Scalar Function Using LOBs.