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
get_appcontext
list_appcontext
rm_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")
context_name – a row that specifies an application context name, saved as the datatype char(30).
attribute_name – a row that specifies an application context name, saved as the datatype char(30)
attribute_value – a row that specifies an application attribute value, saved as the datatype char(2048).
This example creates an application context called CONTEXT1, with an attribute ATTR1 that has the value VALUE1:
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
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
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
set_appcontext returns 0 for success and -1 for failure.
If you set values that already exist in the current session, set_appcontext returns -1.
set_appcontext cannot override the values of an existing application context. To assign new values to a context, remove the context and re-create it with new values.
set_appcontext saves attributes as char datatypes. If you create an access rule that must compare the attribute value to another datatype, the rule should convert the char data to the appropriate datatype.
All arguments in this function are required.
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).
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
get_appcontext returns 0 for success and -1 for failure.
If the attribute you require does not exist in the application context, get_appcontext returns “null”.
get_appcontext saves attributes as char datatypes. If you create an access rule that compares the attribute value to other datatypes, the rule should convert the char data to the appropriate datatype.
All arguments in this function are required.
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)
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
list_appcontext returns 0 for success and -1 for failure.
Since built-in functions do not return multiple result sets, the client application receives list_appcontext returns as messages.
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).
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
rm_appcontext returns 0 for success, -1 for failure.
All arguments in this function are required.