Creating and using application contexts

The following built-in functions are available for creating and maintaining application contexts. For more information than is given in this section, see Reference Manual.


set_appcontext

Sets an application context name, attribute name, and attribute value, defined by the attributes of an application, for a specified user session.

set_appcontext ("context_name", "attribute_name", "attribute_value")

Examples

This example creates an application context called CONTEXT1, with an attribute ATTR1 that has the value VALUE1:

Example 1

select set_appcontext ("CONTEXT1", "ATTR1", "VALUE1")
---------------
0

This example shows an attempt to override the existing application context. The attempt fails, returning -1:

select set_appcontext("CONTEXT1", "ATTR1", "VALUE1")
--------------
-1

Example 2

This example shows how set_appcontext can include a datatype conversion in the value:

declare@val numeric
select @val = 20
select set_appcontext ("CONTEXT1", "ATTR2", 
convert(char(20), @val))
------------
0

Example 3

This example shows the result when a user without appropriate permissions attempts to set the application context. The attempt fails, returning -1:

select set_appcontext("CONTEXT1", "ATTR2", "VALUE1")
--------------
-1

Usage


get_appcontext

Returns the value of the attribute in a specified context.

get_appcontext ("context_name", "attribute_name")

context_name – a row specifying an application context name, saved as datatype char(30).

attribute_name – a row specifying an application context attribute name, saved as datatype char(30).

Examples

This example shows VALUE1 returned for ATTR1:

select get_appcontext ("CONTEXT1", "ATTR1")
-----------
VALUE1

ATTR1 does not exist in CONTEXT2:

select get_appcontext("CONTEXT2", "ATTR1")
------------
NULL

This example shows the result when a user without appropriate permissions attempts to get the application context:

select get_appcontext("CONTEXT1", "ATTR2")
select permisssion denied on built-in get_appcontext, database dbid
----------
-1

Usage


list_appcontext

Lists all the attributes of all the contexts in the current session.

list_appcontext ("context_name")

context_name – names all the application context attributes in the session. list_appcontext has a datatype of char(30)

Examples

To use list_appcontext, the user must have appropriate permissions. For more information about permissions, see “Setting permissions for using application context functions”.

This example shows the results of a user with appropriate permissions listing the application contexts.

select list_appcontext ("*", "*")
Context Name: (CONTEXT1)
Attribute Name: (ATTR1) Value: (VALUE2)
Context Name: (CONTEXT2)
Attribute Name: (ATTR1) Value: (VALUE!)
-----------
0

This example shows a user without appropriate permissions attempting to list the application contexts. The attempt fails, returning -1.

select list_appcontext()
Select permission denied on built-in
list_appcontext, database DBID
---------
-1

Usage


rm_appcontext

Removes a specific application context, or all application contexts.

rm_appcontext ("context_name", "attribute_name")

context_name – a row specifying an application context name, saved as datatype char(30).

attribute_name – a row specifying an application context attribute name, saved as datatype char(30).

Examples

The following three examples show how to remove an application context by specifying some or all attributes. Use an asterisk ("*") to remove all attributes in the specified context.

select rm_appcontext("CONTEXT1", "*")
---------
0

Use an asterisk ("*") to remove all the contexts and attributes.

select rm_appcontext("*", "*")
---------
0

This example shows a user attemptimg to remove a nonexistent context. The attempt fails, returning -1.

select rm_appcontext("NON_EXISTING_CTX", "ATTR2")
---------
-1

This example shows the result of a user without appropriate permissions attempting to remove an application context.

select rm_appcontext("CONTEXT1", "ATTR2")
---------
-1

Usage