Merge lp:~zorba-coders/zorba/feature-xqxq_variable-value into lp:zorba

Proposed by Matthias Brantner
Status: Merged
Approved by: Juan Zacarias
Approved revision: 11241
Merged at revision: 11241
Proposed branch: lp:~zorba-coders/zorba/feature-xqxq_variable-value
Merge into: lp:zorba
Diff against target: 184 lines (+116/-2)
6 files modified
ChangeLog (+1/-0)
modules/xqxq/xqxq.xq (+18/-0)
modules/xqxq/xqxq.xq.src/xqxq.cpp (+62/-0)
modules/xqxq/xqxq.xq.src/xqxq.h (+32/-0)
test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-variable.xml.res (+1/-1)
test/rbkt/Queries/zorba/xqxq/is-bound-variable.xq (+2/-1)
To merge this branch: bzr merge lp:~zorba-coders/zorba/feature-xqxq_variable-value
Reviewer Review Type Date Requested Status
Juan Zacarias Approve
Matthias Brantner Approve
Review via email: mp+148617@code.launchpad.net

Commit message

addex xqxq:variable-value function

Description of the change

addex xqxq:variable-value function

To post a comment you must log in.
Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job feature-xqxq_variable-value-2013-02-15T06-52-52.515Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve, 1 Pending.

Revision history for this message
Juan Zacarias (juan457) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job feature-xqxq_variable-value-2013-02-15T13-18-43.221Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2013-02-13 16:25:55 +0000
3+++ ChangeLog 2013-02-15 06:14:24 +0000
4@@ -12,6 +12,7 @@
5 * In store API, added ability to specify a stream's originating URI (file)
6 for streamable strings and base64Binary.
7 * Added millis-to-dateTime() function in datetime module.
8+ * Addex xqxq:variable-value function.
9
10 Optimizations:
11 * Extended optimization rules for subsequence function (pushing $startingLoc
12
13=== modified file 'modules/xqxq/xqxq.xq'
14--- modules/xqxq/xqxq.xq 2012-10-25 00:07:03 +0000
15+++ modules/xqxq/xqxq.xq 2013-02-15 06:14:24 +0000
16@@ -369,6 +369,24 @@
17 declare %an:sequential function xqxq:delete-query($query-key as xs:anyURI) as
18 empty-sequence() external;
19
20+(:~
21+ : This function returns the value of a variable that is bound in the
22+ : given query.
23+ :
24+ : @param $query-key the identifier of a compiled query.
25+ : @param $var-name the name of the variable whose value should be returned.
26+ :
27+ : @return the value bound to the given variable.
28+ :
29+ : @error xqxq:NoQueryMatch if no query with the given identifier
30+ : was prepared.
31+ : @error xqxq:UndeclaredVariable if the given variable is not declared
32+ : in the query.
33+ : @error xqxq:UnboundVariable if the given variable doesn't have a value.
34+ :)
35+declare function xqxq:variable-value($query-key as xs:anyURI, $var-name as
36+ xs:QName) as item()* external;
37+
38
39 (:~
40 : Internal helper function. Only necessary because of incomplete HOF
41
42=== modified file 'modules/xqxq/xqxq.xq.src/xqxq.cpp'
43--- modules/xqxq/xqxq.xq.src/xqxq.cpp 2013-01-28 20:05:18 +0000
44+++ modules/xqxq/xqxq.xq.src/xqxq.cpp 2013-02-15 06:14:24 +0000
45@@ -81,6 +81,10 @@
46 {
47 lFunc = new DeleteQueryFunction(this);
48 }
49+ else if (localName == "variable-value")
50+ {
51+ lFunc = new VariableValueFunction(this);
52+ }
53 }
54
55 return lFunc;
56@@ -907,6 +911,64 @@
57 return ItemSequence_t(new EmptySequence());
58 }
59
60+
61+/*******************************************************************************
62+
63+********************************************************************************/
64+zorba::ItemSequence_t VariableValueFunction::evaluate(
65+ const Arguments_t& aArgs,
66+ const zorba::StaticContext* aSctx,
67+ const zorba::DynamicContext* aDctx) const
68+{
69+ String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
70+
71+ QueryMap* lQueryMap;
72+ if (!(lQueryMap= dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("xqxqQueryMap"))))
73+ {
74+ throwError("NoQueryMatch", "String identifying query does not exists.");
75+ }
76+
77+ XQuery_t lQuery = getQuery(aDctx, lQueryID);
78+
79+ Item lVarQName = XQXQFunction::getItemArgument(aArgs, 1);
80+ bool lIsBoundVariable = false;
81+
82+ zorba::DynamicContext* lCtx = lQuery->getDynamicContext();
83+ zorba::String lNS = lVarQName.getNamespace(), lLocal = lVarQName.getLocalName();
84+
85+ try
86+ {
87+ lIsBoundVariable = lCtx->isBoundExternalVariable(lNS, lLocal);
88+ }
89+ catch (ZorbaException& ze)
90+ {
91+ if (ze.diagnostic() == zerr::ZAPI0011_VARIABLE_NOT_DECLARED)
92+ XQXQFunction::throwError("UndeclaredVariable", ze.what());
93+ throw; // should not happen
94+ }
95+
96+ if (!lIsBoundVariable)
97+ {
98+ std::ostringstream lMsg;
99+ lMsg << lLocal << ": variable not bound";
100+ XQXQFunction::throwError("UnboundVariable", lMsg.str());
101+ }
102+
103+ zorba::Iterator_t lIterator;
104+ zorba::Item lItem;
105+
106+ lCtx->getVariable(lNS, lLocal, lItem, lIterator);
107+
108+ if (lIterator)
109+ {
110+ return ItemSequence_t(new ValueItemSequence(lIterator));
111+ }
112+ else
113+ {
114+ return ItemSequence_t(new SingletonItemSequence(lItem));
115+ }
116+}
117+
118
119 }/*namespace xqxq*/ }/*namespace zorba*/
120
121
122=== modified file 'modules/xqxq/xqxq.xq.src/xqxq.h'
123--- modules/xqxq/xqxq.xq.src/xqxq.h 2013-01-30 12:26:39 +0000
124+++ modules/xqxq/xqxq.xq.src/xqxq.h 2013-02-15 06:14:24 +0000
125@@ -528,6 +528,38 @@
126 const zorba::DynamicContext*) const;
127 };
128
129+ class VariableValueFunction : public XQXQFunction{
130+ protected:
131+ class ValueItemSequence : public ItemSequence
132+ {
133+ protected:
134+ Iterator_t theIterator;
135+
136+ public:
137+ ValueItemSequence(Iterator_t& aIter)
138+ : theIterator(aIter)
139+ {
140+ }
141+
142+ virtual ~ValueItemSequence(){}
143+
144+ Iterator_t
145+ getIterator() { return theIterator; }
146+
147+ };
148+ public:
149+ VariableValueFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
150+
151+ virtual ~VariableValueFunction() {}
152+
153+ virtual zorba::String
154+ getLocalName() const {return "variable-value"; }
155+
156+ virtual zorba::ItemSequence_t
157+ evaluate(const Arguments_t&,
158+ const zorba::StaticContext*,
159+ const zorba::DynamicContext*) const;
160+ };
161
162
163 }/*xqxq namespace*/}/*zorba namespace*/
164
165=== modified file 'test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-variable.xml.res'
166--- test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-variable.xml.res 2012-10-25 00:07:03 +0000
167+++ test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-variable.xml.res 2013-02-15 06:14:24 +0000
168@@ -1,2 +1,2 @@
169 <?xml version="1.0" encoding="UTF-8"?>
170-true true false
171\ No newline at end of file
172+true true false foo
173
174=== modified file 'test/rbkt/Queries/zorba/xqxq/is-bound-variable.xq'
175--- test/rbkt/Queries/zorba/xqxq/is-bound-variable.xq 2012-10-25 00:07:03 +0000
176+++ test/rbkt/Queries/zorba/xqxq/is-bound-variable.xq 2013-02-15 06:14:24 +0000
177@@ -7,4 +7,5 @@
178 xqxq:bind-variable($query-key, xs:QName('a'), "foo");
179 xqxq:is-bound-variable($query-key, xs:QName('a')),
180 xqxq:is-bound-variable($query-key, xs:QName('b')),
181-xqxq:is-bound-variable($query-key, xs:QName('c'))
182\ No newline at end of file
183+xqxq:is-bound-variable($query-key, xs:QName('c')),
184+xqxq:variable-value($query-key, xs:QName('a'))

Subscribers

People subscribed via source and target branches