473,403 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

UDF Driver?

I was reading the DB2 for Linux/Unix/Windows (V7.2) manuals just now to get
some background information about UDFs when I came across this:

"Note that valuable debugging tools such as printf() do not normally work as
debugging aids for your UDF, because the UDF normally runs in a background
process where stdout has no meaning. As an alternative to using printf(), it
may be possible for you to instrument your UDF with file output logic, and
for debugging purposes write indicative data and control information to a
file.
Another technique to debug your UDF is to write a driver program for
invoking the UDF outside the database environment. With this technique, you
can invoke the UDF with all kinds of marginal or erroneous input arguments
to attempt to provoke it into misbehaving. In this environment, it is not a
problem to use printf() or a source level debugger. "

I could certainly do the File I/O approach described in the first paragraph
but I'd really like to try the technique described in the second paragraph.
Unfortunately, I'm not at all clear on how to develop a UDF driver of the
kind described. Does anyone have a version of such a program, even just a
basic one that I could adapt? Could you possibly post it here or send it to
me directly?

Please note that I'm using DB2 V7.2 so I'm a little bit "back-level".

--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare
Nov 12 '05 #1
7 1977
Rhino wrote:
I was reading the DB2 for Linux/Unix/Windows (V7.2) manuals just now to get
some background information about UDFs when I came across this:

"Note that valuable debugging tools such as printf() do not normally work as
debugging aids for your UDF, because the UDF normally runs in a background
process where stdout has no meaning. As an alternative to using printf(), it
may be possible for you to instrument your UDF with file output logic, and
for debugging purposes write indicative data and control information to a
file.
Another technique to debug your UDF is to write a driver program for
invoking the UDF outside the database environment. With this technique, you
can invoke the UDF with all kinds of marginal or erroneous input arguments
to attempt to provoke it into misbehaving. In this environment, it is not a
problem to use printf() or a source level debugger. "

I could certainly do the File I/O approach described in the first paragraph
but I'd really like to try the technique described in the second paragraph.
Unfortunately, I'm not at all clear on how to develop a UDF driver of the
kind described. Does anyone have a version of such a program, even just a
basic one that I could adapt? Could you possibly post it here or send it to
me directly?

Please note that I'm using DB2 V7.2 so I'm a little bit "back-level".

I guess all you need is a main() and then you invoke the UDF from C (or
whatever).

Cheers
Serge

--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2

"Serge Rielau" <sr*****@ca.ibm.com> wrote in message
news:38*************@individual.net...
Rhino wrote:
I was reading the DB2 for Linux/Unix/Windows (V7.2) manuals just now to get some background information about UDFs when I came across this:

"Note that valuable debugging tools such as printf() do not normally work as debugging aids for your UDF, because the UDF normally runs in a background process where stdout has no meaning. As an alternative to using printf(), it may be possible for you to instrument your UDF with file output logic, and for debugging purposes write indicative data and control information to a file.
Another technique to debug your UDF is to write a driver program for
invoking the UDF outside the database environment. With this technique, you can invoke the UDF with all kinds of marginal or erroneous input arguments to attempt to provoke it into misbehaving. In this environment, it is not a problem to use printf() or a source level debugger. "

I could certainly do the File I/O approach described in the first paragraph but I'd really like to try the technique described in the second paragraph. Unfortunately, I'm not at all clear on how to develop a UDF driver of the kind described. Does anyone have a version of such a program, even just a basic one that I could adapt? Could you possibly post it here or send it to me directly?

Please note that I'm using DB2 V7.2 so I'm a little bit "back-level".

I guess all you need is a main() and then you invoke the UDF from C (or
whatever).

I tried this but I can't get debugger (Eclipse 3.0.1) to see the breakpoints
in the UDF so that I can step through the UDF. Is there some special
technique I need to use? My code is written in Java. I have no problem
getting my debugger to see breakpoints set in other classes but the same
techniques don't work for the UDF....

Rhino
Nov 12 '05 #3
Rhino wrote:
"Serge Rielau" <sr*****@ca.ibm.com> wrote in message
news:38*************@individual.net...
Rhino wrote:
I was reading the DB2 for Linux/Unix/Windows (V7.2) manuals just now to
get
some background information about UDFs when I came across this:

"Note that valuable debugging tools such as printf() do not normally
work as
debugging aids for your UDF, because the UDF normally runs in a
background
process where stdout has no meaning. As an alternative to using
printf(), it
may be possible for you to instrument your UDF with file output logic,
and
for debugging purposes write indicative data and control information to
a
file.
Another technique to debug your UDF is to write a driver program for
invoking the UDF outside the database environment. With this technique,
you
can invoke the UDF with all kinds of marginal or erroneous input
arguments
to attempt to provoke it into misbehaving. In this environment, it is
not a
problem to use printf() or a source level debugger. "

I could certainly do the File I/O approach described in the first
paragraph
but I'd really like to try the technique described in the second
paragraph.
Unfortunately, I'm not at all clear on how to develop a UDF driver of
the
kind described. Does anyone have a version of such a program, even just
a
basic one that I could adapt? Could you possibly post it here or send it
to
me directly?

Please note that I'm using DB2 V7.2 so I'm a little bit "back-level".


I guess all you need is a main() and then you invoke the UDF from C (or
whatever).


I tried this but I can't get debugger (Eclipse 3.0.1) to see the breakpoints
in the UDF so that I can step through the UDF. Is there some special
technique I need to use? My code is written in Java. I have no problem
getting my debugger to see breakpoints set in other classes but the same
techniques don't work for the UDF....

Rhino

Sorry, I'm (still :-0) Java illiterate. I hope someone else jumps in here.
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #4

"Serge Rielau" <sr*****@ca.ibm.com> wrote in message
news:38*************@individual.net...
Rhino wrote:
"Serge Rielau" <sr*****@ca.ibm.com> wrote in message
news:38*************@individual.net...
Rhino wrote:

I was reading the DB2 for Linux/Unix/Windows (V7.2) manuals just now to
get
some background information about UDFs when I came across this:

"Note that valuable debugging tools such as printf() do not normally


work as
debugging aids for your UDF, because the UDF normally runs in a


background
process where stdout has no meaning. As an alternative to using


printf(), it
may be possible for you to instrument your UDF with file output logic,


and
for debugging purposes write indicative data and control information to


a
file.
Another technique to debug your UDF is to write a driver program for
invoking the UDF outside the database environment. With this technique,


you
can invoke the UDF with all kinds of marginal or erroneous input


arguments
to attempt to provoke it into misbehaving. In this environment, it is


not a
problem to use printf() or a source level debugger. "

I could certainly do the File I/O approach described in the first


paragraph
but I'd really like to try the technique described in the second


paragraph.
Unfortunately, I'm not at all clear on how to develop a UDF driver of


the
kind described. Does anyone have a version of such a program, even just


a
basic one that I could adapt? Could you possibly post it here or send
it
to
me directly?

Please note that I'm using DB2 V7.2 so I'm a little bit "back-level".
I guess all you need is a main() and then you invoke the UDF from C (or
whatever).


I tried this but I can't get debugger (Eclipse 3.0.1) to see the breakpoints in the UDF so that I can step through the UDF. Is there some special
technique I need to use? My code is written in Java. I have no problem
getting my debugger to see breakpoints set in other classes but the same
techniques don't work for the UDF....

Rhino

Sorry, I'm (still :-0) Java illiterate. I hope someone else jumps in here.

=========
I am not Java guy. But can you say more clearly?
(1) The UDF code is written in C language, right?
(2) The testing program is written in Java lanaguage, right?



--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab

Nov 12 '05 #5

"Fan Ruo Xin" <fa*****@sbcglobal.net> wrote in message
news:NO****************@newssvr17.news.prodigy.com ...

"Serge Rielau" <sr*****@ca.ibm.com> wrote in message
news:38*************@individual.net...
Rhino wrote:
"Serge Rielau" <sr*****@ca.ibm.com> wrote in message
news:38*************@individual.net...

>Rhino wrote:
>
>>I was reading the DB2 for Linux/Unix/Windows (V7.2) manuals just now to
get

>>some background information about UDFs when I came across this:
>>
>>"Note that valuable debugging tools such as printf() do not normally

work as

>>debugging aids for your UDF, because the UDF normally runs in a

background

>>process where stdout has no meaning. As an alternative to using

printf(), it

>>may be possible for you to instrument your UDF with file output logic,
and

>>for debugging purposes write indicative data and control information to
a

>>file.
>>Another technique to debug your UDF is to write a driver program for
>>invoking the UDF outside the database environment. With this technique,
you

>>can invoke the UDF with all kinds of marginal or erroneous input

arguments

>>to attempt to provoke it into misbehaving. In this environment, it is

not a

>>problem to use printf() or a source level debugger. "
>>
>>I could certainly do the File I/O approach described in the first

paragraph

>>but I'd really like to try the technique described in the second

paragraph.

>>Unfortunately, I'm not at all clear on how to develop a UDF driver of

the

>>kind described. Does anyone have a version of such a program, even just
a

>>basic one that I could adapt? Could you possibly post it here or send it
to

>>me directly?
>>
>>Please note that I'm using DB2 V7.2 so I'm a little bit "back-level".
>>
>
>I guess all you need is a main() and then you invoke the UDF from C (or>whatever).
>

I tried this but I can't get debugger (Eclipse 3.0.1) to see the breakpoints in the UDF so that I can step through the UDF. Is there some special
technique I need to use? My code is written in Java. I have no problem
getting my debugger to see breakpoints set in other classes but the same techniques don't work for the UDF....

Rhino

Sorry, I'm (still :-0) Java illiterate. I hope someone else jumps in

here. =========
I am not Java guy. But can you say more clearly?
(1) The UDF code is written in C language, right?
(2) The testing program is written in Java lanaguage, right?

The UDF code and the testing program are both written in Java.

I'm using Eclipse 3.0.1 in Windows XP.

Here is the UDF:
================================================== ======
import java.sql.SQLException;
import COM.ibm.db2.app.UDF;

public class TextFuncs extends UDF {

public static String reverse (String input)
throws SQLException {

try {
StringBuffer reversedStringBuffer = new StringBuffer();
for (int ix=input.length(); ix>0; ix--) {
reversedStringBuffer.append(input.substring(ix-1, ix));
}

/* Set the output string to be the reverse of the input string. */
return(reversedStringBuffer.toString());
}
catch (Exception excp) {
throw new SQLException("Invalid Operation", "38702");
}
}
}
================================================== ======
Here is the UDFDriver program:
================================================== ======
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javadb2.JDBC01;

public class UDFDriver {

private final String CLASS_NAME = getClass().getName();

private Connection conn01 = null;

public static void main(String[] args) {

new UDFDriver();
}

/**
* Constructor
*/
public UDFDriver() {
super();

System.out.println("Welcome to " + CLASS_NAME + "!\n");

System.out.println("\nLoad the JDBC driver....");
loadDriver();

System.out.println("\nConnect to the database....");
connectToDatabase();

System.out.println("\nExecute functions....");
executeFunctions();
}

/**
* Load the JDBC driver.
*/
private void loadDriver() {

String METHOD_NAME = "loadDriver()";

String jdbcDriverName = "COM.ibm.db2.jdbc.app.DB2Driver";

/* Load the JDBC driver. */
try {
Class.forName(jdbcDriverName);
} catch (ClassNotFoundException excp) {
System.err
.println(CLASS_NAME
+ "."
+ METHOD_NAME
+ " - Encountered ClassNotFoundException while
attempting to load JDBC driver "
+ jdbcDriverName + ". Error: " + excp);
excp.printStackTrace();
System.exit(16);
}
}

/**
* Get a connection to the database.
*
*/
private void connectToDatabase() {

String METHOD_NAME = "connectToDatabase()";

/* Initialize the variables used to get the connection. */
String databaseName = "sample";
String url = "jdbc:db2:" + databaseName;
String loginName = "db2admin";
String password = "db2admin";

/* Connect to the database. */
try {
conn01 = DriverManager.getConnection(url, loginName, password);
} catch (SQLException sql_excp) {
System.err.println(CLASS_NAME + "." + METHOD_NAME
+ " - Encountered SQLException on connect to URL " + url
+ ". Error: "
+ sql_excp);
sql_excp.printStackTrace();
System.exit(16);
}

/* Set autocommit off. */
try {
conn01.setAutoCommit(false);
System.out.println("Turn off autocommit...");
} catch (SQLException sql_excp) {
System.err.println(CLASS_NAME + "." + METHOD_NAME
+ " - Encountered SQLException on attempt to turn
autocommit off. Error: "
+ sql_excp);
sql_excp.printStackTrace();
System.exit(16);
}
}

private void executeFunctions() {

String METHOD_NAME = "executeFunctions()";

String queryTableSQL =
"select lastname, rhino.reverse(lastname) " +
"from rhino.employee " +
"where workdept = 'D21'";

/*
* Query the demonstration table to get information about certain
* employees.
*/
Statement queryTableStmt = null;
ResultSet rs01 = null;
try {
queryTableStmt = conn01.createStatement();
rs01 = queryTableStmt.executeQuery(queryTableSQL);
} catch (SQLException excp) {
System.err.println(CLASS_NAME + "." + METHOD_NAME
+ " - Encountered SQLException while trying to get
information from "
+ "Employee table. Error: " + excp);
excp.printStackTrace();
System.exit(16);
}

/*
* Print a title line above the result set. The static method pad()
is
* used to align the column titles and underlines.
*/
String spaces = " ";
System.out.println(JDBC01.pad("LASTNAME", ' ', 'T', 15) + spaces
+ JDBC01.pad("REVERSED", ' ', 'T', 15));
System.out.println(JDBC01.pad("--------", ' ', 'T', 15) + spaces
+ JDBC01.pad("--------", ' ', 'T', 15));

/* Initialize the host variables used for handling the result set.
*/
String lastname = null;
String reversed = null;

/*
* Print each line of the result set. The static method pad() is
again used
* to align the data values with the column titles.
*/
try {
while (rs01.next()) {
lastname = rs01.getString(1);
reversed = rs01.getString(2);
System.out.println(JDBC01.pad(lastname, ' ', 'T', 15) +
spaces + JDBC01.pad(reversed, ' ', 'T', 15));
}
} catch (SQLException sql_excp) {
System.err.println(CLASS_NAME + "." + METHOD_NAME
+ " - Encountered SQLException while reading Employee "
+ "table. Error: " + sql_excp);
sql_excp.printStackTrace();
System.exit(16);
}

/* Close the result set, dispose of the statement, and commit. */
try {
rs01.close();
queryTableStmt.close();
conn01.commit();
} catch (SQLException sql_excp) {
System.err.println(CLASS_NAME + "." + METHOD_NAME
+ " - Encountered SQLException while closing Employee"
+ " result set, closing statement, or committing. Error:
" + sql_excp);
sql_excp.printStackTrace();
System.exit(16);
}
}
}
================================================== ======

Please note that I'm not actually having any problems with my UDF; it is
very simple and works perfectly. I just want to figure out how to step
through the code in the Eclipse debugger in case I have problems with more
complex UDFs later on.

Rhino
Nov 12 '05 #6
Rhino wrote:
I guess all you need is a main() and then you invoke the UDF from C (or
whatever).

I tried this but I can't get debugger (Eclipse 3.0.1) to see the
breakpoints in the UDF so that I can step through the UDF. Is there some
special technique I need to use? My code is written in Java. I have no
problem getting my debugger to see breakpoints set in other classes but
the same techniques don't work for the UDF....


A UDF is just like any other Java code. A method like "static public void
whatever(parms)" can be called like any other method. In fact, DB2 does
just the same.

What I did once was related to C code, but it just works the same in Java.
I wrote a "main" function, and that function set up all the parameters
required by the UDF and called the UDF with those parameters. It worked
very well and was extremely helpful to debug the UDF.

If this doesn't work in your environment, then I'd suspect that you have
some sort of problem to link all the pieces together.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #7
Rhino wrote:
The UDF code and the testing program are both written in Java.

I'm using Eclipse 3.0.1 in Windows XP.

Here is the UDF:
================================================== ======
import java.sql.SQLException;
import COM.ibm.db2.app.UDF;

public class TextFuncs extends UDF {

public static String reverse (String input)
throws SQLException {

try {
StringBuffer reversedStringBuffer = new StringBuffer();
for (int ix=input.length(); ix>0; ix--) {
reversedStringBuffer.append(input.substring(ix-1, ix));
}

/* Set the output string to be the reverse of the input string. */
return(reversedStringBuffer.toString());
}
catch (Exception excp) {
throw new SQLException("Invalid Operation", "38702");
}
}
}
================================================== ======
Here is the UDFDriver program:
================================================== ======
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javadb2.JDBC01;

public class UDFDriver { [...] private void executeFunctions() {

String METHOD_NAME = "executeFunctions()";

String queryTableSQL =
"select lastname, rhino.reverse(lastname) " +
You are not using the "2nd technique" here. You still have a SQL statement
in the picture, and that involves to call DB2 and get all the logic of the
database engine involved again. And because your UDF is called from DB2,
you run into the same issue mentioned before, i.e. you cannot (yet) debug
UDFs that run inside DB2.
"from rhino.employee " +
"where workdept = 'D21'"; [...]
================================================== ======

Please note that I'm not actually having any problems with my UDF; it is
very simple and works perfectly. I just want to figure out how to step
through the code in the Eclipse debugger in case I have problems with more
complex UDFs later on.


You should use such a driver outside of the DB2 environment:

public class UDFDriver
{
public static main()
{
String str = "test string";
// next comes the call to the UDF right as DB2 would do it
str = TextFucnc.reverse(str);

System.out.println(str);
}
}

Now you can use your favorite debugger and step into the function. Once it
is properly debugged, you can integrate it with DB2 and call it from SQL
statements.

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Philip | last post by:
Hi, i'am looking for a db2 driver for windows the DB2 servers runs on as400 if that makes any difference. Thanks, Philip
3
by: Jim Hubbard | last post by:
My own searches have proven to be of little help in understanding the implementation of this technology (available since Win98). Any information that you could share on Display Driver Management...
0
by: CS Loh | last post by:
Hi, I install a filter driver through INF file to a 3rd party audio device (with driver). The filter driver works well on the 3rd party driver. However upon uninstallation of the filter driver,...
0
by: Bing | last post by:
Hi, I am configuring the same DB2 v8.1 JDBC universal driver (db2jcc.jar and db2jcc_license_cisuz.jar) from DB2 SP5 fix pack under WSAD 5.1.x environment and WebSphere application Server 5.0.2...
2
by: Raquel | last post by:
Read this about the Universal JDBC Driver.... "In a Type 2 mode, the Universal JDBC driver provides local application performance gains (because it avoids using TCP/IP protocol to communicate to...
3
by: Andrew Johnson | last post by:
Hi, I am trying to make a UBD DB2 7.2 connection using the Java COM.ibm.db2.jdbc.app.DB2Driver via Tomcat 3.2.1 on Solaris (and also on an AIX system with 3.3.1). I am attempting this either...
3
by: Rakesh | last post by:
Hi, I want to get connection to a DB2 database using the driver COM.ibm.db2.jdbc.DB2XADataSource. I have also included 'db2java.zip' in the classpath. However I am getting the exception ...
12
by: Steve | last post by:
I wrote a simple virtual device driver int15.sys, Is C# support load the device driver from AP?
3
by: bb | last post by:
I have a windows network device driver written in c++ and a user interface im porting to c#, my problem is i dont seem to be getting notified of the event calls from the driver to the c# app im...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.