16.20 - FNC_GeomGetResultWKBBlob - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL External Routine Programming

Advanced SQL Engine
Teradata Database
Release Number
Release Date
April 2020
Content Type
Programming Reference
Publication ID
English (United States)


Returns the LOB locator to a Well-Known Binary (WKB) BLOB for an ST_Geometry that is defined to be the return value of a UDF/UDM or an INOUT or OUT parameter for an external stored procedure.


FNC_GeomGetResultWKBBlob(GEO_HANDLE            geoHandle,
                         LOB_RESULT_LOCATOR*   geoBlob)
GEO_HANDLE geoHandle
A handle to an ST_Geometry type that is defined to be a return value for a UDF/UDM or an INOUT/OUT parameter to an external stored procedure.
Pointer to the LOB locator that is used to set the ST_Geometry type return value.

Usage Notes

The FNC_GeomGetResultWKBBlob function gets a result LOB locator that is used to set the ST_Geometry return value. The ST_Geometry Handle geoHandle is passed as input and a LOB result locator geoBlob is returned from the function. The user can then use LOB FNC routines to set the BLOB value using the geoBlob locator. The Well-Known Binary value should be written to the BLOB.

The FNC_GeomGetResultWKBBlob should be called only for LOB-based ST_Geometry values. If used with inline ST_Geometry values, a 7579 error is generated: FNC_GeomGetResultWKBBlob can only be called on LOB-based ST_Geometry type.

Example: Using FNC_GeomGetResultWKBBlob and FNC_GeomSetWKBBlob to retrieve and set the value of a return ST_Geometry

The following function takes a ST_Geometry parameter and returns an ST_Geometry that has the same value. It first retrieves the Well-Known Binary format from the input geometry. It then retrieves the LOB result locator from the return ST_Geometry, appends the WKB to it, and then sets the value of the return ST_Geometry.

#define SQL_TEXT Latin_Text
#include <sqltypes_td.h>
#include <string.h>

void geo_wkb( GEO_HANDLE  *geo_in,
              GEO_HANDLE  *geo_out,
              int         *indicator_geo_in,
              int         *indicator_geo_out,
              char        sqlstate[6],
              SQL_TEXT    extname[129],
              SQL_TEXT    specific_name[129],
              SQL_TEXT    error_message[257])
    LOB_RESULT_LOCATOR geoBlob_out;
    LOB_LOCATOR geoBlob_in;
    BYTE buffer[64000];
    FNC_LobLength_t actlen;
    int trunc_err = 0;
    FNC_LobLength_t blob_length;
    int srid = -1;
    int max_length, max_length2, numLobs, numLobs2;

    /* If input is null set return value to null. */
    if (*indicator_geo_in == -1 )
        *indicator_geo_out = -1;

    /* Get the Input Geometry Info */
     FNC_GetGeometryInfo(*geo_in,&max_length, &numLobs);

    /* Get the Output Geometry Info */
     FNC_GetGeometryInfo(*geo_out,&max_length2, &numLobs2);

     * Copy geo_in ST_Geometry value to geo_out ST_Geometry value.
    if(numLobs ==1 && numLobs2 ==1)
      /* Get the LOB_RESULT_LOCATOR of geo_out. */
       FNC_GeomGetResultWKBBlob(*geo_out, &geoBlob_out); 

      /* Get the LOB_LOCATOR and srid of the input ST_Geometry value. */
       FNC_GeomGetWKBBlob(*geo_in, &geoBlob_in, &srid); 

      FNC_LobOpen(geoBlob_in, &id, 0, 0);
      blob_length = FNC_GetLobLength(geoBlob_in);
      while (FNC_LobRead(id, buffer, blob_length, &actlen) == 0 
                 && !trunc_err)
        trunc_err = FNC_LobAppend(geoBlob_out, buffer, actlen, &actlen);

      /* Set the return ST_Geometry value */
       FNC_GeomSetWKBBlob(*geo_out, geoBlob_out, srid);