Top

Chapter 12. Database Event Hooks

Abstract

Virtuoso provides a number of hooks that enable you to traps events within the database such as startup, shutdown, connection, disconnection and SQL compilation events.

Virtuoso allows the dba to set hooks for various events, such as:

Startup
Shutdown
Client Connect
Client Disconnect
Compilation of a Dynamic SQL Statement

These events are intercepted by calling a SQL procedure if one is defined.

In the following we will examine each hook in the context of a simplified database security system. The system will record all logins and logouts and will enforce custom security rules on reading a specific application table.

12.1. Database Startup

DB.DBA.DBEV_STARTUP()

If defined, this is called after the server initialization, including roll forward of transaction logs, compilation of stored procedures, etc..., but before starting to listen for clients. Hence this is guaranteed to run before any clients connect or any HTTP messages are serviced.

The procedure will run in its own transaction, which will be automatically committed upon return, regardless of run time errors. Result sets are not allowed and return values are discarded. All custom Virtuoso Server Extensions (VSEs) will be defined when calling this procedure.

Example 12.1. Sample Startup Procedure Hook

create procedure DB.DBA.DBEV_STARTUP ()
{
  dbg_obj_print (' server started ');
}