Changes

Jump to navigation Jump to search
492 bytes added ,  06:53, 29 November 2019
=Conventions=
As sessions are side* The module will be available if the {{Code|basex-effecting operations, all functions api}} library is found in this module are flagged as ''non-deterministic''the classpath. This means that is the evaluation order case if you use one of the functions will not be influenced by the compilercomplete distributions of BaseX (zip, exe, war)* All functions and errors are assigned to the {{Code|<code><nowiki>http://basex.org/modules/session}} </nowiki></code> namespace, which must be dynamically imported. In this documentation, the namespace is statically bound to the {{Code|session}} prefix. * If any of the functions is called outside the servlet context, <code>[[XQuery Errors#BaseX Errors are assigned to the {{Code|basex:http:]]<//basexcode> is raised.* As sessions are side-effecting operations, all functions are flagged as ''non-deterministic''.org/errors}} namespaceAs a result, which is statically bound to the {{Code|bxerr}} prefixsome query optimizations will be suppressed.
=Functions=
==session:id==
 
{| width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|session:id||xs:string}}
|-
|-
| '''Examples'''
|Running a RESTXQ function the server-side XQuery file {{Code|id.xq}} via <code><nowiki>http://localhost:8984/restxq/id.xq</nowiki></code>:
<pre class="brush:xquery">
module namespace test = 'http://basex.org/examples/test';
import module namespace session = "http://basex.org/modules/session";
declare %restxq:path("/id") function test:id() { 'Session ID: ' || session:id()};
</pre>
|}
==session:keyscreated== {| width='100%'|-| width='120' | '''Signatures'''|{{Func|session:created||xs:dateTime}}|-| '''Summary'''|Returns the creation time of a session.|} ==session:accessed== {| width='100%'|-| width='120' | '''Signatures'''|{{Func|session:accessed||xs:dateTime}}|-| '''Summary'''|Returns the last access time of a session.|} ==session:names== 
{| width='100%'
|-
| width='90120' | '''Signatures'''|{{Func|session:keysnames||xs:string*}}
|-
| '''Summary'''
|Returns the names of all variables attributes bound to the current session.
|-
| '''Examples'''
|Running the server-side XQuery file {{Code|keysnames.xq}} via <code><nowiki>http://localhost:8984/keysnames.xq</nowiki></code>:
<pre class="brush:xquery">
import module namespace session = "http://basex.org/modules/session";
session:keysnames() ! element variable { . }
</pre>
|}
==session:get==
 
{{Mark|Updated with Version 9.3:}} Values that have no XQuery type will be returned as strings.
 
{| width='100%'
|-
| width='90120' | '''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()*}}
|-
| '''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.
|-
| '''Examples'''
==session:set==
 
{| width='100%'
|-
| width='90120' | '''Signatures'''|{{Func|session:set|$key name as xs:string, $value as xs:stringitem()*|empty-sequence()}}
|-
| '''Summary'''
|Assigns a Binds the specified {{Code|$value }} to a the session variableattribute with the specified {{Code|$name}}.
|-
| '''Errors'''
|{{Error|BXSE0001set|#Errors}} a function item was specified as The supplied value of a session variablecannot be materialized.
|-
| '''Examples'''
==session:delete==
 
{| width='100%'
|-
| width='90120' | '''Signatures'''|{{Func|session:delete|$key name as xs:string|empty-sequence()}}
|-
| '''Summary'''
|Deletes a session variable.|-| '''Errors'''|{{Error|BXSE0001|#Errors}} a function item was attribute with the specified as value of a session variable<code>$name</code>.
|-
| '''Examples'''
==session:close==
 
{| width='100%'
|-
| width='90120' | '''Signatures'''
|{{Func|session:close||empty-sequence()}}
|-
{| class="wikitable" width="100%"
! width="5%110"|Code! width="95%"|Description
|-
|{{Code|BXSE0001set}}|A function item was specified as The supplied value of a session attribute.|-|{{Code|BXSE0002}}|An error occurred while retrieving the value of a session attributecannot be materialized.
|}
=Changelog=
 
;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.
 
[[Category:XQuery]]
Bureaucrats, editor, reviewer, Administrators
13,550

edits

Navigation menu