Difference between revisions of "Session Module"

From BaseX Documentation
Jump to navigation Jump to search
Line 35: Line 35:
 
| '''Summary'''
 
| '''Summary'''
 
|Returns the value of an attribute bound to the current session, or an empty sequence if no value was bound. If the attribute does not exist, an empty sequence or the optionally specified default value is returned instead.
 
|Returns the value of an attribute bound to the current session, or an empty sequence if no value was bound. If the attribute does not exist, an empty sequence or the optionally specified default value is returned instead.
 +
|-
 +
| '''Errors'''
 +
|{{Error|BXSE0002|#Errors}} the value of a session attribute could not be retrieved.
 
|-
 
|-
 
| '''Examples'''
 
| '''Examples'''
Line 62: Line 65:
 
| '''Properties'''
 
| '''Properties'''
 
|The function is ''non-deterministic'': evaluation order will be preserved by the compiler.
 
|The function is ''non-deterministic'': evaluation order will be preserved by the compiler.
 +
|-
 +
| '''Errors'''
 +
|{{Error|BXSE0001|#Errors}} a function item was specified as value of a session attribute.
 
|-
 
|-
 
| '''Examples'''
 
| '''Examples'''
Line 87: Line 93:
 
|-
 
|-
 
|{{Code|BXSE0001}}
 
|{{Code|BXSE0001}}
|Function items cannot be stored as session attributes.
+
|A function item was specified as value of a session attribute.
 
|-
 
|-
 
|{{Code|BXSE0002}}
 
|{{Code|BXSE0002}}
|An error occurred while retrieving a session attribute.
+
|An error occurred while retrieving the value of a session attribute.
 
|}
 
|}
  

Revision as of 01:42, 9 September 2012

This XQuery Module contains functions for handling session information on an HTTP request that has triggered the query. This module is mainly useful in the context of Web Applications.

Conventions

All functions in this module are assigned to the http://basex.org/modules/session namespace, which must be dynamically imported. In this documentation, the namespace is bound to the session prefix.

Functions

session:id

Signatures session:id() as xs:string
Summary Returns the session ID of a servlet request.
Examples The following RESTXQ function can be called via http://localhost:8984/restxq/id:
module namespace test = 'http://basex.org/examples/test';
import module namespace session = "http://basex.org/modules/session";
declare %restxq:path("/id") function test:id() {
  'Session ID: ' || session:id()
};

session:attribute

Signatures session:attribute($key as xs:string) as xs:string?
session:attribute($key as xs:string, $default as xs:string) as xs:string
Summary Returns the value of an attribute bound to the current session, or an empty sequence if no value was bound. If the attribute does not exist, an empty sequence or the optionally specified default value is returned instead.
Errors BXSE0002: the value of a session attribute could not be retrieved.
Examples The following RESTXQ function can e.g. be called via http://localhost:8984/restxq/get?key=user:
module namespace test = 'http://basex.org/examples/test';
import module namespace session = "http://basex.org/modules/session";
declare
  %restxq:path("/get")
  %restxq:query-param("key", "{$key}", "")
  function test:get($key)
{
  'Value of ' || $key || ': ' || session:attribute($key)
};

session:update-attribute

Signatures session:update-attribute($key as xs:string, $value as xs:string) as empty-sequence()
Summary Assigns a value to a session attribute.
Properties The function is non-deterministic: evaluation order will be preserved by the compiler.
Errors BXSE0001: a function item was specified as value of a session attribute.
Examples The following RESTXQ function can e.g. be called via http://localhost:8984/restxq/set?key=user&value=john:
module namespace test = 'http://basex.org/examples/test';
import module namespace session = "http://basex.org/modules/session";
declare
  %restxq:path("/set")
  %restxq:query-param("key", "{$key}", "")
  %restxq:query-param("value", "{$value}", "")
  function test:update($key, $value)
{
  session:update-attribute($key, $value),
  'Attribute was set.'
};

Errors

Code Description
BXSE0001 A function item was specified as value of a session attribute.
BXSE0002 An error occurred while retrieving the value of a session attribute.

Changelog

This module was introduced with Version 7.5.