meta data for this page
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, PSQL, ESQL
Added in: 2.0
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_NAME | Either the full path to the database or – if connecting via the path is disallowed – its alias. |
---|---|
NETWORK_PROTOCOL | The protocol used for the connection. Can be 'TCPv4', 'WNET', 'XNET' or NULL. |
CLIENT_ADDRESS | For TCPv4, this is the IP address. For XNET, the local process ID. For all other protocols this variable is NULL. |
CURRENT_USER | Same as global CURRENT_USER variable. |
CURRENT_ROLE | Same as global CURRENT_ROLE variable. |
SESSION_ID | Same as global CURRENT_CONNECTION variable. |
TRANSACTION_ID | Same as global CURRENT_TRANSACTION variable. |
ISOLATION_LEVEL | The isolation level of the current transaction; can be 'READ COMMITTED', 'SNAPSHOT' or 'CONSISTENCY'. |
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'))