We help IT Professionals succeed at work.

Can someone assist with a UDF script that calls a a Java or C++ routine to return DoubleMetaphone Keys?

Enuda
Enuda asked
on
Hi all,
I am in need of examples of a UDF scalar function that can call a Java or C++ routine to return the DoubleMetaphone keys for a name search or something like that. I have never written a UDF let alone one that call another routine so please provide as much  as possible  detail explanation of what the code is doing. This is rather urgent for a report I hae to prep for Monday. I will appreciate a good and helpful response soon.

Thank you all very much  
Comment
Watch Question

in which language do you want to write the udf?

Author

Commented:
Hi momi sabag,
The language is SQL...
why not writing the entire thing in java or C++ and make your life eaiser?

Author

Commented:
Hello again momi_sabag,
Thanks for your response here...I do need to get this solution ready by tomorrow. First, bear in mind I am working from a osition of relative ignorance of which language is easier to implement or maintain. As I said, this is my first foray into the land of UDF and its usage. I will love to be able to present the options for java ans C++. I read up about this Lawrence Phillip C++ double metaphone script and I think that is what my manger want to be able to call from a UDF. Why, I don't really know. But my task is to show it can be done. And from all that I have read so far, it seem this is doable, right?
Now, if I can be able to also show that, according to your statement that it can be more efficiently done in Java or C++, I will certainly like to have those solutions available to show how with the working example I may find.
The long and short of it is that I will appreciate what you can ponit me to.  If you have have or know of both java and C++ examples, please go ahead and point me to it. Important in this also is how to use the java or C++ versions if possible. The idea is to be able to call this routines for a phonetic name/word search from an application of some sort. My job is to make the routine available and how it is used is up to the developers...I hope you can see where I am comming from...

Thanks
Enuda
when you create a udf you can specify that it is an external function and you need to point db2 to the file that contains the actual implmentation, after you get that straight, the implementation of the function is just like any other program in the language you choose
read about it here
http://publib.boulder.ibm.com/infocenter/db2luw/v8//topic/com.ibm.db2.udb.doc/admin/r0004461.htm

Author

Commented:
Hello all,
I have gotten this far and now I am having problem building/registering the following UDF using the DB2 UDB Development Center. Anyone see something wrong with it? When I change the code a little bit to say JAVA, it build successfully but when it says Language C, it fails to build. Is there a keyword(s) I should or shouldn't use for language = C? Here are the UDF code:

 LANGUAGE C:   This fails
CREATE FUNCTION DMPHONECppScalar ( CWORD  VARCHAR(50))
     RETURNS Varchar(50)
     SPECIFIC DMPHONECppScalar
     EXTERNAL NAME 'CppUDFs!DoubleMetaphone'
     LANGUAGE C
     PARAMETER STYLE SQL
     DETERMINISTIC
     FENCED
     NOT NULL CALL
     NO SQL
     NO EXTERNAL ACTION  

 LANGUAGE Java:   This build successfully.
CREATE FUNCTION DMPHONEJavaScalar ( JWORD  VARCHAR(50))
     RETURNS Varchar(50)
     FENCED
     LANGUAGE JAVA
     PARAMETER STYLE JAVA
     SPECIFIC DMPHONEjAVAScalar
     EXTERNAL NAME 'javaUDFs.DoubleMetaphone'
     NO EXTERNAL ACTION
     CALLED ON NULL INPUT
     DETERMINISTIC
     NO SQL


Explore More ContentExplore courses, solutions, and other research materials related to this topic.