Exemplo n.º 1
0
void SimpleLazyTempSeqIter::init(
    const store::TempSeq_t& seq,
    xs_integer startPos,
    xs_integer endPos)
{
  assert(seq->isLazy());

  theTempSeq = static_cast<SimpleLazyTempSeq*>(seq.getp());

  try
  {
    theStartPos = to_xs_long(startPos);
  }
  catch ( std::range_error const& )
  {
    throw ZORBA_EXCEPTION(
      zerr::ZSTR0060_RANGE_EXCEPTION,
      ERROR_PARAMS( startPos, ZED( ZSTR0060_ForSequence ) )
    );
  }
  try
  {
    theEndPos = to_xs_long(endPos);
  }
  catch ( std::range_error const& )
  {
    throw ZORBA_EXCEPTION(
      zerr::ZSTR0060_RANGE_EXCEPTION,
      ERROR_PARAMS( endPos, ZED( ZSTR0060_ForSequence ) )
    );
  }

  theCurPos = theStartPos - 1;
}
Exemplo n.º 2
0
SimpleLazyTempSeqIter::SimpleLazyTempSeqIter(
    const SimpleLazyTempSeq* tempSeq,
    xs_integer startPos,
    xs_integer endPos)
  :
  theTempSeq(const_cast<SimpleLazyTempSeq*>(tempSeq))
{
  try
  {
    theStartPos = to_xs_long(startPos);
  }
  catch ( std::range_error const& )
  {
    throw ZORBA_EXCEPTION(
      zerr::ZSTR0060_RANGE_EXCEPTION,
      ERROR_PARAMS( startPos, ZED( ZSTR0060_ForSequence ) )
    );
  }
  try
  {
    theEndPos = to_xs_long(endPos);
  }
  catch ( std::range_error const& )
  {
    throw ZORBA_EXCEPTION(
      zerr::ZSTR0060_RANGE_EXCEPTION,
      ERROR_PARAMS( endPos, ZED( ZSTR0060_ForSequence ) )
    );
  }

  theCurPos = theStartPos - 1;
}
Exemplo n.º 3
0
void areNodeModifiersViolated(
    const static_context* aSctx,
    const store::Item* aTarget,
    const QueryLoc& aLoc)
{
  const store::Collection* lColl = aTarget->getCollection();
  if (lColl != 0 && !lColl->isDynamic()) 
  {
    const StaticallyKnownCollection* lDeclColl = 
    aSctx->lookup_collection(lColl->getName());

    if (lDeclColl == NULL)
    {
      throw XQUERY_EXCEPTION(zerr::ZDDY0001_COLLECTION_NOT_DECLARED,
                             ERROR_PARAMS(lColl->getName()->getStringValue()),
                             ERROR_LOC(aLoc));
    }

    switch(lDeclColl->getNodeModifier()) 
    {
    case StaticContextConsts::read_only:
      throw XQUERY_EXCEPTION(zerr::ZDDY0010_COLLECTION_CONST_NODE_UPDATE,
                             ERROR_PARAMS( lColl->getName()->getStringValue() ),
                             ERROR_LOC(aLoc));

    case StaticContextConsts::mutable_node:
      // good to go
      break;
    }
  }
}
Exemplo n.º 4
0
AnnotationList::RuleBitSet AnnotationList::checkDuplicateDeclarations(
    DeclarationKind declKind,
    const QueryLoc& loc) const
{
  RuleBitSet lCurrAnn;

  // mark and detect duplicates
  for (Annotations::const_iterator ite = theAnnotationList.begin();
       ite != theAnnotationList.end();
       ++ite)
  {
    const store::Item* qname = (*ite)->getQName();
    AnnotationId id = (*ite)->getId();

    // detect duplicate annotations (if we "know" them)
    if (id != AnnotationInternal::zann_end && lCurrAnn.test(id))
    {
      if (declKind == var_decl)
      {
        RAISE_ERROR(err::XQST0116, loc,
        ERROR_PARAMS(ZED(XQST0116_Duplicate), qname->getStringValue()));
      }
      else
      {
        RAISE_ERROR(err::XQST0106, loc,
        ERROR_PARAMS(ZED(XQST0106_Duplicate), qname->getStringValue()));
      }
    }
    lCurrAnn.set(id);
  }
  return lCurrAnn;
}
Exemplo n.º 5
0
store::IndexCondition_t IndexImpl::createCondition(store::IndexCondition::Kind k)
{
  if (!isSorted() &&
      (k == store::IndexCondition::BOX_VALUE || 
       k == store::IndexCondition::BOX_GENERAL))
  {
    RAISE_ERROR_NO_LOC(zerr::ZSTR0007_INDEX_UNSUPPORTED_PROBE_CONDITION,
    ERROR_PARAMS(IndexConditionImpl::getKindString(k), getName()->getStringValue()));
  }

  if (isGeneral())
  {
    return new GeneralIndexCondition(this, k);
  }
  else if (k == store::IndexCondition::POINT_VALUE)
  {
    return new IndexPointCondition(this, k);
  }
  else if (k == store::IndexCondition::BOX_VALUE)
  {
    return new IndexBoxValueCondition(this, k);
  }
  else
  {
    RAISE_ERROR_NO_LOC(zerr::ZSTR0007_INDEX_UNSUPPORTED_PROBE_CONDITION,
    ERROR_PARAMS(IndexConditionImpl::getKindString(k), getName()->getStringValue()));

    ZORBA_ASSERT(false);
  }
}
Exemplo n.º 6
0
bool
IndexKeysIterator::nextImpl(
    store::Item_t& result,
    PlanState& aPlanState) const
{
  store::Item_t    lQName;
  IndexDecl_t      indexDecl;
  store::IndexKey  lKey;

  store::Item_t lKeyNodeName;
  GENV_ITEMFACTORY->createQName(lKeyNodeName,
      static_context::ZORBA_STORE_UNORDERED_MAPS_FN_NS,
      "", "key");

  IndexKeysIteratorState* state;
  DEFAULT_STACK_INIT(IndexKeysIteratorState, state, aPlanState);

  consumeNext(lQName, theChildren[0].getp(), aPlanState);

  if ((indexDecl = theSctx->lookup_index(lQName)) == NULL)
  {
    throw XQUERY_EXCEPTION(
      zerr::ZDDY0021_INDEX_NOT_DECLARED,
      ERROR_PARAMS( lQName->getStringValue() ),
      ERROR_LOC( loc )
    );
  }

  state->theIndex = GENV_STORE.getIndex(lQName);

  if (!state->theIndex)
  {
    throw XQUERY_EXCEPTION(
      zerr::ZDDY0023_INDEX_DOES_NOT_EXIST,
      ERROR_PARAMS( lQName->getStringValue() ),
      ERROR_LOC( loc )
    );
  }

  state->theIter = state->theIndex->keys();

  state->theIter->open();

  // generate result elements of the form
  // <key>
  //   <attribute value="key1_value"/>
  //   <attribute value="key2_value"/>
  //   <attribute value="key3_value"/>
  // </key>
  while (state->theIter->next(lKey))
  {
    IndexUtil::createIndexKeyElement(
        state->theIndex->getSpecification().theIsGeneral,
        result, lKey, static_context::ZORBA_STORE_STATIC_INDEXES_DML_FN_NS
      );
    STACK_PUSH(true, state);
  }

  STACK_END(state);
}
Exemplo n.º 7
0
Item ItemFactoryImpl::createQName(
    const String& aNamespace,
    const String& aPrefix,
    const String& aLocalname)
{
  zstring const &lNamespace = Unmarshaller::getInternalString( aNamespace );
  zstring const &lPrefix = Unmarshaller::getInternalString( aPrefix );
  zstring const &lLocalname = Unmarshaller::getInternalString( aLocalname );

  if (!GenericCast::instance()->castableToNCName(lLocalname.c_str()))
  {
    RAISE_ERROR_NO_LOC(err::FORG0001,
    ERROR_PARAMS(ZED(FORG0001_LocalNotNCName_2), lLocalname));
  }

  if (lPrefix.size() && !GenericCast::instance()->castableToNCName(lPrefix.c_str()))
  {
    RAISE_ERROR_NO_LOC(err::FORG0001,
    ERROR_PARAMS(ZED(FORG0001_PrefixNotNCName_2), lPrefix));
  }

  store::Item_t lItem;
  theItemFactory->createQName(lItem, lNamespace, lPrefix, lLocalname);
  return &*lItem;
}
Exemplo n.º 8
0
void dynamic_context::get_variable(
    ulong varid,
    const store::Item_t& varname,
    const QueryLoc& loc,
    store::Item_t& itemValue,
    store::TempSeq_t& seqValue) const
{
  itemValue = NULL;
  seqValue = NULL;

  if (varid >= theVarValues.size() ||
      theVarValues[varid].theState == VarValue::undeclared)
  {
    zstring varName = static_context::var_name(varname.getp());

    if (varid >= theVarValues.size() ||
        theVarValues[varid].theIsExternalOrLocal ||
        (varid > 0 && varid < MAX_IDVARS_RESERVED))
    {
      RAISE_ERROR(err::XPDY0002, loc,
      ERROR_PARAMS(ZED(XPDY0002_VariableUndeclared_2), varName));
    }
    else
    {
      RAISE_ERROR(err::XQDY0054, loc, ERROR_PARAMS(varName));
    }
  }

  const VarValue& var = theVarValues[varid];

  if (var.theState == VarValue::declared)
  {
    zstring varName = static_context::var_name(varname.getp());

    if (var.theIsExternalOrLocal)
    {
      RAISE_ERROR(err::XPDY0002, loc,
      ERROR_PARAMS(ZED(XPDY0002_VariableHasNoValue_2), varName));
    }
    else
    {
      RAISE_ERROR(err::XQDY0054, loc, ERROR_PARAMS(varName));
    }
  }

  if (var.theState == VarValue::item)
    itemValue = var.theValue.item;
  else
    seqValue = var.theValue.temp_seq;
}
Exemplo n.º 9
0
/*******************************************************************************
  declare updating function
  put($uri as xs:string, $doc as xs:document-node()) as empty-sequence()
********************************************************************************/
bool PutDocumentIterator::nextImpl(
    store::Item_t& result,
    PlanState& aPlanState) const
{
  zstring       lRetrievedUriString;
  zstring       lResolvedUriString;
  store::Item_t lUri;
  store::Item_t lDoc;
  store::Item_t lResolvedUriItem;
  std::unique_ptr<store::PUL> lPul;

  PlanIteratorState* state;
  DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);

  consumeNext(lUri, theChildren[0].getp(), aPlanState);

  // absolutize retrieved uri
  try
  {
    lUri->getStringValue2(lRetrievedUriString);
    lResolvedUriString = theSctx->resolve_relative_uri(lRetrievedUriString, true);
  }
  catch (ZorbaException const&)
  {
    RAISE_ERROR(err::FODC0004, loc,
    ERROR_PARAMS(lResolvedUriString, ZED(NoResolveRelativeURI)));
  }

  // check if document already exists in the store
  if (GENV_STORE.getDocument(lResolvedUriString) != NULL)
  {
    RAISE_ERROR(zerr::ZAPI0020_DOCUMENT_ALREADY_EXISTS, loc,
    ERROR_PARAMS(lResolvedUriString));
  }

  // create the pul and add the primitive
  GENV_ITEMFACTORY->createAnyURI(lResolvedUriItem, lResolvedUriString);

  lPul.reset(GENV_ITEMFACTORY->createPendingUpdateList());

  consumeNext(lDoc, theChildren[1].getp(), aPlanState);
  lPul->addCreateDocument(&loc, lResolvedUriItem, lDoc);

  result = lPul.release();
  STACK_PUSH(result != NULL, state);

  STACK_END(state);
}
Exemplo n.º 10
0
void dynamic_context::set_implicit_timezone(long tzone_seconds)
{
  if (tzone_seconds > 14*3600 || tzone_seconds < -14*3600)
    throw XQUERY_EXCEPTION(err::FODT0003, ERROR_PARAMS(tzone_seconds));

  theTimezone = tzone_seconds;
}
Exemplo n.º 11
0
/*******************************************************************************
  declare function
  is-available-document($uri as xs:string) as xs:boolean
********************************************************************************/
bool IsAvailableDocumentIterator::nextImpl(
    store::Item_t& result,
    PlanState& aPlanState) const
{
  zstring       lRetrievedUriString;
  zstring       lResolvedUriString;
  store::Item_t lUri;

  PlanIteratorState* state;
  DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);

  consumeNext(lUri, theChildren[0].getp(), aPlanState);

  // absolutize retrieved uri
  try
  {
    lUri->getStringValue2(lRetrievedUriString);
    lResolvedUriString = theSctx->resolve_relative_uri(lRetrievedUriString, true);
  }
  catch (ZorbaException const&)
  {
    RAISE_ERROR(err::FODC0004, loc,
    ERROR_PARAMS(lResolvedUriString, ZED(NoResolveRelativeURI)));
  }

  // check if document exists in the store
  GENV_ITEMFACTORY->
  createBoolean(result, GENV_STORE.getDocument(lResolvedUriString) != NULL);

  STACK_PUSH(true, state);

  STACK_END(state);
}
Exemplo n.º 12
0
void relpath_expr::compute_scripting_kind()
{
  theScriptingKind = UNKNOWN_SCRIPTING_KIND;

  for (unsigned i = 0; i < size(); ++i)
  {
    expr* step = theSteps[i];

    if (step->is_updating())
    {
      throw XQUERY_EXCEPTION(err::XUST0001,
                             ERROR_PARAMS(ZED(XUST0001_Generic)),
                             ERROR_LOC(get_loc()));
    }

    theScriptingKind |= step->get_scripting_detail();
  }

  theScriptingKind &= ~VACUOUS_EXPR;

  if (is_sequential(theScriptingKind))
    theScriptingKind &= ~SIMPLE_EXPR;

  checkScriptingKind();
}
Exemplo n.º 13
0
Resource*
FileURLResolver::resolveURL
(zstring const& aUrl, EntityData const* aEntityData)
{
  switch ( aEntityData->getKind() ) {
    case EntityData::COLLECTION:
#ifndef ZORBA_NO_FULL_TEXT
    case EntityData::THESAURUS:
#endif /* ZORBA_NO_FULL_TEXT */
      return nullptr;
    default:
      break;
  }

  uri::scheme lScheme = uri::get_scheme(aUrl);
  if (lScheme != uri::file) {
    return NULL;
  }
  try {
    std::string lPath( fs::normalize_path(aUrl) );
    if (fs::get_type(lPath) == fs::file) {
      std::ifstream* lStream = new std::ifstream(lPath.c_str());
      return new StreamResource(
          lStream, &fileStreamReleaser, "", true /* seekable */);
    }
    return NULL;
  }
  catch ( std::invalid_argument const &e ) {
    throw XQUERY_EXCEPTION( err::XPTY0004, ERROR_PARAMS( e.what() ) );
  }
}
Exemplo n.º 14
0
void AnnotationList::checkLiterals(DeclarationKind k, const QueryLoc& loc) const
{
  for (Annotations::const_iterator ite = theAnnotationList.begin();
       ite != theAnnotationList.end();
       ++ite)
  {
    AnnotationInternal* lAnn = *ite;
    switch (lAnn->getId())
    {
      case AnnotationInternal::zann_exclude_from_cache_key:
      case AnnotationInternal::zann_compare_with_deep_equal:
        //One or more integers
        if (!lAnn->getNumLiterals())
        {
          RAISE_ERROR(zerr::ZXQP0062_INVALID_ANNOTATION_LITERALS_NUMBER, loc,
              ERROR_PARAMS(
                  AnnotationInternal::lookup(lAnn->getId())->getStringValue(),
                  ZED(ZXQP0062_ONE_OR_MORE_LITERALS)));
        }
        for (csize i=0; i<lAnn->getNumLiterals(); ++i)
          checkLiteralType(lAnn, lAnn->getLiteral(i), store::XS_INTEGER, loc);
        break;
      default:
        break;
    }
  }
}
Exemplo n.º 15
0
void SimpleLazyTempSeq::getItem(xs_integer position, store::Item_t& result)
{
  xs_long pos;
  try 
  {
    pos = to_xs_long(position);
  }
  catch (std::range_error const&)
  {
    RAISE_ERROR_NO_LOC(zerr::ZSTR0060_RANGE_EXCEPTION,
    ERROR_PARAMS(position,ZED(ZSTR0060_ForSequence)));
  }

  ZORBA_ASSERT(pos > thePurgedUpTo);

  std::vector<store::Item*>::size_type numItemsToBuffer = pos - thePurgedUpTo;

  while (!theMatFinished && theItems.size() <  numItemsToBuffer) 
  {
    matNextItem();
  }

  if (theItems.size() >= numItemsToBuffer)
  {
    std::vector<store::Item*>::size_type sPos = static_cast<std::vector<store::Item*>::size_type>(pos - thePurgedUpTo - 1);
    result = theItems[sPos];
  }
  else 
  {
    result = NULL;
  }
}
Exemplo n.º 16
0
ModuleInfo* XQueryCompiler::parseInfo(
    std::istream& aXQuery,
    const zstring& aFileName)
{
  parsenode_t lParseNode = parse(aXQuery, aFileName);

  if (typeid (*lParseNode) == typeid (ParseErrorNode))
  {
    ParseErrorNode* pen = static_cast<ParseErrorNode *>(lParseNode.getp());
    throw XQUERY_EXCEPTION_VAR(pen->err, 
    ERROR_PARAMS(pen->msg), ERROR_LOC(pen->get_location()));
  }

  LibraryModule* lLibModule = dynamic_cast<LibraryModule*>(lParseNode.getp());

  zstring lTargetNamespace;

  if (lLibModule)
  {
    ModuleDecl* lDecl = lLibModule->get_decl().getp();
    lTargetNamespace = lDecl->get_target_namespace();
  }

  return new ModuleInfoImpl(lTargetNamespace);
}
Exemplo n.º 17
0
void SimpleLazyTempSeq::purgeUpTo(xs_integer position)
{
  xs_long pos;
  try 
  {
    pos = to_xs_long(position);
  }
  catch (std::range_error const&)
  {
    throw ZORBA_EXCEPTION(zerr::ZSTR0060_RANGE_EXCEPTION,
    ERROR_PARAMS(position,ZED(ZSTR0060_ForSequence)));
  }

  ZORBA_ASSERT(pos >= thePurgedUpTo);
  ZORBA_ASSERT(static_cast<std::vector<store::Item*>::size_type>(pos - thePurgedUpTo) <= theItems.size());

  std::vector<store::Item*>::iterator ite = theItems.begin();
  std::vector<store::Item*>::iterator end = theItems.begin() + static_cast<std::vector<store::Item*>::size_type>(pos - thePurgedUpTo);
  for (; ite != end; ++ite)
  {
    (*ite)->removeReference();
  }

  theItems.erase(theItems.begin(), end);

  thePurgedUpTo = pos;
}
Exemplo n.º 18
0
bool OpNumericUnaryIterator::nextImpl(store::Item_t& result, PlanState& planState) const
{
  store::Item_t item;
  store::SchemaTypeCode type;

  const TypeManager* tm = theSctx->get_typemanager();

  PlanIteratorState* state;
  DEFAULT_STACK_INIT(PlanIteratorState, state, planState);

  if (consumeNext(item, theChild.getp(), planState ))
  {
    assert(item->isAtomic());

    type = item->getTypeCode();

    if (type == store::XS_UNTYPED_ATOMIC)
    {
      GenericCast::castToBuiltinAtomic(item, item, store::XS_DOUBLE, NULL, loc);
      type = store::XS_DOUBLE;
    }
    
    // TODO Optimizations (e.g. if item has already the correct type and value,
    // it does not have to be created newly)
    if (TypeOps::is_subtype(type, store::XS_DOUBLE))
    {
      GENV_ITEMFACTORY->
      createDouble(result,
                   (thePlus ? item->getDoubleValue() : -item->getDoubleValue()));
    }
    else if (TypeOps::is_subtype(type, store::XS_FLOAT))
    {
      GENV_ITEMFACTORY->
      createFloat(result,
                  (thePlus ? item->getFloatValue() : -item->getFloatValue()));
    }
    else if (TypeOps::is_subtype(type, store::XS_INTEGER))
    {
      GENV_ITEMFACTORY->
      createInteger(result,
                    (thePlus ? item->getIntegerValue() : -item->getIntegerValue()));
    }
    else if (TypeOps::is_subtype(type, store::XS_DECIMAL))
    {
      GENV_ITEMFACTORY->
      createDecimal(result,
                   (thePlus ? item->getDecimalValue() : -item->getDecimalValue()));
    }
    else
    {
      xqtref_t type = tm->create_value_type(item);
      RAISE_ERROR(err::XPTY0004, loc,
      ERROR_PARAMS(ZED(BadTypeFor_23), type->toSchemaString(), ZED(UnaryArithOp)));
    }
    
    STACK_PUSH(true, state);
  }

  STACK_END(state);
}
Exemplo n.º 19
0
static void x2j_children( store::Item_t const &parent,
                          vector<store::Item_t> *children ) {
  ZORBA_ASSERT( children );
  store::Iterator_t i( parent->getChildren() );
  i->open();
  store::Item_t child_item, temp_item;
  while ( i->next( child_item ) ) {
    if ( !x2j_map_atomic( child_item, &temp_item ) ) {
      if ( !child_item->isNode() )
        throw XQUERY_EXCEPTION(
          zerr::ZJ2X0001_JSONML_ARRAY_BAD_JSON,
          ERROR_PARAMS( ZED( ZJ2X0001_BadElement ), child_item->getKind() )
        );
      switch ( child_item->getNodeKind() ) {
        case store::StoreConsts::elementNode:
          x2j_element( child_item, &temp_item );
          break;
        case store::StoreConsts::textNode: {
          zstring s( child_item->getStringValue() );
          GENV_ITEMFACTORY->createString( temp_item, s );
          break;
        }
        default:
          continue;
      } // switch
    } // if
    children->push_back( temp_item );
  } // while
  i->close();
}
Exemplo n.º 20
0
/*******************************************************************************
  14.9.2 fn:parse-xml-fragment
********************************************************************************/
bool FnParseXmlFragmentIterator::nextImpl(
    store::Item_t& result,
    PlanState& planState) const
{
  zstring docString;

  FnParseXmlFragmentIteratorState* state;
  DEFAULT_STACK_INIT(FnParseXmlFragmentIteratorState, state, planState);

  if (consumeNext(result, theChildren[0].getp(), planState))
  {
    if (result->isStreamable())
    {
      state->theFragmentStream.theStream = &result->getStream();
    }
    else
    {
      result->getStringValue2(docString);
      state->theFragmentStream.theIss = new std::istringstream(docString.c_str());
      state->theFragmentStream.theStream = state->theFragmentStream.theIss;
    }

    state->theProperties.setBaseUri(theSctx->get_base_uri());
    state->theProperties.setParseExternalParsedEntity(true);
    state->theProperties.setStoreDocument(false);

    state->baseUri = state->theProperties.getBaseUri();    

    // create only one document node holding all fragment nodes
    state->theFragmentStream.only_one_doc_node = 1;
       
    try
    {
      result = GENV.getStore().loadDocument(state->baseUri,
                                            state->docUri,
                                            state->theFragmentStream,
                                            state->theProperties);
    }
    catch ( ZorbaException const &e )
    {
      if ( !state->theProperties.getNoError() )
      {
        XQueryException xe(
          XQUERY_EXCEPTION(err::FODC0006,
          ERROR_PARAMS( "fn:parse-xml-fragment()", e.what() ),
          ERROR_LOC( loc )));

        set_data( xe, e );
        throw xe;
      }
      result = nullptr;
    }

    if (result != NULL)
      STACK_PUSH(true, state);
  } // if 

  STACK_END(state);
}
Exemplo n.º 21
0
void AnnotationList::checkRequiredDeclarations(
    RuleBitSet declaredAnn,
    DeclarationKind declKind,
    const QueryLoc& loc) const
{
  // check rules
  std::vector<AnnotationRequirement>::const_iterator ite = AnnotationInternal::theRequiredRuleSet.begin();
  std::vector<AnnotationRequirement>::const_iterator end = AnnotationInternal::theRequiredRuleSet.end();

  for (; ite != end; ++ite)
  {
    const AnnotationId& lCurrAnn = ite->first;
    const RuleBitSet& lCurrSet = ite->second;

    if (declaredAnn.test(lCurrAnn) && (declaredAnn & lCurrSet).count() == 0)
    {
      // build error string to return set of required annotations
      std::ostringstream lProblems;
      for (csize i = 0, j = 0; i < AnnotationInternal::zann_end; ++i)
      {
        if (lCurrSet.test(i))
        {
          AnnotationId id = static_cast<AnnotationId>(i);
          lProblems << AnnotationInternal::lookup(id)->getStringValue()
                    << ((j == lCurrSet.count() - 1) ? "" : ", ");
          ++j;
        }
      }

      if (declKind == var_decl)
      {
        RAISE_ERROR(err::XQST0116, loc,
        ERROR_PARAMS(ZED(XQST0116_Requirement),
            AnnotationInternal::lookup(lCurrAnn)->getStringValue(),
            lProblems.str()));
      }
      else
      {
        RAISE_ERROR(err::XQST0106, loc,
        ERROR_PARAMS(ZED(XQST0106_Requirement),
            AnnotationInternal::lookup(lCurrAnn)->getStringValue(),
            lProblems.str()));
      }
    }
  }
}
Exemplo n.º 22
0
/*******************************************************************************
  declare updating function
  remove($uri as xs:string) as empty-sequence()
********************************************************************************/
bool RemoveDocumentIterator::nextImpl(
    store::Item_t& result,
    PlanState& aPlanState) const
{
  zstring       lRetrievedUriString;
  zstring       lResolvedUriString;
  store::Item_t lUri;
  store::Item_t lResolvedUriItem;
  store::PUL_t lPul;

  PlanIteratorState* state;
  DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);

  consumeNext(lUri, theChildren[0].getp(), aPlanState);

  // absolutize retrieved uri
  try
  {
    lUri->getStringValue2(lRetrievedUriString);
    lResolvedUriString = theSctx->resolve_relative_uri(lRetrievedUriString, true);
  }
  catch (ZorbaException const&)
  {
    RAISE_ERROR(err::FODC0004, loc,
    ERROR_PARAMS(lResolvedUriString, ZED(NoResolveRelativeURI)));
  }

  // check if document exists in the store
  if (GENV_STORE.getDocument(lResolvedUriString) == NULL)
  {
    RAISE_ERROR(zerr::ZXQD0002_DOCUMENT_NOT_VALID, loc,
    ERROR_PARAMS(lResolvedUriString, ZED(NoURIInStore)));
  }

  // create the pul and add the primitive
  GENV_ITEMFACTORY->createAnyURI(lResolvedUriItem, lResolvedUriString);

  lPul = GENV_ITEMFACTORY->createPendingUpdateList();

  lPul->addDeleteDocument(&loc, lResolvedUriItem);

  result.transfer(lPul);
  STACK_PUSH(result != NULL, state);

  STACK_END(state);
}
Exemplo n.º 23
0
void AnnotationList::checkConflictingDeclarations(
    RuleBitSet currAnn,
    DeclarationKind declKind,
    const QueryLoc& loc) const
{
  // check rules
  std::vector<RuleBitSet>::const_iterator ite = AnnotationInternal::theConflictRuleSet.begin();
  std::vector<RuleBitSet>::const_iterator end = AnnotationInternal::theConflictRuleSet.end();

  for (; ite != end; ++ite)
  {
    const RuleBitSet& lCurrSet = *ite;

    if ((currAnn & lCurrSet).count() > 1)
    {
      // build error string to return set of conflicting annotations
      std::ostringstream lProblems;
      for (csize i = 0, j = 0; i < AnnotationInternal::zann_end; ++i)
      {
        if (lCurrSet.test(i))
        {
          AnnotationId id = static_cast<AnnotationId>(i);

          lProblems << AnnotationInternal::lookup(id)->getStringValue()
                    << ((j == (currAnn & lCurrSet).count() - 1) ? "" : ", ");
          ++j;
        }
      }

      if (declKind == var_decl)
      {
        RAISE_ERROR(err::XQST0116, loc,
        ERROR_PARAMS(ZED(XQST0116_Conflicting), lProblems.str()));
      }
      else
      {
        RAISE_ERROR(err::XQST0106, loc,
        ERROR_PARAMS(ZED(XQST0106_Conflicting), lProblems.str()));
      }
    }
  }
}
Exemplo n.º 24
0
void ArithOperationsCommons::createError(
    const TypeManager* tm,
    const char* aOp, 
    const QueryLoc* aLoc, 
    store::SchemaTypeCode aType0,
    store::SchemaTypeCode aType1)
{
  xqtref_t t0 = tm->create_builtin_atomic_type(aType0,SequenceType::QUANT_ONE);
  xqtref_t t1 = tm->create_builtin_atomic_type(aType1,SequenceType::QUANT_ONE);

  RAISE_ERROR(err::XPTY0004, aLoc,
  ERROR_PARAMS(ZED(OperationNotPossibleWithTypes_234), aOp, *t0, *t1 ));
}
Exemplo n.º 25
0
/******************************************************************************
  Create a dummy main module to wrap a library module.
******************************************************************************/
parsenode_t XQueryCompiler::createMainModule(
    parsenode_t aLibraryModule,
    std::istream& aXQuery,
    const zstring& aFileName)
{
  //get the namespace from the LibraryModule
  LibraryModule* mod_ast = dynamic_cast<LibraryModule *>(&*aLibraryModule);
  if (!mod_ast)
    throw ZORBA_EXCEPTION(zerr::ZAPI0002_XQUERY_COMPILATION_FAILED,
    ERROR_PARAMS(ZED(BadLibraryModule)));

  const zstring& lib_namespace = mod_ast->get_decl()->get_target_namespace();

  URI lURI(lib_namespace);
  if(!lURI.is_absolute())
  {
    throw XQUERY_EXCEPTION(err::XQST0046,
    ERROR_PARAMS(lURI.toString(), ZED(MustBeAbsoluteURI)),
      ERROR_LOC(mod_ast->get_decl()->get_location()));
  }

  // Set up the original query stream as the result of resolving the
  // library module's URI
  aXQuery.clear();
  aXQuery.seekg(0);

  FakeLibraryModuleURLResolver* aFakeResolver =
    new FakeLibraryModuleURLResolver(aFileName, aXQuery);

  theCompilerCB->theRootSctx->add_url_resolver(aFakeResolver);

  // create a dummy main module and parse it
  std::stringstream lDocStream;
  zstring tmp;
  zorba::xml::escape(lib_namespace, &tmp);
  lDocStream << "import module namespace m = '" << tmp << "'; 1";
  return parse(lDocStream, aFileName);
}
Exemplo n.º 26
0
Item ItemFactoryImpl::createNCName(const String& aValue)
{
  zstring lString = Unmarshaller::getInternalString(aValue);

  if (!GenericCast::instance()->castableToNCName(lString.c_str()))
  {
    RAISE_ERROR_NO_LOC(err::FORG0001,
    ERROR_PARAMS(ZED(FORG0001_NameNotNCName_2), lString));
  }

  store::Item_t lItem;
  theItemFactory->createNCName(lItem, lString);
  return &*lItem;
}
Exemplo n.º 27
0
/*******************************************************************************
  declare function
  document($uri as xs:string) as document-node()
********************************************************************************/
bool RetrieveDocumentIterator::nextImpl(
    store::Item_t& result,
    PlanState& aPlanState) const
{
  zstring       lRetrievedUriString;
  zstring       lResolvedUriString;
  store::Item_t lUri;
  store::Item_t lResolvedUriItem;

  PlanIteratorState* state;
  DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState);

  consumeNext(lUri, theChildren[0].getp(), aPlanState);

  // absolutize retrieved uri
  try
  {
    lUri->getStringValue2(lRetrievedUriString);
    lResolvedUriString = theSctx->resolve_relative_uri(lRetrievedUriString, true);
  }
  catch (ZorbaException const&)
  {
    RAISE_ERROR(err::FODC0004, loc,
    ERROR_PARAMS(lResolvedUriString, ZED( NoResolveRelativeURI)));
  }

  // check if document exists in the store
  if ((result = GENV_STORE.getDocument(lResolvedUriString)) == NULL)
  {
    RAISE_ERROR(zerr::ZXQD0002_DOCUMENT_NOT_VALID, loc,
    ERROR_PARAMS(lResolvedUriString, ZED( NoURIInStore)));
  }

  STACK_PUSH(true, state);

  STACK_END(state);
}
Exemplo n.º 28
0
bool IntegerDivideOperation::compute<store::XS_DOUBLE,store::XS_DOUBLE>(
    store::Item_t& result,
    dynamic_context* /* dctx */,
    const TypeManager* /* tm */,
    const QueryLoc* loc,
    const store::Item* i0,
    const store::Item* i1 )
{
  xs_double d0 = i0->getDoubleValue();
  xs_double d1 = i1->getDoubleValue();

  if ( d1 == numeric_consts<xs_double>::zero() )
  {
    throw XQUERY_EXCEPTION( err::FOAR0001, ERROR_LOC( loc ) );
  }

  if (i0->isNaN() || i1->isNaN()) 
  {
    throw XQUERY_EXCEPTION(
      err::FOAR0002, ERROR_PARAMS( ZED( DivisionNoNaN ) ), ERROR_LOC( loc )
    );
  }
  if (i0->isPosOrNegInf()) 
  {
    throw XQUERY_EXCEPTION(
      err::FOAR0002, ERROR_PARAMS( ZED( DivisionNoINF ) ), ERROR_LOC( loc )
    );
  }

  if (i0->isPosOrNegInf()) {
    // idiv with +-INF divisor has 0 as result
    return GENV_ITEMFACTORY->createInteger(result, numeric_consts<xs_integer>::zero());
  }

  xs_integer const lInteger( d0 / d1 );
  return GENV_ITEMFACTORY->createInteger (result,  lInteger );
}
Exemplo n.º 29
0
void dynamic_context::set_variable(
    ulong varid,
    const store::Item_t& varname,
    const QueryLoc& loc,
    store::Iterator_t& valueIter)
{
  if (varid >= theVarValues.size() ||
      theVarValues[varid].theState == VarValue::undeclared)
  {
    RAISE_ERROR(err::XPDY0002, loc,
    ERROR_PARAMS(ZED(XPDY0002_VariableUndeclared_2), varname->getStringValue()));
  }

  valueIter->open();

  // For now, use eager eval because the assignment expression may reference
  // the variable itself, and the current value of the variable is overwriten
  // here by this temp sequence. TODO: use lazy eval if we know the the
  // assignment expression does not reference the variable itself.
  store::TempSeq_t seq = GENV_STORE.createTempSeq(valueIter, false); // no lazy eval

  valueIter->close();

  VarValue& var = theVarValues[varid];

  // variables can be set multiple times, so we need to make sure to remove
  // previously set temp sequences
  if (var.theState == VarValue::item)
  {
    assert(var.theValue.item != NULL);
    var.theValue.item->removeReference();
  }
  else if (var.theState == VarValue::temp_seq)
  {
    assert(var.theValue.temp_seq != NULL);
    RCHelper::removeReference(var.theValue.temp_seq);
  }
  else if (var.theState == VarValue::declared)
  {
    assert(var.theValue.item == NULL);
  }
  else
  {
    ZORBA_ASSERT(false);
  }

  var.theState = VarValue::temp_seq;
  var.theValue.temp_seq = seq.release();
}
Exemplo n.º 30
0
void json_to_xml( store::Item_t const &json_item, store::Item_t *xml_item ) {
  ZORBA_ASSERT( xml_item );
  switch ( json_item->getKind() ) {
    case store::Item::ARRAY:
      *xml_item = j2x_array( json_item, nullptr );
      break;
    case store::Item::OBJECT:
      throw XQUERY_EXCEPTION(
        zerr::ZJ2X0001_JSONML_ARRAY_BAD_JSON,
        ERROR_PARAMS( ZED( ZJ2X0001_ArrayRequired ) )
      );
    default:
      ZORBA_ASSERT( false );
  }
}