Creating C External Procedures
This chapter describes how to configure the basic environment for C external procedures and how to create C external procedures.
Basic Environment Configuration
C external procedures are executed by the tbEPA, as mentioned earlier. The binary used to execute the tbEPA process exists in the $TB_HOME/client/bin directory.
This section describes how to specify the basic environment configuration needed to execute tbEPA processes, before creating the external C procedure.
Initialization Parameters
When first executed, the tbEPA process checks the user-specified initialization parameters. The initialization parameter is specified in the tbepa.cfg file located under the $TB_HOME/client/tbepa directory. If no initialization parameter is specified, the default value is used.
The initialization parameters that users can define for the tbEPA process are as follows:
<<tbepa.cfg>>
LOG_DIR
tPath to the tbEPA log file. (Default value: $TB_HOME/client/tbepa)
LOG_LVL
Logging level. (Default value: 2)
MAX_LOG_SIZE
Maximum size of the log file. (Default value: 0, unit: byte)
If set to 0: Log file size is unlimited.
If the log file size exceeds the specified maximum size, the log file is backed up.
MAX_LOG_BACKUP_SIZE
Maximum total size of log files in the backup directory. (Default value: 0, unit: byte)
If set to 0: Total size of the log files is unlimited.
If the total size of the log files exceeds the specified maximum size, the oldest one-third of the log files are removed.
LOG_LVL is an initialization parameter in the tbepa.cfg file and allows users to choose a logging level between 1-5.
The following table details each logging level.
Logging Level
Log Level Name
Description
1
ERROR
Error related events.
2
WARNING
Warning related events.
3
INFO
The basic trace events.
4
DEBUG
Detail level trace events to debug applications.
5
TRACE
The most verbose logging level.
Creating C External Procedures
Users must take the following steps to create an external C procedure.
Create a user shared library
Register the library object
Map the function (external procedure) to a PSM
Execute the function
1. Creating User Shared Libraries
Create a user shared library which can be dynamically called in C.
A user shared library is created in the following order.
(1) Write a C function
<<extproc.c>>
(2) Perform compilation
The following example performs compilation in the UNIX series (Linux included) platform.
When the compilation completes, a user shared library named libextproc.so is created.
2. Registering Library Objects
Library Object registers a user shared library file in Tibero. It is a type of schema object.
The following is the syntax used to register a library object.
Item
Description
schema_name
Name of the schema object.
library_name
Name of the library object.
file_path
Absolute path to the user shared library file.
Executing the CREATE LIBRARY statement requires the CREATE LIBRARY privilege.
The following example registers the library object named 'extproc' using a created user shared library file.
3. Function and PSM Object Mapping
When a function within the library object is mapped to a PSM object after the library object is registered, an external C procedure is created. Users can call the function in the same way as they call general PSMs.
The following syntax defines a PSM.
Item
Description
library_name
Name of the library object.
c_string_literal_name
Function to be called.
WITH CONTEXT
Indicates that a context pointer will be passed to the C external procedure. (For detailed information, refer to
“External C Procedure Utility”, “Callback Service”.)
PARAMETERS (external_parameter)
Parameters mapped to PSM parameters. (For detailed information about external_parameter, refer to “ Parameter Mapping”.)
The following example maps a specific function (find_max) within the library object to the PSM.
4. Executing Functions
A function is mapped to a PSM in Tibero, thus users can use the PSM syntax to execute the function.
The following example executes an external C procedure using the PSM syntax.
Last updated