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

Shared Object Libraries

This section contains information about creating, loading, and replacing shared object libraries with the database server.

Creating a Shared Library

When you create external routines, you put them into a shared library that the database server can access.

Shared object files must be owned by the user ID that runs the database server. In a production installation, Universal Server runs as user informix and shared object files are owned by user informix.

To create a shared library

    1. Compile the source file into an object file with the C compiler.

    Include any necessary header files that the file needs, such as the library where the DataBlade API functions reside.

    2. Create a shared object library (.so file extension on Solaris systems) and load the object file(s) for the external routine(s).

    Put related routines into the same shared library. The following sample command loads the object file into the shared library:

    3. Put the shared library in a directory that is readable by user informix and set the permissions to 755 or 775 so that only the owner can write to the shared object files.

    If a shared object file has write permission set to all, and someone tries to execute a routine in the shared object file, the database server issues error -9793 and writes a message in the log file.

    4. Specify the path of the shared library in the CREATE FUNCTION (or CREATE PROCEDURE) statement when you register the external routine. CREATE FUNCTION abs_eq(integer, integer)
    RETURNS boolean
    EXTERNAL NAME
    '/usr/code/abs.so(abs_equal)'
    LANGUAGE C NOT VARIANT;

Loading a Shared Library into Memory

When an application or the database server invokes one of the UDRs in a shared library, the database server performs the following tasks:

    1. If the routine is overloaded, determines which UDR to execute, based upon the arguments specified in the routine invocation

    2. Locates the shared library that contains the UDR from the path column in the sysprocedures system catalog table

    3. Loads this shared library into memory, if the library is not already loaded

Use the onstat command-line utility with the -g dll option to view the dynamically loaded libraries in which your user-defined routines reside. Once the database server has loaded a shared library into memory, this library remains in memory until one of the following situations occurs:

    Once all user-defined routines are dropped, the database server automatically unloads the shared library from memory.

    All memory that the database server uses is released when the database server shuts down.

Replacing a Shared Object File

You can explicitly replace a shared library without bringing down the database server. You use one of the following user-defined functions that Informix provides to upgrade a shared library:

    In this syntax, module path is a character string that lists the full path of the shared library, and language name is either `c' or `spl'.

    In this syntax, <old module path> and <new module path> are each character strings that list the full path of a shared library, and language name is either `c' or `spl'.

    This ifx_replace_module function updates the sysprocedures system catalog with the new name or location.

These functions return one of the following integer values:

You can also execute these functions in a SELECT statement. For example, the following SELECT statement executes the ifx_reload_module() statement:

If you do not want the shared library replaced multiple times with this SELECT statement, ensure that the SELECT statement returns only one "row" of values.

E/C
When you execute these functions from within an INFORMIX-ESQL/C application, you must associate the EXECUTE FUNCTION statement with a function cursor. For more information on writing ESQL/C applications, refer to the
INFORMIX-ESQL/C Programmer's Manual.

Important: Do not overwrite a shared object file on disk while it is loaded in memory because you might cause the database server to stop functioning when the overwritten module is accessed or unloaded. Use the ifx_replace_module function to replace the shared object file.
To unload a module without restarting the database server, you must drop all routines in the module using the SQL DROP statement. After you drop all routines in the module and all instances of the routines finish executing, the database server removes the module from the memory map and records a message in the log file to indicate that the module is unloaded. After the module is unloaded, you can replace the shared object file and re-create its user-defined routines in the database.




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