Changes

Jump to navigation Jump to search
558 bytes added ,  10:29, 3 August 2022
m
Text replacement - "8984" to "8080"
=Conventions=
* The module will be available if the {{Code|basex-api}} package must be included library is found in the classpath. This is always the case if you use one of the complete distributions of BaseX (zip, exe, war) of BaseX.* All functions and errors are assigned to the {{Code|http://basex.org/modules/session}} namespace. The module must be imported in the query prolog:<pre class="brush:xquery"code><nowiki>import module namespace session = "http://basex.org/modules/session";...</prenowiki>* In this documentation, the namespace is bound to the {{Code|session}} prefix.* Errors are assigned to the {{Code|http:<//basex.org/errors}} code> namespace, which is statically bound to the {{Code|bxerrsession}} prefix.* If any of the functions is called outside the servlet context, the error {{Error|BXSE0003|<code>[[XQuery Errors#BaseX Errors}} |basex:http]]</code> is raised.* As sessions are side-effecting operations, all functions are flagged as ''non-deterministic''. This means that the functions As a result, some query optimizations will not be reordered by the compilersuppressed.
=Functions=
==session:id==
 
{| 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>
|}
==session:created==
 
{| 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.
|}
==session:accessed==
 
{| 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.
|}
==session:names==
 
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|session:names||xs:string*}}
|-valign="top"
| '''Summary'''
|Returns the names of all variables 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==
 
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|session:get|$key name as xs:string|xs:string?item()*}}<br/>{{Func|session:get|$key name as xs:string, $default as xs:stringitem()*|xs:stringitem()*}}|-valign="top"
| '''Summary'''
|Returns the value of a variable bound to session attribute with the current sessionspecified <code>$name</code>. If the variable does not existattribute is unknown, an empty sequence or the optionally specified default value is returned instead.|-| '''Errors'''|{{ErrorCode|BXSE0002|#Errors$default}} the value of a session variable could not will be retrievedreturned 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>
|}
==session:set==
 
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|session:set|$key name as xs:string, $value as xs:stringitem()*|empty-sequence()}}|-valign="top"
| '''Summary'''
|Assigns a Binds the specified {{Code|$value }} to a the session variableattribute with the specified {{Code|$name}}.|-valign="top"
| '''Errors'''
|{{Error|BXSE0001not-found|#Errors}} a function item was specified as value of a No session variableis 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>
|}
==session:delete==
 
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|session:delete|$key name as xs:string|empty-sequence()}}|-valign="top"
| '''Summary'''
|Deletes a session variableattribute 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>
|}
==session:close==
 
{| width='100%'
|-valign="top"
| width='120' | '''Signatures'''
|{{Func|session:close||empty-sequence()}}
|-valign="top"
| '''Summary'''
|Unregisters a session and all data associated with it.
=Errors=
{| width='100%' class="wikitable" width="100%"! width="5%110"|Code! width="95%"|Description|-valign="top"|{{Code|BXSE0001}}|A function item was specified as value of a session attribute.|not-|{{Code|BXSE0002found}}|An error occurred while retrieving the value of a No session attribute.|-|{{Code|BXSE0003}}|A function was called outside is available for the servlet contextcurrent client.
|}
=Changelog=
 
;Version 9.4
* Updated: Only create session if required.
 
;Version 9.3
* Updated: {{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.
 
[[Category:XQuery]]
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu