示例#1
0
static void get_options( store::Item_t const &options_object,
                         options_type *options ) {
  ZORBA_ASSERT( options_object->getKind() == store::Item::OBJECT );
  store::Iterator_t i( options_object->getObjectKeys() );
  i->open();
  store::Item_t opt_key;
  while ( i->next( opt_key ) ) {
    zstring const opt_name( opt_key->getStringValue() );
    store::Item_t const opt_value( options_object->getObjectValue( opt_key ) );
    (*options)[ opt_name ] = opt_value->getStringValue();
  }
  i->close();
}
示例#2
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();
}
示例#3
0
bool x2j_map_atomic( store::Item_t const &xml_item, store::Item_t *json_item ) {
  if ( xml_item->isAtomic() ) {
    switch ( xml_item->getTypeCode() ) {
      case store::JS_NULL:
      case store::XS_BOOLEAN:
      case store::XS_BYTE:
      case store::XS_DECIMAL:
      case store::XS_DOUBLE:
      case store::XS_ENTITY:
      case store::XS_FLOAT:
      case store::XS_ID:
      case store::XS_IDREF:
      case store::XS_INT:
      case store::XS_INTEGER:
      case store::XS_LONG:
      case store::XS_NAME:
      case store::XS_NCNAME:
      case store::XS_NEGATIVE_INTEGER:
      case store::XS_NMTOKEN:
      case store::XS_NON_NEGATIVE_INTEGER:
      case store::XS_NON_POSITIVE_INTEGER:
      case store::XS_NORMALIZED_STRING:
      case store::XS_POSITIVE_INTEGER:
      case store::XS_SHORT:
      case store::XS_STRING:
      case store::XS_TOKEN:
      case store::XS_UNSIGNED_BYTE:
      case store::XS_UNSIGNED_INT:
      case store::XS_UNSIGNED_LONG:
      case store::XS_UNSIGNED_SHORT:
        *json_item = xml_item;
        break;
      default:
        zstring s( xml_item->getStringValue() );
        GENV_ITEMFACTORY->createString( *json_item, s );
        break;
    } // switch
    return true;
  } // if
  return false;
}
示例#4
0
void dynamic_context::set_variable(
    ulong varid,
    const store::Item_t& varname,
    const QueryLoc& loc,
    store::Item_t& valueItem)
{
  if (varid >= theVarValues.size() ||
      theVarValues[varid].theState == VarValue::undeclared)
  {
    RAISE_ERROR(err::XPDY0002, loc,
    ERROR_PARAMS(ZED(XPDY0002_VariableUndeclared_2), varname->getStringValue()));
  }

  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::item;
  var.theValue.item = valueItem.release();
}
示例#5
0
void dynamic_context::unset_variable(
    ulong varid,
    const store::Item_t& varname,
    const QueryLoc& loc)
{
  if (varid >= theVarValues.size() ||
      theVarValues[varid].theState == VarValue::undeclared)
  {
    RAISE_ERROR(err::XPDY0002, loc,
    ERROR_PARAMS(ZED(XPDY0002_VariableUndeclared_2), varname->getStringValue()));
  }

  VarValue& var = theVarValues[varid];

  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::declared;
  var.theValue.item = NULL;
}
示例#6
0
bool MultiDynamicFnCallIterator::nextImpl(
    store::Item_t& result,
    PlanState& planState) const
{
  store::Item_t item;
  store::Item_t targetItem;
  FunctionItem* fnItem;
  zstring key;

  MultiDynamicFnCallIteratorState* state;

  DEFAULT_STACK_INIT(MultiDynamicFnCallIteratorState, state, planState);

  while (consumeNext(targetItem, theChild, planState))
  {
    if (targetItem->isFunction())
    {
      fnItem = static_cast<FunctionItem*>(targetItem.getp());

      if (fnItem->getArity() != 0)
      {
        RAISE_ERROR(err::XPTY0004, loc,
        ERROR_PARAMS("dynamic function invoked with incorrect number of arguments"));
      }

      state->thePlan = fnItem->getImplementation(planState.theCompilerCB);
      
      // must be opened after vars and params are set
      state->thePlan->open(planState, state->theUDFStateOffset);
      state->theIsOpen = true;

      while (consumeNext(result, state->thePlan, planState))
      {
        STACK_PUSH(true, state);
      }

      // Need to close here early in case the plan is completely consumed.
      // Otherwise, the plan would still be opened if destroyed from the
      // state's destructor.
      state->thePlan->close(planState);
      state->theIsOpen = false;
    } // if (targetItem->isFunction())

    else if (targetItem->isJSONItem())
    {
      if (targetItem->isObject())
      {
        if (!state->theKeysSet.get())
          state->theKeysSet.reset(new HashSet<zstring, HashMapZStringCmp>(64, false));

        state->theIterator = targetItem->getObjectKeys();

        state->theIterator->open();

        while (state->theIterator->next(result))
        {
          key = result->getStringValue();

          if (!state->theKeysSet->exists(key))
          {
            state->theKeysSet->insert(key);
            STACK_PUSH(true, state);
          }
        }
      }
      else
      {
        state->theIterator = targetItem->getArrayValues();

        state->theIterator->open();

        while (state->theIterator->next(result))
        {
          STACK_PUSH(true, state);
        }
      }

      state->theIterator->close();
    } // jsoniq item
#if 0
    else if (theSctx->language_kind() == StaticContextConsts::language_kind_xquery)
    {
      xqtref_t type = theSctx->get_typemanager()->create_value_type(targetItem);

      RAISE_ERROR(err::XPTY0004, loc, 
      ERROR_PARAMS(ZED(XPTY0004_NoTypePromote_23),
                   type->toSchemaString(),
                   GENV_TYPESYSTEM.ANY_FUNCTION_TYPE_ONE->toSchemaString()));
    }
#endif
  }

  STACK_END(state);
};