Contents Index Calling external libraries from procedures External function prototypes

ASA SQL User's Guide
  Using Procedures, Triggers, and Batches
    Calling external libraries from procedures

Creating procedures and functions with external calls


This section presents some examples of procedures and functions with external calls.

DBA authority required 
You must have DBA authority to create procedures or functions that reference external libraries. This requirement is more strict than the RESOURCE authority required for creating other procedures or functions.
Syntax 

You can create a procedure that calls a function function_name in DLL library.dll as follows:

CREATE PROCEDURE dll_proc ( parameter-list )
EXTERNAL NAME 'function_name@library.dll'

If you call an external DLL from a procedure, the procedure cannot carry out any other tasks; it just forms a wrapper around the DLL.

An analogous CREATE FUNCTION statement is as follows:

CREATE FUNCTION dll_func ( parameter-list )
RETURNS data-type
EXTERNAL NAME 'function_name@library.dll'

In these statements, function_name is the exported name of a function in the dynamic link library, and library.dll is the name of the library. The arguments in parameter-list must correspond in type and order to the argument expected by the library function. The library function accesses the procedure argument using an API described in External function prototypes.

Any value returned by the external function is in turn returned by the procedure to the calling environment.

No other statements permitted 

A procedure that references an external function can include no other statements: its sole purpose is to take arguments for a function, call the function, and return any value and returned arguments from the function to the calling environment. You can use IN, INOUT, or OUT parameters in the procedure call in the same way as for other procedures: the input values get passed to the external function, and any parameters modified by the function are returned to the calling environment in OUT or INOUT parameters.

System-dependent calls 

You can specify operating-system dependent calls, so that a procedure calls one function when run on one operating system, and another function (presumably analogous) on another operating system. The syntax for such calls involves prefixing the function name with the operating system name. For example:

CREATE PROCEDURE dll_proc ( parameter-list )
EXTERNAL NAME
'Windows95:95_fn@95_lib.dll;WindowsNT:nt_fn@nt_lib.dll'

The operating system identifier must be one of WindowsNT, Windows95, UNIX, or NetWare.

If the list of functions does not contain an entry for the operating system on which the server is running, but the list does contain an entry without an operating system specified, the database server calls the function in that entry.

NetWare calls have a slightly different format than the other operating systems. All symbols are globally known under NetWare, so any symbol (such as a function name) exported must be unique to all NLMs on the system. Consequently, the NLM name is not necessary in the call as long as the NLM is already loaded.

It is recommended that you always use the libray name, regardless of whether the NLM is already loaded. If the NLM is not already loaded, you must provide a library name. The file extension .nlm is optional.

For more information about the CREATE PROCEDURE statement syntax, see CREATE PROCEDURE statement.

For more information about the CREATE FUNCTION statement syntax, see CREATE FUNCTION statement.


Contents Index Calling external libraries from procedures External function prototypes