Changes

Jump to navigation Jump to search
496 bytes added ,  10:29, 3 August 2022
m
Text replacement - "8984" to "8080"
* 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.
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|session:id||xs:string}}
|-valign="top"
| '''Summary'''
|Returns the session ID of a servlet request.
|-valign="top"| '''Errors'''|{{Error|not-found|#Errors}} No session is available for the current client.|- valign="top"
| '''Examples'''
|Running the server-side XQuery file {{Code|id.xq}} via <code><nowiki>http://localhost:89848080/id.xq</nowiki></code>:<pre classsyntaxhighlight lang="brush:xquery">
import module namespace session = "http://basex.org/modules/session";
'Session ID: ' || session:id()
</presyntaxhighlight>
|}
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|session:created||xs:dateTime}}
|-valign="top"
| '''Summary'''
|Returns the creation time of a session.
|- valign="top"
| '''Errors'''
|{{Error|not-found|#Errors}} No session is available for the current client.
|}
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|session:accessed||xs:dateTime}}
|-valign="top"
| '''Summary'''
|Returns the last access time of a session.
|- valign="top"
| '''Errors'''
|{{Error|not-found|#Errors}} No session is available for the current client.
|}
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|session:names||xs:string*}}
|-valign="top"
| '''Summary'''
|Returns the names of all attributes bound to the current session.
|-valign="top"
| '''Examples'''
|Running the server-side XQuery file {{Code|names.xq}} via <code><nowiki>http://localhost:89848080/names.xq</nowiki></code>:<pre classsyntaxhighlight lang="brush:xquery">
import module namespace session = "http://basex.org/modules/session";
session:names() ! element variable { . }
</presyntaxhighlight>
|}
==session:get==
 
{{Mark|Updated with Version 9.3:}} Values that have no XQuery type will be returned as strings.
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|session:get|$name as xs:string|item()*}}<br/>{{Func|session:get|$name as xs:string, $default as item()*|item()*}}
|-valign="top"
| '''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.
|-valign="top"
| '''Examples'''
|Running the server-side XQuery file {{Code|get.xq}} via <code><nowiki>http://localhost:89848080/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>
|}
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|session:set|$name as xs:string, $value as item()*|empty-sequence()}}
|-valign="top"
| '''Summary'''
|Binds the specified {{Code|$value}} to the session attribute with the specified {{Code|$name}}.
|-valign="top"
| '''Errors'''
|{{Error|setnot-found|#Errors}} The supplied value cannot be materializedNo session is available for the current client.|-valign="top"
| '''Examples'''
|Running the server-side XQuery file {{Code|set.xq}} via <code><nowiki>http://localhost:89848080/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>
|}
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|session:delete|$name as xs:string|empty-sequence()}}
|-valign="top"
| '''Summary'''
|Deletes a session attribute with the specified <code>$name</code>.
|-valign="top"
| '''Examples'''
|Running the server-side XQuery file {{Code|delete.xq}} via <code><nowiki>http://localhost:89848080/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>
|}
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|session:close||empty-sequence()}}
|-valign="top"
| '''Summary'''
|Unregisters a session and all data associated with it.
{| class="wikitable" width="100%"
! width="110" |Code
|Description
|-valign="top"|{{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{{Function||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