Example: FNC_GetXMLResultBlob and FNC_SetXMLBlob - Analytics Database - Teradata Vantage

SQL External Routine Programming

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Published
June 2022
Language
English (United States)
Last Update
2023-07-11
dita:mapPath
iiv1628111441820.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
dita:id
B035-1147
lifecycle
latest
Product Category
Teradata Vantageā„¢

The following function takes an input BLOB value and returns an XML value back to the user.

CREATE FUNCTION xmlUDF7(P1 BLOB AS LOCATOR)
RETURNS XML
NO SQL
PARAMETER STYLE SQL
DETERMINISTIC
LANGUAGE C
EXTERNAL NAME 'CS!xmlUDF7!xmlUDF7.c';

void xmlUDF7(LOB_LOCATOR* input_blob,
             XML_HANDLE  *xml_handle,
             int*       indicator_inputBLOB,
             int*       indicator_returnXML,
             char       sqlstate[6],
             SQL_TEXT   extname[129],
             SQL_TEXT   specific_name[129],
             SQL_TEXT   error_message[257] )
{
     LOB_RESULT_LOCATOR xmlBlob;
     BYTE buffer[100000];
     LOB_CONTEXT_ID id;
     FNC_LobLength_t actlen;
     int trunc_err = 0;
     int numLobs;
     FNC_XMLSize_t xmlSize;
    
     /* Get the XML Size */
      FNC_GetXMLInfo(*xml_handle, &xmlSize, &numLobs); 

     if(numLobs ==1 )
     {

       /* Read XML return lob locator */ 
        FNC_GetXMLResultBlob(*xml_handle,&xmlBlob); 
      /* Use LOB FNC calls to read the input BLOB into the XML clob */                                                                                                                           
       FNC_LobOpen(*input_blob, &id, 0, 0);
        while( FNC_LobRead(id, buffer, 100000, &actlen) == 0 && !trunc_err)
        trunc_err = FNC_LobAppend(*xmlClob, buffer, actlen, &actlen);
       FNC_LobClose(id);

       /* Set the return XML value */
        FNC_SetXMLBlob(*xml_handle,xmlClob); 
       *indicator_returnXML = 0;
     }
 }