RDB$GET_CONTEXT()

<< RAND() | FB 2.5 Language Reference | RDB$SET_CONTEXT() >>

RDB$GET_CONTEXT()

Note: RDB$GET_CONTEXT and its counterpart RDB$SET_CONTEXT are actually predeclared UDFs. They are listed here as internal functions because they are always present – the user doesn't have to do anything to make them available.

Available in: DSQL, ESQL, PSQL

Added in: 2.0

Changed in: 2.1

Description

Retrieves the value of a context variable from one of the namespaces SYSTEM, USER_SESSION and USER_TRANSACTION.

Result type: VARCHAR(255)

Syntax

 RDB$GET_CONTEXT ('<namespace>', '<varname>')

 <namespace> ::= SYSTEM | USER_SESSION | USER_TRANSACTION
 <varname>   ::= A case-sensitive string of max. 80 characters

The namespaces

The USER_SESSION and USER_TRANSACTION namespaces are initially empty. The user can create and set variables in them with RDB$SET_CONTEXT() and retrieve them with RDB$GET_CONTEXT(). The SYSTEM namespace is read-only. It contains a number of predefined variables, shown in the table below.

Table 11.3. Context variables in the SYSTEM namespace
DB_NAMEEither the full path to the database or – if connecting via the path is disallowed – its alias.
NETWORK_PROTOCOLThe protocol used for the connection. Can be 'TCPv4', 'WNET', 'XNET' or NULL.
CLIENT_ADDRESSFor TCPv4, this is the IP address. For XNET, the local process ID. For all other protocols this variable is NULL.
CURRENT_USERSame as global CURRENT_USER variable.
CURRENT_ROLESame as global CURRENT_ROLE variable.
SESSION_IDSame as global CURRENT_CONNECTION variable.
TRANSACTION_IDSame as global CURRENT_TRANSACTION variable.
ISOLATION_LEVELThe isolation level of the current transaction; can be 'READ COMMITTED', 'SNAPSHOT' or 'CONSISTENCY'.
ENGINE_VERSIONThe Firebird engine (server) version. Added in 2.1.

Return values and error behaviour

If the polled variable exists in the given namespace, its value will be returned as a string of max. 255 characters. If the namespace doesn't exist or if you try to access a non-existing variable in the SYSTEM namespace, an error is raised. If you poll a non-existing variable in one of the other namespaces, NULL is returned. Both namespace and variable names must be given as single-quoted, case-sensitive, non-NULL strings.

Examples

 select rdb$get_context('SYSTEM', 'DB_NAME') from rdb$database

 New.UserAddr = rdb$get_context('SYSTEM', 'CLIENT_ADDRESS');

 insert into MyTable (TestField)
   values (rdb$get_context('USER_SESSION', 'MyVar'))

See also:
RDB$SET_CONTEXT()
SET TRANSACTION
Data transaction
Database statistics
Transaction options explained
Firebird 2.1 Release Notes: Lock timeout for WAIT transactions
Firebird 2.0 & 2.1 Release Notes: SET TRANSACTION enhanced
Firebird for the database expert: episode 4 - OAT, OIT and sweep
Firebird for the database expert: episode 5 - Locking and record versions
Multi-generational architecture (MGA) and record versioning
Multi-version concurrency control

back to top of page
<< RAND() | FB 2.5 Language Reference | RDB$SET_CONTEXT() >>