Home Page for the TeradataForum
 

Archives of the TeradataForum

Message Posted: Wed, 15 Sep 2004 @ 11:57:32 GMT


     
  <Prev Next>   <<First <Prev Next> Last>>  


Subj:   Re: UDF's without using C
 
From:   Dennis Calkins

Hi,

Just to complete this thread. Here is the UDF for Reverse_str. Please adjust the line

     EXTERNAL NAME 'CS!reverse_str_v!c:\dennis\udfs\reverse_str_v.c'

accordingly for your installation.

you can fully qualify the PATH to the C file for BTEQ.

Here are some examples I came up with where I might install the source files on my system. The path and name of the file are irrelevent provided you specify whatever you called the file correctly to the "replace function" command.

UNIX

     EXTERNAL NAME 'CS!reverse_str_v!/home/dennis/udfs/reverse_str.c'

WINDOWS

     EXTERNAL NAME 'CS!reverse_str_v!c:\dennis\udfs\reverse_str.c'

If you are using SQL ASSISTANT (ODBC based client) you must first FTP to source down to the TPA node and then use SS ( Server has Source ) instead of CS ( Client has Source ) since ODBC as a protocol doesn't support Client has source feature.

     EXTERNAL NAME 'SS!reverse_str_v!c:\dennis\udfs\reverse_str.c'

You will note if I am running BTEQ on my Windows TPA node ( like for the DEMO software ) I can specify either CS or SS since the client and the server are the same box.


     --------------  reverse_str.c -----------------

     #define SQL_TEXT Latin_Text
     #include "sqltypes_td.h"

     void reverse_str_v( VARCHAR_LATIN *inputString,
                         VARCHAR_LATIN  *result,
                         char sqlstate[6])
     {
         char *src2;
         char *src;
         char *dest;

          /* put the parameters in a couple locals */
         src = (char *)inputString;
         dest = (char *)result;

          /* position to the end of the string */
         src2 = (src + strlen(src) - 1);

          /* While we haven't reached the start of the string */
         while ( src2 >= src )
         {
              /* store the character from src position
                  into the dest string at dest position.
                 increment the dest position
                 decrement the src position.
              */
      *dest++ = *src2--;
         }

          /* make sure there is a trailing zero on the dest string */
         *dest = '\0';

         return;
     }

     ----------- install --------------------


     Replace FUNCTION reverse_str
     (myval VARCHAR(64000))
     RETURNS VARCHAR(64000)
     SPECIFIC reverse_str_v
     LANGUAGE C
     NO SQL
     DETERMINISTIC
     EXTERNAL NAME 'CS!reverse_str_v!c:\dennis\udfs\reverse_str.c'
     PARAMETER STYLE TD_GENERAL;


     ----------------- example run --------------------

      BTEQ -- Enter your DBC/SQL request or BTEQ command:
     sel reverse_str('dennis');

     sel reverse_str('dennis');

      *** Query completed. One row found. One column returned.
      *** Total elapsed time was 1 second.

     reverse_str('dennis')
     ---------------------------------------------------------------------------
     sinned


     
  <Prev Next>   <<First <Prev Next> Last>>  
 
 
 
 
 
 
 
 
  
  Top Home Privacy Feedback  
 
 
Copyright for the TeradataForum (TDATA-L), Manta BlueSky    
Copyright 2016 - All Rights Reserved    
Last Modified: 15 Jun 2023