bool CastableIterator::nextImpl(store::Item_t& result, PlanState& planState) const { bool res; store::Item_t item; TypeManager* tm = theSctx->get_typemanager(); PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); if (!consumeNext(item, theChild.getp(), planState)) { res = theAllowEmpty; } else { res = GenericCast::isCastable(item, theCastType, tm); if (consumeNext(item, theChild.getp(), planState)) { res = false; } } STACK_PUSH(GENV_ITEMFACTORY->createBoolean(result, res), state); STACK_END(state); }
bool DeleteIterator::nextImpl(store::Item_t& result, PlanState& aPlanState) const { store::Item_t target; std::unique_ptr<store::PUL> pul; PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, aPlanState); pul.reset(GENV_ITEMFACTORY->createPendingUpdateList()); while (consumeNext(target, theChild, aPlanState)) { if (!target->isNode()) throw XQUERY_EXCEPTION( err::XUTY0007, ERROR_LOC( loc ) ); areNodeModifiersViolated(theSctx, target, loc); pul->addDelete(&loc, target); } result = pul.release(); STACK_PUSH(true, state); STACK_END(state); }
bool IsFollowingSiblingPositionIterator::nextImpl(store::Item_t& result, PlanState& planState) const { store::Item_t lUriA; store::Item_t lUriB; PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); consumeNext(lUriA, theChildren[0].getp(), planState); consumeNext(lUriB, theChildren[1].getp(), planState); try { GENV_ITEMFACTORY->createBoolean(result, lUriA->isFollowingSibling(lUriB)); } catch (ZorbaException& e) { set_source(e, loc); throw; } STACK_PUSH(true,state); STACK_END (state); }
bool JSoundValidateIterator::nextImpl( store::Item_t &result, PlanState &plan_state ) const { bool cast = cast_default; store::Item_t jsd_item, type_item, json_item, options_item; PlanIteratorState *state; DEFAULT_STACK_INIT( PlanIteratorState, state, plan_state ); consumeNext( jsd_item, theChildren[0], plan_state ); consumeNext( type_item, theChildren[1], plan_state ); consumeNext( json_item, theChildren[2], plan_state ); consumeNext( options_item, theChildren[3], plan_state ); try { get_bool_opt( options_item, "cast-atomic-values", &cast ); jsound::schema const schema( jsd_item ); GENV_ITEMFACTORY->createBoolean( result, schema.validate( json_item, type_item->getStringValue(), cast ) ); } catch ( ZorbaException &e ) { set_source( e, loc, false ); throw; } STACK_PUSH( true, state ); STACK_END( state ); }
bool FunctionNameIterator::nextImpl( store::Item_t& r, PlanState& planState) const { store::Item_t lFItem; FunctionItem* lFunctionItem = 0; PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); consumeNext(lFItem, theChildren[0], planState); // function signature guarantees that ZORBA_ASSERT(lFItem->isFunction()); lFunctionItem = static_cast<FunctionItem*>(lFItem.getp()); if ((!lFunctionItem->isInline() || lFunctionItem->isCoercion()) && lFunctionItem->getFunctionName() && (lFunctionItem->getArity() == lFunctionItem->getStartArity())) { // non-inline function r = lFunctionItem->getFunctionName(); STACK_PUSH(true, state); } STACK_END(state); }
/******************************************************************************* 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); }
bool SeqValueIntersectIterator::nextImpl( store::Item_t &result, PlanState &plan_state ) const { XQPCollator *const coll = theSctx->get_default_collator( loc ); store::Item_t item; TypeManager *const tm = getTypeManager(); long tz; SeqValueIntersectIteratorState *state; DEFAULT_STACK_INIT( SeqValueIntersectIteratorState, state, plan_state ); tz = plan_state.theLocalDynCtx->get_implicit_timezone(); state->set_[0] = new_Item_set( tm, tz, coll, loc ); state->set_[1] = new_Item_set( tm, tz, coll, loc ); while ( consumeNext( item, theChildren[0], plan_state ) ) if ( state->set_[0]->insert( item.getp() ).second ) item->addReference(); while ( consumeNext( item, theChildren[1], plan_state ) ) if ( ztd::contains( *state->set_[0], item.getp() ) && state->set_[1]->insert( item.getp() ).second ) { item->addReference(); result = item; STACK_PUSH( true, state ); } delete_Item_set( state->set_[0] ); delete_Item_set( state->set_[1] ); STACK_END( state ); }
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); }
bool SpecificNumArithIterator<Operation, Type>::nextImpl( store::Item_t& result, PlanState& planState) const { bool res; store::Item_t n0; store::Item_t n1; PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); if (this->consumeNext(n0, this->theChild0.getp(), planState)) { if (this->consumeNext(n1, this->theChild1.getp(), planState)) { assert(n0->isAtomic()); assert(n1->isAtomic()); res = Operation::template computeSingleType<Type>(result, NULL, NULL, &this->loc, n0.getp(), n1.getp()); STACK_PUSH(res, state); } } STACK_END(state); }
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); }
bool NumArithIterator<Operation>::nextImpl( store::Item_t& result, PlanState& planState) const { bool res; store::Item_t n0; store::Item_t n1; PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); if (this->consumeNext(n0, this->theChild0.getp(), planState)) { if (this->consumeNext(n1, this->theChild1.getp(), planState)) { res = compute(result, planState.theLocalDynCtx, this->theSctx->get_typemanager(), this->loc, n0, n1); STACK_PUSH(res, state); } } STACK_END(state); }
bool JSONtoXMLInternal::nextImpl( store::Item_t& result, PlanState &planState ) const { store::Item_t item; options_type options; PlanIteratorState *state; DEFAULT_STACK_INIT( PlanIteratorState, state, planState ); ZORBA_ASSERT( theChildren.size() == 2 ); consumeNext( item, theChildren[1], planState ); get_options( item, &options ); consumeNext( item, theChildren[0], planState ); result = nullptr; { // local scope options_type::mapped_type const &format_opt = options[ "json-format" ]; ZORBA_ASSERT( !format_opt.empty() ); if ( format_opt == "Snelson" ) snelson::json_to_xml( item, &result ); else if ( format_opt == "JsonML" || format_opt == "JsonML-array" ) jsonml_array::json_to_xml( item, &result ); else if ( format_opt == "JsonML-object" ) jsonml_object::json_to_xml( item, &result ); else ZORBA_ASSERT( false ); } // local scope STACK_PUSH( !!result, state ); STACK_END( state ); }
bool ZorbaValidateInPlaceIterator::nextImpl(store::Item_t& result, PlanState& planState) const { store::Item_t node; PlanIteratorState* state; store::PUL_t pul; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); if (consumeNext(node, theChild.getp(), planState)) { // verify that if the element being revalidated is an element it is the root if (node->getNodeKind()==store::StoreConsts::elementNode && node->getParent() && node->getParent()->getNodeKind()!=store::StoreConsts::documentNode) throw XQUERY_EXCEPTION( zerr::ZAPI0090_CANNOT_VALIDATE_NON_ROOT, ERROR_LOC( loc ) ); pul = GENV_ITEMFACTORY->createPendingUpdateList(); pul->addRevalidate(&loc,node); result.transfer(pul); STACK_PUSH(true, state); } STACK_END(state); }
bool IfThenElseIterator::nextImpl(store::Item_t& result, PlanState& planState) const { IfThenElseIteratorState* state; DEFAULT_STACK_INIT(IfThenElseIteratorState, state, planState); if (theIsBooleanIter) { store::Item_t condResult; consumeNext ( condResult, theCondIter.getp(), planState ); state->theThenUsed = condResult->getBooleanValue(); } else { state->theThenUsed = FnBooleanIterator::effectiveBooleanValue(this->loc, planState, theCondIter); } while (true) { STACK_PUSH(consumeNext(result, (state->theThenUsed ? theThenIter.getp() : theElseIter.getp()), planState), state); } STACK_END(state); }
bool ForIterator::nextImpl(store::Item_t& aResult, PlanState& aPlanState) const { ForState* lState; store::Item_t lItem; DEFAULT_STACK_INIT(ForState, lState, aPlanState); while (consumeNext(aResult, theChild0, aPlanState)) { while (consumeNext(lItem, theChild1, aPlanState)) { bindVariables(lItem, theVarRefs, aPlanState); if (theHasPosVars) { store::Item_t lPosItem; GENV_ITEMFACTORY->createInteger(lPosItem, xs_integer(lState->incReturnPosition())); bindVariables(lPosItem, thePosVarRefs, aPlanState); } STACK_PUSH(true, lState); } lState->resetPosition(); theChild1->reset(aPlanState); } STACK_END(lState); }
/******************************************************************************* 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); }
bool ExitIterator::nextImpl(store::Item_t& result, PlanState& planState) const { PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); throw ExitException(new PlanIteratorWrapper(theChild, planState)); STACK_END(state); }
bool FlowCtlIterator::nextImpl(store::Item_t& result, PlanState& planState) const { PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); throw FlowCtlException(act); STACK_END(state); }
bool SingletonIterator::nextImpl(store::Item_t& result, PlanState& planState) const { PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); result = theValue; STACK_PUSH ( result != NULL, state ); STACK_END (state); }
bool PromoteIterator::nextImpl(store::Item_t& result, PlanState& planState) const { store::Item_t item; store::Item_t temp; const TypeManager* tm = theSctx->get_typemanager(); PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); if (!consumeNext(item, theChild.getp(), planState)) { if (theQuantifier == SequenceType::QUANT_PLUS || theQuantifier == SequenceType::QUANT_ONE) { raiseError("empty-sequence()"); } } else if (theQuantifier == SequenceType::QUANT_QUESTION || theQuantifier == SequenceType::QUANT_ONE) { if (consumeNext(temp, theChild.getp(), planState)) { raiseError("sequence of more than one item"); } // catch exceptions to add/change the error location if (! GenericCast::promote(result, item, thePromoteType, &theNsCtx, tm, loc)) { zstring valueType = tm->create_value_type(item)->toSchemaString(); raiseError(valueType); } STACK_PUSH(true, state); } else { do { if (! GenericCast::promote(result, item, thePromoteType, &theNsCtx, tm, loc)) { zstring valueType = tm->create_value_type(item)->toSchemaString(); raiseError(valueType); } else { STACK_PUSH(true, state); } } while (consumeNext(item, theChild.getp(), planState)); } STACK_END(state); }
bool NodePositionIterator::nextImpl(store::Item_t& result, PlanState& planState) const { bool valid; store::Item_t inNode; PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); valid = consumeNext(inNode, theChildren[0], planState); assert(valid); STACK_PUSH(GENV_STORE.getStructuralInformation(result, inNode), state); STACK_END(state); }
/******************************************************************************* 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); }
bool PlanIterator::count(store::Item_t& result, PlanState& planState) const { store::Item_t item; xs_integer count(0); PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); while (consumeNext(item, this, planState)) { ++count; } STACK_PUSH(GENV_ITEMFACTORY->createInteger(result, xs_integer(count)), state); STACK_END(state); }
/******************************************************************************* 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); }
bool ZorbaSchemaTypeIterator::nextImpl(store::Item_t& result, PlanState& planState) const { store::Item_t item; PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); if (consumeNext(item, theChildren[0].getp(), planState)) { result = item->getType(); if ( result ) STACK_PUSH(true, state ); } STACK_END(state); }
bool LoopIterator::nextImpl(store::Item_t& result, PlanState& planState) const { bool lBreakLoop = false; PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); while (!lBreakLoop) { try { while (! consumeNext(result, theChild, planState)) { // bugfix: removed a goto in case // planState.theHasToQuit was true // this should not be needed because // the FlowCtlException::INTERRUPT // exception is rethrown below theChild->reset(planState); } } catch (FlowCtlException &e) { switch (e.act) { case FlowCtlException::BREAK: lBreakLoop = true; break; case FlowCtlException::CONTINUE: theChild->reset(planState); continue; default: throw; } } if (!lBreakLoop) { STACK_PUSH(true, state); } } STACK_END(state); }
bool AvailableDocumentsIterator::nextImpl( store::Item_t& result, PlanState& aPlanState) const { AvailableDocumentsIteratorState* state; DEFAULT_STACK_INIT(AvailableDocumentsIteratorState, state, aPlanState); state->theNameIterator = GENV_STORE.getDocumentNames(); state->theNameIterator->open(); while (state->theNameIterator->next(result)) { STACK_PUSH( true, state); } STACK_PUSH(false, state); STACK_END(state); }
bool ZorbaIsValidatedIterator::nextImpl(store::Item_t& result, PlanState& planState) const { store::Item_t item; store::ItemFactory* factory = GENV_ITEMFACTORY; PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); if (consumeNext(item, theChildren[0].getp(), planState)) { factory->createBoolean(result, item->isValidated()); STACK_PUSH(true, state); } STACK_END(state); }
bool XMLtoJSONInternal::nextImpl( store::Item_t& result, PlanState &planState ) const { store::Item_t xml_item; options_type options; PlanIteratorState *state; DEFAULT_STACK_INIT( PlanIteratorState, state, planState ); ZORBA_ASSERT( theChildren.size() == 2 ); consumeNext( xml_item, theChildren[1], planState ); get_options( xml_item, &options ); consumeNext( xml_item, theChildren[0], planState ); try { options_type::mapped_type const &format_opt = options[ "json-format" ]; ZORBA_ASSERT( !format_opt.empty() ); switch ( xml_item->getNodeKind() ) { case store::StoreConsts::elementNode: if ( format_opt == "Snelson" ) snelson::xml_to_json( xml_item, &result ); else if ( format_opt == "JsonML" || format_opt == "JsonML-array" ) jsonml_array::xml_to_json( xml_item, &result ); else if ( format_opt == "JsonML-object" ) jsonml_object::xml_to_json( xml_item, &result ); else ZORBA_ASSERT( false ); break; default: throw XQUERY_EXCEPTION( zerr::ZJSE0001_NOT_ELEMENT_NODE, ERROR_LOC( loc ) ); } // switch } catch ( ZorbaException &e ) { set_source( e, loc ); throw; } STACK_PUSH( !!result, state ); STACK_END( state ); }
bool OpDoubleUnaryIterator::nextImpl(store::Item_t& result, PlanState& planState) const { store::Item_t item; PlanIteratorState* state; DEFAULT_STACK_INIT(PlanIteratorState, state, planState); if (consumeNext(item, theChild.getp(), planState)) { assert(item->isAtomic()); GENV_ITEMFACTORY->createDouble(result, (thePlus ? item->getDoubleValue() : -item->getDoubleValue())); STACK_PUSH(true, state); } STACK_END(state); }