INFORMIX
Extending INFORMIX-Universal Server: User-Defined Routines
Chapter 3: Designing a User-Defined Routine
Home Contents Index Master Index New Book

Registering External Routines

Routines can be functions or procedures. You use different SQL statements to register each type of routine.

Registering an External Function

When you want a routine to return a value, you must create that routine as a function. To create an external function, write the body of the function in a language other than SPL, then use the CREATE FUNCTION statement to register the function.

Important: To register an external UDR that is a function, you must use the CREATE FUNCTION statement. You cannot use the CREATE PROCEDURE statement to create an external function.
The following example registers an external function of the name equal in the database server and specifies the library where the function object module is stored. The equal() function takes two arguments of the data type udtype1 and returns a BOOLEAN value.

When you register an external function, the END FUNCTION keywords are optional. Registration for an external routine requires two special clauses that help the database server locate the routine:

EXTERNAL NAME "/usr/lib/udtype1/lib/libbtype1.so()"

For more information, see the CREATE FUNCTION statement in Chapter 1 of the Informix Guide to SQL: Syntax.

Registering an External Procedure

When you do not want your routine to return a value, you must create that the routine as a procedure. To create an external procedure, write the body of the procedure in a language other than SPL, then use the CREATE PROCEDURE statement to register the procedure. The following example shows how to register an external procedure:

The EXTERNAL NAME and LANGUAGE clauses work the same way for external procedures as is explained for external functions on page 3-10.

In the preceding example, the actual body of the procedure is named compare_n_insert and is located in the C-language library /usr/lib/udtype1/lib/libbtype2.so. If the EXTERNAL NAME clause does not specify an entry point within the library, the database server invokes the module at the default entry point, log_compare().

The following example also includes the SPECIFIC keyword to create a function alias, basetype2_lessthan. Once you use the SPECIFIC keyword to create a routine alias, you can use that alias in DROP statements.

For information about the CREATE PROCEDURE statement, see the CREATE PROCEDURE statement in Chapter 1 of the Informix Guide to SQL: Syntax.

Registering an External Routine with Modifiers

When you create an external routine, you can specify optional modifiers that help optimize how the database server executes the routine. The following example shows how to use the WITH clause to specify a set of modifiers when you create an external function:

Following the WITH keyword, the modifiers that you want to specify are enclosed within parentheses and separated by commas. The handlesnulls modifier indicates that the basetype2_lessthan() function (in the library /usr/lib/basetype1/lib/libbtype1.so) is written so that it can recognize when an SQL NULL argument is passed.

External functions support a different set of modifiers than external procedures.

Modifiers for External Functions

The database server supports the following modifiers for external functions:

For more information on the syntax of these modifiers, see the CREATE FUNCTION statement in Chapter 1 of the Informix Guide to SQL: Syntax.

Modifiers for External Procedures

The database server supports the following modifiers for external procedures:

For a list of the supported modifiers for external procedures, see the CREATE PROCEDURE statement in Chapter 1 of the Informix Guide to SQL: Syntax.




Extending INFORMIX-Universal Server: User-Defined Routines, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.