As an example, an audio-visual application may need to process data through a series of spatial/temporal filters. The bulk data could be stored in a table in its "raw" form, and the filters in a second table. Users could then select data/filter combinations, and could then output the processed data to a monitor and speaker. The processing operations would be UDFs.
User defined functions can be made accessible to users through the SQL interface only, the 4GL interface only, or through both the SQL and 4GL interfaces. Here, we describe only how to install these functions for use in the 4GL. Creation of the actual functions is the same for both SQL-based and 4GL-based UDFs, and is described in detail in the Empress User Defined Functions manual. In the following sections, we assume that the user is familiar with creating user defined functions, and so we mention a number of C-structures which we only briefly describe. For a more detailed description, see the Empress User Defined Functions manual.
For those with no experience in creating user defined functions, we offer the following synopsis. A UDF is defined in Empress by a number of structures which contain information regarding the keyword, the type of function/operator, and the manner in which the function handles input and output. There are two types of UDFs in Empress: SC (Standard C) and DT (Data Type), each having different advantages and drawbacks which are described in the Empress User Defined Functions manual. However, for the purposes of incorporating a UDF into the 4GL, these differences can be ignored. Finally, we note that the structures which define a UDF in Empress include the following:
6.2 Function Precedence
By locating the data structures and code describing the UDF in different
places, the system administrator can affect where various functions can
be accessed. That is, the UDF can be accessible to SQL only, 4GL only,
or both.
We begin with a list of the major files, table structures, and their
usage. All files are in the Empress custom subdirectory.
Table 6-1
| File Keyword | Table Name | Description |
| usrstdfns.c | usrsktab | SC function keywords |
| usrfns.c | usrxktab | DT function keywords |
However, the Empress 4GL functions also have a keyword
table that is not included in the above:
Table 6-2
| File | Keyword Table Name | Description |
| aptabs.c | usraktab | 4GL function keywords |
Note, however, that if the keyword is to be available only within the 4GL, its keyword is not necessarily placed in one aptabs.c file (see next section).
In all cases, after the user function tables are searched, Empress searches the built-in function tables. These function tables would contain the standard Empress 4GL functions such as next_rec or concat for example.
|
|
|
|||
| 4GL | SQL | usrxktab (DT) | usrsktab (SC) | usraktab (4GL) |
| no | no | no | no | no |
| no | yes | yes* | yes* | no |
| yes | no | no | no | yes |
| yes | yes | yes* | yes* | yes |
(*) for each function,, add a keyword to one of these tables as appropriate.
We will now consider how to implement each of the last two cases:
A. UDF Available in both SQL and 4GL:
B. UDF Available only in the 4GL:
Method 1:
Method 2:
The differences between these methods are in the types of functions which can be defined, and where they can be used. Here is a summary:
Method 1 UDF's:
- cannot be used in a call() in a 4GL script, i.e., cannot
be used as a procedure
- can be any operator/function keytag type
Method 2 UDF's:
- can be accessed through a call() in a 4GL script
- are SC-type "tuple" functions (arguments are passed by the C (argc, argv)
convention) with a keytag type of opf_x.
6.5 Function Incorporation
Once you have created the desired entries in the files aptabs.c,
usrfns.c and usrstdfns.c, you must compile and relink
the executables. This procedure is discussed in the manual Empress User
Defined Functions in the following chapters:
| File | See |
| usrstdfns.c | Chapter 4, "Standard C Functions" |
| usrfns.c | Chapter 5, "Data Type Functions" |
| aptabs.c | Chapter 6, "4GL Functions" |