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

Teradata Vantage™ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
16.20
Release Date
April 2020
Content Type
Programming Reference
Publication ID
B035-1147-162K
Language
English (United States)
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.