1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| UDF library placement
The rules for placing UDF libraries have changed since InterBase version 5. In InterBase 6
and later, InterBase finds a UDF library only if one of the following conditions is met:
The library is in interbase_home/UDF
The library in a directory other than interbase_home/UDF and the complete pathname to the
directory, including a drive letter in the case of a Windows server, is listed in the InterBase
configuration file.
InterBase finds the functions once you have declared them with DECLARE EXTERNAL
FUNCTION. You do not need to specify a path in the declaration.
The InterBase configuration file is called ibconfig on Windows machines and isc_config on
UNIX machines.
To specify a location for UDF libraries in a configuration file, enter a line of the following
form for Windows platforms:
EXTERNAL_FUNCTION_DIRECTORY "D:\Mylibraries\InterBase"
For UNIX, the line does not include a drive letter:
EXTERNAL_FUNCTION_DIRECTORY "/usr/local/lib/Mylibraries/InterBase"
Note that it is no longer sufficient to include a complete path name for the module in the
DECLARE EXTERNAL FUNCTION statement. You must list the path in the InterBase
configuration file if it is other than interbase_home/UDF.
IMPORTANT For security reasons, InterBase strongly recommends that you place your compiled
libraries in directories that are dedicated to InterBase libraries. Placing InterBase
libraries in directories such as C:\winnt40\system32 or /usr/lib permits access to all libraries
in those directories and is a serious security hole.
Example The following statement declares the TOPS() UDF to a database:
DECLARE EXTERNAL FUNCTION TOPS
CHAR(256), INTEGER, BLOB
RETURNS INTEGER BY VALUE
ENTRY_POINT 'TE1' MODULE_NAME 'TM1.DLL';
This example does not need the FREE_IT keyword because only cstrings, CHAR, and
VARCHAR return types require memory allocation. The module must be in InterBases UDF
directory or in a directory that is named in the configuration file.
CALLING A UDF
DEVELOPERS GUIDE 85
Example The following isql script declares three UDFs, ABS(), DATEDIFF(), and TRIM(), to the
employee.gdb database:
CONNECT 'employee.gdb';
DECLARE EXTERNAL FUNCTION ABS
DOUBLE PRECISION
RETURNS DOUBLE BY VALUE
ENTRY_POINT 'fn_abs' MODULE_NAME 'ib_udf';
DECLARE EXTERNAL FUNCTION DATEDIFF
DATE, DATE
RETURNS INTEGER
ENTRY_POINT 'fn_datediff' MODULE_NAME 'ib_udf';
DECLARE EXTERNAL FUNCTION TRIM
SMALLINT, CSTRING(256), SMALLINT
RETURNS CSTRING(256) FREE_IT
ENTRY_POINT 'fn_trim' MODULE_NAME 'ib_udf';
COMMIT;
Note that no extension is supplied for the module name. This creates a portable module.
Windows machines add a .dll extension automatically. |
Partager