Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SQL Statements > CREATE PROCEDURE >

Using sysbdopen( ) and sysdbclose( ) Stored Procedures (XPS)

To set the initial environment for one or more sessions, create and install the sysdbopen( ) SPL procedure. The primary function of these procedures is to initialize properties of a session without requiring the properties to be explicitly defined within the session. These procedures are executed whenever users connect to a database where the procedures are installed. Such procedures are useful if users access databases through client applications that cannot modify application code or set environment options or environment variables.

You can also create the sysdbclose( ) SPL procedure which is executed when a user disconnects from the database.

You can include valid SQL or SPL language statements that are appropriate when a database is opened or closed. See the following sections for restrictions on SQL and SPL statements within SPL routines:

Important:
The sysdbopen( ) and sysdbclose( ) procedures are exceptions to the scope rule for stored procedures. In ordinary UDR procedures, the scope of variables and statements is local. SET PDQPRIORITY and SET ENVIRONMENT statement settings do not persist when these SPL procedures exit. In sysdbopen( ) and sysdbclose( ) procedures, however, statements that set the session environment remain in effect until another statement resets the options.

For example, you might create the following procedure, which sets the isolation level to Dirty Read and turns on the IMPLICIT_PDQ environment variable, to be executed when any user connect to the database:

create procedure public.sysdbopen()
   set role engineer;
end procedure;

Procedures do not accept arguments or return values. The sysdbopen( ) and sysdbclose( ) procedures must be executed from the connection coserver and must be installed in each database where you want to execute them. You can create the following four SPL procedures.

Procedure Name
Description
user.sysdbopen( )
This procedure is executed when the specified user opens the database as the current database.
public.sysdbopen( )
If no user.sysdbopen( ) procedure applies, this procedure is executed when any user opens the database as the current database. To avoid duplicating SPL code, you can call this procedure from a user-specific procedure.
user.sysdbclose( )
This procedure is executed when the specified user closes the database, disconnects from the database server, or the user session ends. If the sysdbclose( ) procedure did not exist when a session opened the database, however, it is not executed when the session closes the database.
public.sysdbclose( )
If no user.sysdbopen( ) procedure applies, this procedure is executed when the specified user closes the database, disconnects from the database server, or the user session ends. If the sysdbclose( ) procedure did not exist when a session opened the database, however, it is not executed when the session closes the database.

See also the section Transactions in SPL Routines.

Make sure that you set permissions appropriately to allow intended users to execute the SPL procedure statements. For example, if the SPL procedure executes a command that writes output to a local directory, permissions must be set to allow users to write to this directory. If you want the procedure to continue if permission failures occur, include an ON EXCEPTION error handler for this condition.

See also the section Support for Roles and User Identity.

Warning:
If a sysdbopen( ) procedure fails, the database cannot be opened. If a sysdbclose( ) procedure fails, the failure is ignored. While you are writing and debugging a sysdbopen( ) procedure, set the DEBUG environment variable to NODBPROC before you connect to the database. When DEBUG is set to NODBPROC, the procedure is not executed, and failures cannot prevent the database from opening. Failures from these procedures can be generated by the system or simulated by the procedures with the RAISE EXCEPTION statement of SPL. For more information, refer to the description of RAISE EXCEPTION in Chapter 3.

Only a user with DBA privileges can install these procedures. For security reasons, non-DBAs cannot prevent execution of these procedures. For some applications, however, such as ad hoc query applications, users can execute commands and SQL statements that subsequently change the environment.

For general information about how to write and install SPL procedures, refer to the chapter about SPL routines in IBM Informix Guide to SQL: Tutorial.

Related Information

Related statements: ALTER FUNCTION , ALTER PROCEDURE, ALTER ROUTINE, CREATE FUNCTION, CREATE FUNCTION FROM , CREATE PROCEDURE FROM, DROP FUNCTION , DROP PROCEDURE , DROP ROUTINE , EXECUTE FUNCTION , EXECUTE PROCEDURE, GRANT, PREPARE, REVOKE, and UPDATE STATISTICS.

For a discussion of how to create and use SPL routines, see the IBM Informix Guide to SQL: Tutorial. For a discussion of external routines, see IBM Informix User-Defined Routines and Data Types Developer's Guide.

For information about how to create C UDRs, see the IBM Informix DataBlade API Programmer's Guide. For more information on the NODEFDAC environment variable and the related system catalog tables (sysprocedures, sysprocplan, sysprocbody and sysprocauth), see the IBM Informix Guide to SQL: Reference.

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]