예제 #1
0
uint32_t deHashAttributes(
  const QueryLoc& loc,
  static_context* sctx,
  const store::Iterator_t& it,
  XQPCollator* collator,
  int timezone)
{
  uint32_t lHash = FNV_32_INIT;
  std::vector<uint32_t> lInnerHashes;
  store::Item_t attr;

  it->open();
  while (it->next(attr))
  {
    lInnerHashes.push_back(deHash(loc, sctx, attr, collator, timezone));
  }

  std::sort(lInnerHashes.begin(), lInnerHashes.end());
  for(std::vector<uint32_t>::iterator it = lInnerHashes.begin(); it != lInnerHashes.end(); ++it)
  {
    lHash = hashfun::h32(&(*it), sizeof(*it), lHash);
  }

  return lHash;
}
예제 #2
0
uint32_t deHashChildren(
    const QueryLoc& loc,
    static_context* sctx,
    const store::Iterator_t& it,
    XQPCollator* collator,
    int timezone)
{
  uint32_t lHash = FNV_32_INIT;
  uint32_t lInnerHash;
  store::Item_t child;
  it->open();

  while (it->next(child))
  {
    if (child->getNodeKind() == store::StoreConsts::piNode
        ||
        child->getNodeKind() == store::StoreConsts::commentNode)
      continue;

    lInnerHash = deHash(loc, sctx, child, collator, timezone);
    lHash = hashfun::h32(&lInnerHash, sizeof(lInnerHash), lHash);
  }

  return lHash;
}
예제 #3
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();
}
예제 #4
0
bool deepEqualChildren(
    const QueryLoc& loc,
    static_context* sctx,
    const store::Iterator_t& it1,
    const store::Iterator_t& it2,
    XQPCollator* collator,
    int timezone,
    bool raiseError)
{
  store::Item_t child1, child2;
  bool c1Valid, c2Valid;

  it1->open();
  it2->open();

  while (1)
  {
    while ((c1Valid = it1->next(child1)) &&
           (child1->getNodeKind() == store::StoreConsts::piNode ||
            child1->getNodeKind() == store::StoreConsts::commentNode))
      ;

    while ((c2Valid = it2->next(child2)) &&
            (child2->getNodeKind() == store::StoreConsts::piNode ||
             child2->getNodeKind() == store::StoreConsts::commentNode))
      ;

    if (!c1Valid && !c2Valid)
      return true;
    else if (!c1Valid || !c2Valid)
      return false;
    else if (!deepEqual(loc, sctx, child1, child2, collator, timezone, raiseError))
      return false;
  }

  return true;
}
예제 #5
0
void SchemaValidatorImpl::validateAttributes(
    EventSchemaValidator& schemaValidator,
    store::Iterator_t attributes)
{
  store::Item_t attribute;

  while ( attributes->next(attribute) )
  {
    ZORBA_ASSERT(attribute->isNode());
    ZORBA_ASSERT(attribute->getNodeKind() == store::StoreConsts::attributeNode);

    //cout << " vup    - attr: " << attribute->getNodeName()->getLocalName()->
    //  c_str() << "\n"; cout.flush();

    store::Item_t attName = attribute->getNodeName();
    schemaValidator.attr(attName, attribute->getStringValue());
  }
}
예제 #6
0
bool deepEqualAttributes(
  const QueryLoc& loc,
  static_context* sctx,
  const store::Iterator_t& it1,
  const store::Iterator_t& it2,
  XQPCollator* collator,
  int timezone,
  bool raiseError)
{
  store::Item_t child1, child2;
  int c1count = 0, c2count = 0;

  it1->open();
  it2->open();

  while (it1->next(child1))
  {
    c1count++;

    it2->reset();

    bool found = false;
    while (it2->next(child2))
    {
      if (deepEqual(loc, sctx, child1, child2, collator, timezone, raiseError))
      {
        found = true;
        break;
      }
    }

    if (!found)
      return false;
  }

  it2->reset();
  while (it2->next(child2))
    c2count++;

  if (c1count != c2count)
    return false;

  return true;
}
예제 #7
0
int SchemaValidatorImpl::processChildren(
    store::PUL* pul,
    namespace_context& nsCtx,
    TypeManager* typeManager,
    EventSchemaValidator& schemaValidator,
    store::Iterator_t children,
    std::vector<store::Item_t>& typedValues,
    const QueryLoc& loc)
{
  store::Item_t child;

  store::Item_t typeName;

  int noOfChildren = 0;
  while ( children->next(child) )
  {
    noOfChildren++;

    if ( child->isNode() )
    {
      //cout << " vup  - processChildren: " << child->getType()->getLocalName()
      //  ->c_str() << "\n"; cout.flush();

      switch ( child->getNodeKind() )
      {
      case store::StoreConsts::elementNode:
        processElement(pul, typeManager, schemaValidator, child, loc);
        break;

      case store::StoreConsts::attributeNode:
        ZORBA_ASSERT(false);
        break;

      case store::StoreConsts::documentNode:
        ZORBA_ASSERT(false);
        break;

      case store::StoreConsts::textNode:
      {
        //cout << " vup        - pC text: '" << child->getStringValue()->
        //  normalizeSpace()->str() << "'\n"; cout.flush();

        zstring childStringValue;
        child->getStringValue2(childStringValue);

        schemaValidator.text(childStringValue);

        store::Item_t typeQName = schemaValidator.getTypeQName();
        
        processTextValue(pul,
                         typeManager,
                         nsCtx,
                         typeQName,
                         childStringValue,
                         child,
                         typedValues,
                         loc);
      }
      break;

      case store::StoreConsts::piNode:
        //cout << " vup        - pi: " << child->getStringValue() << "\n"; cout.flush();
        // do nothing
        break;

      case store::StoreConsts::commentNode:
        //cout << " vup        - comment: " << child->getStringValue() << "\n"; cout.flush();
        // do nothing
        break;

      case store::StoreConsts::anyNode:
        //cout << " vup        - any: " << child->getStringValue() << "\n"; cout.flush();
        ZORBA_ASSERT(false);
        break;

      default:
        ZORBA_ASSERT(false);
      }
    }
  }
  return noOfChildren;
}