Changes

Jump to navigation Jump to search
239 bytes added ,  18:35, 1 December 2023
m
Text replacement - "</syntaxhighlight>" to "</pre>"
* 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.
* 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-deterministicnondeterministic''. As a result, some query optimizations will be suppressed.
=Functions=
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>session:id||() as xs:string}}</pre>|-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>:<syntaxhighlight pre lang="'xquery"'>
import module namespace session = "http://basex.org/modules/session";
'Session ID: ' || session:id()
</syntaxhighlightpre>
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>session:created||() as xs:dateTime}}</pre>|-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' | '''SignaturesSignature'''|{{Func|<pre>session:accessed||() as xs:dateTime}}</pre>|-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' | '''SignaturesSignature'''|{{Func|<pre>session:names||() as xs:string*}}</pre>|-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>:<syntaxhighlight pre lang="'xquery"'>
import module namespace session = "http://basex.org/modules/session";
session:names() ! element variable { . }
</syntaxhighlightpre>
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|session:get|$name as xs:string|item()*}}<br/pre>{{Func|session:get|( $name as xs:string, $default as item()*| := ()) as item()*}}</pre>|-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>:<syntaxhighlight pre lang="'xquery"'>
import module namespace session = "http://basex.org/modules/session";
'Value of ' || $key || ': ' || session:get($key)
</syntaxhighlightpre>
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>session:set|( $name as xs:string, $value as item()*|) as empty-sequence()}}</pre>|-valign="top"
| '''Summary'''
|Binds the specified {{Code|$value}} to the session attribute with the specified {{Code|$name}}.
|-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|set.xq}} via <code><nowiki>http://localhost:89848080/set.xq?key=user&value=john</nowiki></code>:<syntaxhighlight pre lang="'xquery"'>
import module namespace session = "http://basex.org/modules/session";
session:set($key, $value), 'Variable was set.'
</syntaxhighlightpre>
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>session:delete|( $name as xs:string|) as empty-sequence()}}</pre>|-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>:<syntaxhighlight pre lang="'xquery"'>
import module namespace session = "http://basex.org/modules/session";
session:delete($key), 'Variable was deleted.'
</syntaxhighlightpre>
|}
{| width='100%'
|-valign="top"| width='120' | '''SignaturesSignature'''|{{Func|<pre>session:close||() as empty-sequence()}}</pre>|-valign="top"
| '''Summary'''
|Unregisters a session and all data associated with it.
! width="110"|Code
|Description
|-valign="top"
|{{Code|not-found}}
|No session is available for the current client.
Bureaucrats, editor, reviewer, Administrators
13,554

edits

Navigation menu