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
=== modified file 'ChangeLog'
--- ChangeLog 2013-02-13 16:25:55 +0000
+++ ChangeLog 2013-02-15 06:14:24 +0000
@@ -12,6 +12,7 @@
12 * In store API, added ability to specify a stream's originating URI (file)12 * In store API, added ability to specify a stream's originating URI (file)
13 for streamable strings and base64Binary.13 for streamable strings and base64Binary.
14 * Added millis-to-dateTime() function in datetime module.14 * Added millis-to-dateTime() function in datetime module.
15 * Addex xqxq:variable-value function.
1516
16Optimizations:17Optimizations:
17 * Extended optimization rules for subsequence function (pushing $startingLoc18 * Extended optimization rules for subsequence function (pushing $startingLoc
1819
=== modified file 'modules/xqxq/xqxq.xq'
--- modules/xqxq/xqxq.xq 2012-10-25 00:07:03 +0000
+++ modules/xqxq/xqxq.xq 2013-02-15 06:14:24 +0000
@@ -369,6 +369,24 @@
369declare %an:sequential function xqxq:delete-query($query-key as xs:anyURI) as369declare %an:sequential function xqxq:delete-query($query-key as xs:anyURI) as
370 empty-sequence() external;370 empty-sequence() external;
371371
372(:~
373 : This function returns the value of a variable that is bound in the
374 : given query.
375 :
376 : @param $query-key the identifier of a compiled query.
377 : @param $var-name the name of the variable whose value should be returned.
378 :
379 : @return the value bound to the given variable.
380 :
381 : @error xqxq:NoQueryMatch if no query with the given identifier
382 : was prepared.
383 : @error xqxq:UndeclaredVariable if the given variable is not declared
384 : in the query.
385 : @error xqxq:UnboundVariable if the given variable doesn't have a value.
386 :)
387declare function xqxq:variable-value($query-key as xs:anyURI, $var-name as
388 xs:QName) as item()* external;
389
372390
373(:~391(:~
374 : Internal helper function. Only necessary because of incomplete HOF392 : Internal helper function. Only necessary because of incomplete HOF
375393
=== modified file 'modules/xqxq/xqxq.xq.src/xqxq.cpp'
--- modules/xqxq/xqxq.xq.src/xqxq.cpp 2013-01-28 20:05:18 +0000
+++ modules/xqxq/xqxq.xq.src/xqxq.cpp 2013-02-15 06:14:24 +0000
@@ -81,6 +81,10 @@
81 {81 {
82 lFunc = new DeleteQueryFunction(this);82 lFunc = new DeleteQueryFunction(this);
83 }83 }
84 else if (localName == "variable-value")
85 {
86 lFunc = new VariableValueFunction(this);
87 }
84 }88 }
85 89
86 return lFunc;90 return lFunc;
@@ -907,6 +911,64 @@
907 return ItemSequence_t(new EmptySequence());911 return ItemSequence_t(new EmptySequence());
908}912}
909913
914
915/*******************************************************************************
916
917********************************************************************************/
918zorba::ItemSequence_t VariableValueFunction::evaluate(
919 const Arguments_t& aArgs,
920 const zorba::StaticContext* aSctx,
921 const zorba::DynamicContext* aDctx) const
922{
923 String lQueryID = XQXQFunction::getOneStringArgument(aArgs,0);
924
925 QueryMap* lQueryMap;
926 if (!(lQueryMap= dynamic_cast<QueryMap*>(aDctx->getExternalFunctionParameter("xqxqQueryMap"))))
927 {
928 throwError("NoQueryMatch", "String identifying query does not exists.");
929 }
930
931 XQuery_t lQuery = getQuery(aDctx, lQueryID);
932
933 Item lVarQName = XQXQFunction::getItemArgument(aArgs, 1);
934 bool lIsBoundVariable = false;
935
936 zorba::DynamicContext* lCtx = lQuery->getDynamicContext();
937 zorba::String lNS = lVarQName.getNamespace(), lLocal = lVarQName.getLocalName();
938
939 try
940 {
941 lIsBoundVariable = lCtx->isBoundExternalVariable(lNS, lLocal);
942 }
943 catch (ZorbaException& ze)
944 {
945 if (ze.diagnostic() == zerr::ZAPI0011_VARIABLE_NOT_DECLARED)
946 XQXQFunction::throwError("UndeclaredVariable", ze.what());
947 throw; // should not happen
948 }
949
950 if (!lIsBoundVariable)
951 {
952 std::ostringstream lMsg;
953 lMsg << lLocal << ": variable not bound";
954 XQXQFunction::throwError("UnboundVariable", lMsg.str());
955 }
956
957 zorba::Iterator_t lIterator;
958 zorba::Item lItem;
959
960 lCtx->getVariable(lNS, lLocal, lItem, lIterator);
961
962 if (lIterator)
963 {
964 return ItemSequence_t(new ValueItemSequence(lIterator));
965 }
966 else
967 {
968 return ItemSequence_t(new SingletonItemSequence(lItem));
969 }
970}
971
910 972
911}/*namespace xqxq*/ }/*namespace zorba*/973}/*namespace xqxq*/ }/*namespace zorba*/
912974
913975
=== modified file 'modules/xqxq/xqxq.xq.src/xqxq.h'
--- modules/xqxq/xqxq.xq.src/xqxq.h 2013-01-30 12:26:39 +0000
+++ modules/xqxq/xqxq.xq.src/xqxq.h 2013-02-15 06:14:24 +0000
@@ -528,6 +528,38 @@
528 const zorba::DynamicContext*) const;528 const zorba::DynamicContext*) const;
529};529};
530530
531 class VariableValueFunction : public XQXQFunction{
532 protected:
533 class ValueItemSequence : public ItemSequence
534 {
535 protected:
536 Iterator_t theIterator;
537
538 public:
539 ValueItemSequence(Iterator_t& aIter)
540 : theIterator(aIter)
541 {
542 }
543
544 virtual ~ValueItemSequence(){}
545
546 Iterator_t
547 getIterator() { return theIterator; }
548
549 };
550 public:
551 VariableValueFunction(const XQXQModule* aModule) : XQXQFunction(aModule) {}
552
553 virtual ~VariableValueFunction() {}
554
555 virtual zorba::String
556 getLocalName() const {return "variable-value"; }
557
558 virtual zorba::ItemSequence_t
559 evaluate(const Arguments_t&,
560 const zorba::StaticContext*,
561 const zorba::DynamicContext*) const;
562 };
531563
532564
533}/*xqxq namespace*/}/*zorba namespace*/565}/*xqxq namespace*/}/*zorba namespace*/
534566
=== modified file 'test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-variable.xml.res'
--- test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-variable.xml.res 2012-10-25 00:07:03 +0000
+++ test/rbkt/ExpQueryResults/zorba/xqxq/is-bound-variable.xml.res 2013-02-15 06:14:24 +0000
@@ -1,2 +1,2 @@
1<?xml version="1.0" encoding="UTF-8"?>1<?xml version="1.0" encoding="UTF-8"?>
2true true false
3\ No newline at end of file2\ No newline at end of file
3true true false foo
44
=== modified file 'test/rbkt/Queries/zorba/xqxq/is-bound-variable.xq'
--- test/rbkt/Queries/zorba/xqxq/is-bound-variable.xq 2012-10-25 00:07:03 +0000
+++ test/rbkt/Queries/zorba/xqxq/is-bound-variable.xq 2013-02-15 06:14:24 +0000
@@ -7,4 +7,5 @@
7xqxq:bind-variable($query-key, xs:QName('a'), "foo");7xqxq:bind-variable($query-key, xs:QName('a'), "foo");
8xqxq:is-bound-variable($query-key, xs:QName('a')),8xqxq:is-bound-variable($query-key, xs:QName('a')),
9xqxq:is-bound-variable($query-key, xs:QName('b')),9xqxq:is-bound-variable($query-key, xs:QName('b')),
10xqxq:is-bound-variable($query-key, xs:QName('c'))
11\ No newline at end of file10\ No newline at end of file
11xqxq:is-bound-variable($query-key, xs:QName('c')),
12xqxq:variable-value($query-key, xs:QName('a'))

Subscribers

People subscribed via source and target branches