UDF Overview

From InterBase
Jump to: navigation, search

Go Up to Working with UDFs and Blob Filters


Just as InterBase has built-in SQL functions such as MIN(), MAX(), and CAST(), it also supports libraries of user-defined functions (UDFs). User-defined functions (UDFs) are host-language programs for performing customized, often-used tasks in applications. UDFs enable the programmer to modularize an application by separating it into more reusable and manageable units. Possibilities include statistical, string, and date functions. UDFs are extensions to the InterBase server and execute as part of the server process.

InterBase provides a library of UDFs, documented in The InterBase UDF Library section of this chapter.

You can access UDFs and Blob filters through isql or a host-language program. You can also access UDFs in stored procedures and trigger bodies.

UDFs can be used in a database application anywhere that a built-in SQL function can be used. This chapter describes how to create UDFs and how to use them in an application.

Creating a UDF is a three-step process:

  1. Write the function in any programming language that can create a shared library. Functions written in Java are not supported.
  2. Compile the function and link it to a dynamically linked or shared library.
  3. Use DECLARE EXTERNAL FUNCTION to declare each UDF to each database in which you need to use it.

Location of ib_udf Files and Library

  • The UDF script, ib_udf.sql is located in the <InterBase_home>/examples/udf directory.
For example the file is located in the following directory:
x:\ProgramData\Embarcadero\InterBase\gds_db\examples\ib_udf.sql
  • The UDF library, named ib_udf.dll on Windows platforms and ib_udf on UNIX platforms is located in <InterBase_home>/UDF and its functions are all implemented using the standard C library.

Put the ib_udf.dll into your UDF directory (if it is not already there) and run the ib_udf.sql script to define the functions in it. You can read the comments in the script for what each does and expected input.

Once that script is applied to your database, you can call the UDF functions defined in that script.

Advance To: