Matthias Brantner has proposed merging lp:~zorba-coders/zorba/msb-misc into lp:zorba.
Commit message: expose setDefaultFunctionNamespaces in the C++ api Requested reviews: Matthias Brantner (matthias-brantner) For more details, see: https://code.launchpad.net/~zorba-coders/zorba/msb-misc/+merge/155370 -- https://code.launchpad.net/~zorba-coders/zorba/msb-misc/+merge/155370 Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'include/zorba/static_context.h' --- include/zorba/static_context.h 2013-03-21 23:41:00 +0000 +++ include/zorba/static_context.h 2013-03-25 23:12:21 +0000 @@ -803,6 +803,16 @@ virtual void clearBaseURI() = 0; + /** \brief Sets a list of default function namespaces that will be + * used in order during the lookup of functions. + * + * @param aURIs the list of default function namespaces. + * @return true if the said namespaces have been set, false otherwise + * if an DiagnosticHandler has been registered. + * @throw ZorbaException if an error occured. + */ + virtual bool + setDefaultFunctionNamespaces( const std::vector<String>& aURIs ) = 0; }; } /* namespace zorba */ === modified file 'src/api/staticcontextimpl.cpp' --- src/api/staticcontextimpl.cpp 2013-03-21 23:41:00 +0000 +++ src/api/staticcontextimpl.cpp 2013-03-25 23:12:21 +0000 @@ -337,6 +337,35 @@ /******************************************************************************* ********************************************************************************/ +bool +StaticContextImpl::setDefaultFunctionNamespaces( + const std::vector<String>& aURIs) +{ + try + { + for (std::vector<String>::const_reverse_iterator lIter = aURIs.rbegin(); + lIter != aURIs.rend(); ++lIter) + { + const zstring& lURI = Unmarshaller::getInternalString(*lIter); + QueryLoc loc; + theCtx->set_default_function_ns(lURI, false, loc); + } + } + catch (ZorbaException const& e) + { + ZorbaImpl::notifyError(theDiagnosticHandler, e); + } + catch (std::exception const& e) + { + ZorbaImpl::notifyError(theDiagnosticHandler, e.what()); + } + return ""; +} + + +/******************************************************************************* + +********************************************************************************/ void StaticContextImpl::addCollation( const String& URI ) { === modified file 'src/api/staticcontextimpl.h' --- src/api/staticcontextimpl.h 2013-03-21 23:41:00 +0000 +++ src/api/staticcontextimpl.h 2013-03-25 23:12:21 +0000 @@ -104,6 +104,9 @@ virtual String getDefaultFunctionNamespace() const; + virtual bool + setDefaultFunctionNamespaces( const std::vector<String>& aURIs ); + virtual void addCollation( const String& URI ); === modified file 'test/unit/test_static_context.cpp' --- test/unit/test_static_context.cpp 2012-06-28 04:14:03 +0000 +++ test/unit/test_static_context.cpp 2013-03-25 23:12:21 +0000 @@ -357,27 +357,82 @@ } +bool +sctx_test_6(Zorba* zorba) +{ + std::stringstream queryString; + + queryString + << "jsoniq version '1.0';\n" + << "declare function local:concat() { fn:current-dateTime() };\n" + << "trace(concat(), 'concat') instance of xs:dateTime"; + + StaticContext_t sctx = zorba->createStaticContext(); + + std::vector<String> lNamespaces; + lNamespaces.push_back("http://www.w3.org/2005/xquery-local-functions"); + lNamespaces.push_back("http://www.w3.org/2005/xpath-functions"); + sctx->setDefaultFunctionNamespaces(lNamespaces); + + { + XQuery_t lQuery = zorba->compileQuery(queryString.str(), sctx); + std::ofstream planFile("out.plan"); + assert(planFile.good()); + + lQuery->saveExecutionPlan(planFile); + } + { + std::ifstream planFile("out.plan"); + assert(planFile.good()); + + XQuery_t query = zorba->createQuery(); + + query->loadExecutionPlan(planFile); + + Iterator_t lIter = query->iterator(); + + lIter->open(); + + Item lItem; + if (!lIter->next(lItem) || !lItem.getBooleanValue()) + { + return false; + } + } + return true; +} + + int test_static_context( int argc, char *argv[] ) { void* zstore = StoreManager::getStore(); Zorba* zorba = Zorba::getInstance(zstore); + std::cout << "executing sctx_test_1" << std::endl; if (!sctx_test_1(zorba)) return 1; + std::cout << "executing sctx_test_2" << std::endl; if (!sctx_test_2(zorba)) return 2; + std::cout << "executing sctx_test_3" << std::endl; if (!sctx_test_3(zorba)) return 3; + std::cout << "executing sctx_test_4" << std::endl; if (!sctx_test_4(zorba)) return 4; + std::cout << "executing sctx_test_5" << std::endl; if (!sctx_test_5(zorba)) return 5; + std::cout << "executing sctx_test_6" << std::endl; + if (!sctx_test_6(zorba)) + return 5; + zorba->shutdown(); StoreManager::shutdownStore( zstore ); return 0;
-- Mailing list: https://launchpad.net/~zorba-coders Post to : zorba-coders@lists.launchpad.net Unsubscribe : https://launchpad.net/~zorba-coders More help : https://help.launchpad.net/ListHelp