Changes

Jump to navigation Jump to search
349 bytes added ,  12:50, 8 July 2020
no edit summary
* The module will be available if the {{Code|basex-api}} library is found in the classpath. This is the case if you use one of the complete distributions of BaseX (zip, exe, war).
* All functions and errors are assigned to the <code><nowiki>http://basex.org/modules/session</nowiki></code> namespace, which is statically bound to the {{Code|session}} prefix. Prior to {{Version|9.2}}, the module needed to be imported in the query prolog:<pre class="brush:xquery">import module namespace session = "http://basex.org/modules/session";...</pre>
* If any of the functions is called outside the servlet context, <code>[[XQuery Errors#BaseX Errors|basex:http]]</code> is raised.
* As sessions are side-effecting operations, all functions are flagged as ''non-deterministic''. As a result, some query optimizations will be suppressed.
| '''Summary'''
|Returns the session ID of a servlet request.
|-
| '''Errors'''
|{{Error|not-found|#Errors}} No session is available for the current client.
|-
| '''Examples'''
|Running the server-side XQuery file {{Code|id.xq}} via <code><nowiki>http://localhost:8984/id.xq</nowiki></code>:
<pre classsyntaxhighlight lang="brush:xquery">
import module namespace session = "http://basex.org/modules/session";
'Session ID: ' || session:id()
</presyntaxhighlight>
|}
| '''Summary'''
|Returns the creation time of a session.
|-
| '''Errors'''
|{{Error|not-found|#Errors}} No session is available for the current client.
|}
| '''Summary'''
|Returns the last access time of a session.
|-
| '''Errors'''
|{{Error|not-found|#Errors}} No session is available for the current client.
|}
| '''Examples'''
|Running the server-side XQuery file {{Code|names.xq}} via <code><nowiki>http://localhost:8984/names.xq</nowiki></code>:
<pre classsyntaxhighlight lang="brush:xquery">
import module namespace session = "http://basex.org/modules/session";
session:names() ! element variable { . }
</presyntaxhighlight>
|}
| '''Summary'''
|Returns the value of a session attribute with the specified <code>$name</code>. If the attribute is unknown, an empty sequence or the optionally specified {{Code|$default}} value will be returned instead.
|-
| '''Errors'''
|{{Error|get|#Errors}} the value of an attribute could not be retrieved.
|-
| '''Examples'''
|Running the server-side XQuery file {{Code|get.xq}} via <code><nowiki>http://localhost:8984/get.xq?key=user</nowiki></code>:
<pre classsyntaxhighlight lang="brush:xquery">
import module namespace session = "http://basex.org/modules/session";
'Value of ' || $key || ': ' || session:get($key)
</presyntaxhighlight>
|}
|-
| '''Errors'''
|{{Error|set|#Errors}} The supplied value cannot be materialized.<br/>{{Error|not-found|#Errors}} No session is available for the current client.
|-
| '''Examples'''
|Running the server-side XQuery file {{Code|set.xq}} via <code><nowiki>http://localhost:8984/set.xq?key=user&value=john</nowiki></code>:
<pre classsyntaxhighlight lang="brush:xquery">
import module namespace session = "http://basex.org/modules/session";
session:set($key, $value), 'Variable was set.'
</presyntaxhighlight>
|}
| '''Examples'''
|Running the server-side XQuery file {{Code|delete.xq}} via <code><nowiki>http://localhost:8984/delete.xq?key=user</nowiki></code>:
<pre classsyntaxhighlight lang="brush:xquery">
import module namespace session = "http://basex.org/modules/session";
session:delete($key), 'Variable was deleted.'
</presyntaxhighlight>
|}
{| class="wikitable" width="100%"
! width="110" |Code
|Description
|-
|{{Code|getset}}|The supplied value cannot be stored attribute is no XQuery value.
|-
|{{Code|setnot-found}}|The supplied value cannot be materializedNo session is available for the current client.
|}
=Changelog=
 
;Version 9.4
* Updated: Only create session if required.
 
;Version 9.3
* Updated: [[#session:get|session:get]]: Values that have no XQuery type will be returned as strings.
;Version 9.0
 
* Updated: error codes updated; errors now use the module namespace
;Version 8.0
 
* Updated: Allow sequences as session values.
This module was introduced with Version 7.5.
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu