zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #24668
[Merge] lp:~zorba-coders/zorba/markos-scratch into lp:zorba
Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch into lp:zorba.
Commit message:
added a DynamicContextImpl::setVariable() function + cosmetic
Requested reviews:
Markos Zaharioudakis (markos-za)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/178011
added a DynamicContextImpl::setVariable() function + cosmetic
--
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/178011
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'include/zorba/dynamic_context.h'
--- include/zorba/dynamic_context.h 2013-06-11 23:38:49 +0000
+++ include/zorba/dynamic_context.h 2013-08-01 08:00:47 +0000
@@ -68,6 +68,25 @@
const String& aQName,
const Item& aItem) = 0;
+ /**
+ * \brief Defines the external variable identified by an expanded QName and
+ * assigns it the value of aItem.
+ *
+ * The named external variable may be located in the main query or in any
+ * modules imported directly or indirectly by the query.
+ *
+ * @param aNamespace the namespace URI of the variable's expanded QName
+ * @param aLocalname the local name of the variable's expanded QName
+ * @param aItem the Item that is used as value for the variable.
+ * @return true if the variable has been set successfully, false otherwise.
+ * @throw ZorbaException if an error occured (e.g. the given Item is not valid).
+ */
+ virtual bool
+ setVariable(
+ const String& inNamespace,
+ const String& inLocalname,
+ const Item& inValue) = 0;
+
/**
* \brief Defines the external variable identified by aQName and assigns it
* the sequence that is returned by evaluating aIterator.
=== modified file 'src/api/dynamiccontextimpl.cpp'
--- src/api/dynamiccontextimpl.cpp 2013-06-18 23:53:59 +0000
+++ src/api/dynamiccontextimpl.cpp 2013-08-01 08:00:47 +0000
@@ -34,6 +34,8 @@
#include "api/xqueryimpl.h"
#include "api/resultiteratorimpl.h"
#include "api/storeiteratorimpl.h"
+//#include "api/item_iter_query_result.h"
+//#include "api/item_iter_store.h"
#include "api/dynamiccontextimpl.h"
#include "compiler/parser/query_loc.h"
@@ -231,6 +233,55 @@
********************************************************************************/
bool DynamicContextImpl::setVariable(
+ const String& inVarName,
+ const Iterator_t& inValue)
+{
+ ZORBA_DCTX_TRY
+ {
+ checkNoIterators();
+
+ if (!inValue.get())
+ {
+ throw ZORBA_EXCEPTION(zerr::ZAPI0014_INVALID_ARGUMENT,
+ ERROR_PARAMS("null", ZED( BadIterator)));
+ }
+
+ const zstring& varName = Unmarshaller::getInternalString(inVarName);
+ store::Iterator_t value = Unmarshaller::getInternalIterator(inValue.get());
+
+ VarInfo* var = NULL;
+
+ try
+ {
+ var = get_var_info(varName);
+ }
+ catch (ZorbaException const& e)
+ {
+ // Normally, we should be throwing an exception if the variable has not
+ // been declared inside the xquery program, but this cases many failures
+ // with the w3c XQTS.
+ if (e.diagnostic() == err::XPST0008)
+ {
+ return false;
+ }
+ throw;
+ }
+
+ ulong varId = var->getId();
+
+ theCtx->add_variable(varId, value);
+
+ return true;
+ }
+ ZORBA_DCTX_CATCH
+ return false;
+}
+
+
+/****************************************************************************//**
+
+********************************************************************************/
+bool DynamicContextImpl::setVariable(
const String& inNamespace,
const String& inLocalname,
const Iterator_t& inValue)
@@ -247,6 +298,7 @@
const zstring& nameSpace = Unmarshaller::getInternalString(inNamespace);
const zstring& localName = Unmarshaller::getInternalString(inLocalname);
+
store::Iterator_t value = Unmarshaller::getInternalIterator(inValue.get());
VarInfo* var = NULL;
@@ -282,6 +334,53 @@
********************************************************************************/
bool DynamicContextImpl::setVariable(
+ const String& inNamespace,
+ const String& inLocalname,
+ const Item& inValue)
+{
+ ZORBA_DCTX_TRY
+ {
+ checkNoIterators();
+
+ const zstring& nameSpace = Unmarshaller::getInternalString(inNamespace);
+ const zstring& localName = Unmarshaller::getInternalString(inLocalname);
+
+ store::Item_t value(Unmarshaller::getInternalItem(inValue));
+ checkItem(value);
+
+ VarInfo* var = NULL;
+
+ try
+ {
+ var = get_var_info(nameSpace, localName);
+ }
+ catch (ZorbaException const& e)
+ {
+ // Normally, we should be throwing an exception if the variable has not
+ // been declared inside the xquery program, but this causes many failures
+ // with the w3c XQTS.
+ if (e.diagnostic() == err::XPST0008)
+ {
+ return false;
+ }
+ throw;
+ }
+
+ ulong varId = var->getId();
+
+ theCtx->add_variable(varId, value);
+
+ return true;
+ }
+ ZORBA_DCTX_CATCH
+ return false;
+}
+
+
+/****************************************************************************//**
+
+********************************************************************************/
+bool DynamicContextImpl::setVariable(
const String& inVarName,
const Item& inValue)
{
@@ -291,103 +390,68 @@
// unmarshall the string and the item
const zstring& varName = Unmarshaller::getInternalString(inVarName);
+
store::Item_t value(Unmarshaller::getInternalItem(inValue));
- ZorbaImpl::checkItem(value);
-
- // For string items, check that the value is a valid Unicode codepoint sequence
+ checkItem(value);
+
+ VarInfo* var = NULL;
+
+ try
+ {
+ var = get_var_info(varName);
+ }
+ catch (ZorbaException const& e)
+ {
+ // Normally, we should be throwing an exception if the variable has not
+ // been declared inside the xquery program, but this cases many failures
+ // with the w3c XQTS.
+ if (e.diagnostic() == err::XPST0008)
+ {
+ return false;
+ }
+ throw;
+ }
+
+ ulong varId = var->getId();
+
+ theCtx->add_variable(varId, value);
+
+ return true;
+ }
+ ZORBA_DCTX_CATCH
+ return false;
+}
+
+
+/****************************************************************************//**
+
+********************************************************************************/
+void DynamicContextImpl::checkItem(const store::Item_t& item)
+{
+ if (!item)
+ {
+ throw ZORBA_EXCEPTION(zerr::ZAPI0014_INVALID_ARGUMENT,
+ ERROR_PARAMS("null", ZED(BadItem)));
+ }
+
+ // For string items, check that the value is a valid Unicode codepoint sequence
+ if (item->isStreamable() == false && item->isAtomic())
+ {
const char* invalid_char;
- if (value->isStreamable() == false && value->isAtomic())
- {
- store::SchemaTypeCode itemTypeCode = value->getTypeCode();
-
- if (TypeOps::is_subtype(itemTypeCode, store::XS_STRING) &&
- (invalid_char = utf8::validate(value->getStringValue().c_str())) != NULL)
- {
- throw XQUERY_EXCEPTION(err::FOCH0001,
- ERROR_PARAMS(zstring("#x") +
- BUILD_STRING(std::uppercase << std::hex
- << (static_cast<unsigned int>(*invalid_char) & 0xFF)) ));
- }
- }
-
- VarInfo* var = NULL;
-
- try
- {
- var = get_var_info(varName);
- }
- catch (ZorbaException const& e)
- {
- // Normally, we should be throwing an exception if the variable has not
- // been declared inside the xquery program, but this cases many failures
- // with the w3c XQTS.
- if (e.diagnostic() == err::XPST0008)
- {
- return false;
- }
- throw;
- }
-
- ulong varId = var->getId();
-
- // add it to the internal context
- theCtx->add_variable(varId, value);
-
- return true;
- }
- ZORBA_DCTX_CATCH
- return false;
-}
-
-
-/****************************************************************************//**
-
-********************************************************************************/
-bool DynamicContextImpl::setVariable(
- const String& inVarName,
- const Iterator_t& inValue)
-{
- ZORBA_DCTX_TRY
- {
- checkNoIterators();
-
- if (!inValue.get())
- {
- throw ZORBA_EXCEPTION(zerr::ZAPI0014_INVALID_ARGUMENT,
- ERROR_PARAMS("null", ZED( BadIterator)));
- }
-
- const zstring& varName = Unmarshaller::getInternalString(inVarName);
- store::Iterator_t value = Unmarshaller::getInternalIterator(inValue.get());
-
- VarInfo* var = NULL;
-
- try
- {
- var = get_var_info(varName);
- }
- catch (ZorbaException const& e)
- {
- // Normally, we should be throwing an exception if the variable has not
- // been declared inside the xquery program, but this cases many failures
- // with the w3c XQTS.
- if (e.diagnostic() == err::XPST0008)
- {
- return false;
- }
- throw;
- }
-
- ulong varId = var->getId();
-
- theCtx->add_variable(varId, value);
-
- return true;
- }
- ZORBA_DCTX_CATCH
- return false;
-}
+ store::SchemaTypeCode itemTypeCode = item->getTypeCode();
+
+ if (TypeOps::is_subtype(itemTypeCode, store::XS_STRING) &&
+ (invalid_char = utf8::validate(item->getStringValue().c_str())) != NULL)
+ {
+ throw XQUERY_EXCEPTION(err::FOCH0001,
+ ERROR_PARAMS(zstring("#x") +
+ BUILD_STRING(std::uppercase << std::hex
+ << (static_cast<unsigned int>(*invalid_char) & 0xFF))));
+ }
+ }
+}
+
/****************************************************************************//**
@@ -579,7 +643,7 @@
store::Item_t lItem = Unmarshaller::getInternalItem(aDateTimeItem);
- ZorbaImpl::checkItem(lItem);
+ checkItem(lItem);
TypeManager* tm = theStaticContext->get_typemanager();
@@ -661,7 +725,7 @@
checkNoIterators();
store::Item_t lItem = Unmarshaller::getInternalItem(aCollectionUri);
- ZorbaImpl::checkItem(lItem);
+ checkItem(lItem);
theCtx->set_default_collection(lItem);
return true;
@@ -697,27 +761,37 @@
return Item();
}
+
/****************************************************************************//**
********************************************************************************/
-void DynamicContextImpl::setLocale( locale::iso639_1::type aLang,
- locale::iso3166_1::type aCountry ) {
+void DynamicContextImpl::setLocale(
+ locale::iso639_1::type aLang,
+ locale::iso3166_1::type aCountry )
+{
theCtx->set_locale( aLang, aCountry );
}
-void DynamicContextImpl::getLocale( locale::iso639_1::type *aLang,
- locale::iso3166_1::type *aCountry ) const {
- theCtx->get_locale( aLang, aCountry );
+
+void DynamicContextImpl::getLocale(
+ locale::iso639_1::type *aLang,
+ locale::iso3166_1::type *aCountry) const
+{
+ theCtx->get_locale(aLang, aCountry);
}
+
/****************************************************************************//**
********************************************************************************/
-void DynamicContextImpl::setCalendar( time::calendar::type aCalendar ) {
- theCtx->set_calendar( aCalendar );
+void DynamicContextImpl::setCalendar(time::calendar::type aCalendar)
+{
+ theCtx->set_calendar(aCalendar);
}
-time::calendar::type DynamicContextImpl::getCalendar() const {
+
+time::calendar::type DynamicContextImpl::getCalendar() const
+{
return theCtx->get_calendar();
}
@@ -758,8 +832,7 @@
/****************************************************************************//**
********************************************************************************/
-bool
-DynamicContextImpl::addExternalFunctionParameter (
+bool DynamicContextImpl::addExternalFunctionParameter(
const String& aName,
ExternalFunctionParameter* aValue ) const
{
=== modified file 'src/api/dynamiccontextimpl.h'
--- src/api/dynamiccontextimpl.h 2013-03-13 16:17:38 +0000
+++ src/api/dynamiccontextimpl.h 2013-08-01 08:00:47 +0000
@@ -67,6 +67,9 @@
static_context * theStaticContext;
protected:
+ static void checkItem(const store::Item_t& aItem);
+
+protected:
DynamicContextImpl(const XQueryImpl* aQuery);
// Used by ExtFunctionCallIterator to create a temporary wrapper
@@ -97,6 +100,12 @@
virtual bool
setVariable(
+ const String& inNamespace,
+ const String& inLocalname,
+ const Item& inValue);
+
+ virtual bool
+ setVariable(
const String& inVarName,
const Iterator_t& inValue);
Follow ups