Session Module

From BaseX Documentation

Jump to: navigation, search

This XQuery Module contains functions for accessing and modifying server-side session information. This module is mainly useful in the context of Web Applications.

Contents

[edit] Conventions

import module namespace session = "http://basex.org/modules/session";
...

[edit] Functions

[edit] session:id

Signatures session:id() as xs:string
Summary Returns the session ID of a servlet request.
Examples Running the server-side XQuery file id.xq via http://localhost:8984/id.xq:
import module namespace session = "http://basex.org/modules/session";
'Session ID: ' || session:id()

[edit] session:created

Signatures session:created() as xs:dateTime
Summary Returns the creation time of a session.

[edit] session:accessed

Signatures session:accessed() as xs:dateTime
Summary Returns the last access time of a session.

[edit] session:names

Signatures session:names() as xs:string*
Summary Returns the names of all variables bound to the current session.
Examples Running the server-side XQuery file names.xq via http://localhost:8984/names.xq:
import module namespace session = "http://basex.org/modules/session";
session:names() ! element variable { . }

[edit] session:get

Signatures session:get($name as xs:string) as item()*
session:get($name as xs:string, $default as item()*) as item()*
Summary Returns the value of $name bound to the current session. If the specified variable is unknown, an empty sequence or the optionally specified default value is returned instead.
Errors BXSE0002: the value of a session variable could not be retrieved.
Examples Running the server-side XQuery file get.xq via http://localhost:8984/get.xq?key=user:
import module namespace session = "http://basex.org/modules/session";
'Value of ' || $key || ': ' || session:get($key)

[edit] session:set

Signatures session:set($name as xs:string, $value as item()*) as empty-sequence()
Summary Binds the specified name/value pair to a session.
Errors BXSE0001: a function item was specified as value of a session variable.
Examples Running the server-side XQuery file set.xq via http://localhost:8984/set.xq?key=user&value=john:
import module namespace session = "http://basex.org/modules/session";
session:set($key, $value), 'Variable was set.'

[edit] session:delete

Signatures session:delete($name as xs:string) as empty-sequence()
Summary Deletes a session value bound to $name.
Examples Running the server-side XQuery file delete.xq via http://localhost:8984/delete.xq?key=user:
import module namespace session = "http://basex.org/modules/session";
session:delete($key), 'Variable was deleted.'

[edit] session:close

Signatures session:close() as empty-sequence()
Summary Unregisters a session and all data associated with it.

[edit] 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.
BXSE0003 A function was called outside the servlet context.

[edit] Changelog

Version 8.0

This module was introduced with Version 7.5.

Personal tools
Namespaces
Variants
Actions
Navigation
Print/export