void Item::processNode(const QDomNode &node) { if (node.isElement()) processAttributes(node.toElement()); if (node.hasChildNodes()) processChildNodes(node.firstChild()); }
void XMLTreeBuilder::processStartTag(const AtomicXMLToken& token) { exitText(); bool isFirstElement = !m_sawFirstElement; m_sawFirstElement = true; NodeStackItem top = m_currentNodeStack.last(); processNamespaces(token, top); QualifiedName qName(token.prefix(), token.name(), top.namespaceForPrefix(token.prefix(), top.namespaceURI())); RefPtr<Element> newElement = m_document->createElement(qName, true); processAttributes(token, top, newElement); newElement->beginParsingChildren(); m_currentNodeStack.last().node()->parserAddChild(newElement.get()); top.setNode(newElement); pushCurrentNode(top); if (!newElement->attached()) newElement->attach(); if (isFirstElement && m_document->frame()) m_document->frame()->loader()->dispatchDocumentElementAvailable(); if (token.selfClosing()) closeElement(newElement); }
void SAXParser::processElement() { Element element; // C.3.3 If the optional component attributes is present, then the bit '1' (presence) is appended to the bit stream; // otherwise, the bit '0' (absence) is appended. bool hasAttributes = checkBit(_b, 2) != 0; // C.3.4 If the optional component namespace-attributes is present, it is encoded as described in the three // following subclauses. // C.3.4.1 The four bits '1110' (presence) and the two bits '00' (padding) are appended to the bit stream. // check for namespace attributes if((_b & Constants::ELEMENT_NAMESPACE_ATTRIBUTES_MASK) == Constants::ELEMENT_NAMESPACE_ATTRIBUTES_FLAG) { throw std::runtime_error("No namespace support yet"); } // C.3.5 The value of the component qualified-name is encoded as described in C.18. getQualifiedNameOrIndex3(element._qualifiedName); if(hasAttributes) processAttributes(); _contentHandler->startElement(_vocab, element, _attributes); _attributes.clear(); while(!_terminated) { _b = static_cast<unsigned char>(_stream->get()); if(!checkBit(_b, 1)) { // 0 padding announcing element processElement(); } else if((_b & Constants::TWO_BITS) == Constants::ELEMENT_CHARACTER_CHUNK) { processCharacterChunk(); } else if (_b == Constants::TERMINATOR_SINGLE || _b == Constants::TERMINATOR_DOUBLE) { _terminated = true; _doubleTerminated = _b == Constants::TERMINATOR_DOUBLE; } else throw std::runtime_error("message.decodingEIIs"); } _contentHandler->endElement(_vocab, element); _terminated = _doubleTerminated; _doubleTerminated = false; }
TSK_RETVAL_ENUM TSKAutoImpl::processFile(TSK_FS_FILE * a_fsFile, const char * a_path) { // skip the . and .. dirs if (isDotDir(a_fsFile, a_path) == 1) { return TSK_OK; } m_db.begin(); TSK_RETVAL_ENUM retval; // process the attributes if there are more than 1 if (tsk_fs_file_attr_getsize(a_fsFile) == 0) { retval = TSK_OK; uint64_t fileId; // If COR is returned, then keep on going. if (insertFileData(a_fsFile, NULL, a_path, fileId) == TSK_ERR) retval = TSK_ERR; else m_numFilesSeen++; } else { retval = processAttributes(a_fsFile, a_path); } static time_t lastCheck = m_startTime; time_t timeNow = time(NULL); if ((timeNow - lastCheck) > 3600) { lastCheck = timeNow; std::wstringstream msg; msg << L"TSKAutoImpl::processFile : Processed " << m_numFilesSeen << " files."; LOGINFO(msg.str()); } m_db.commit(); return retval; }
void process(char* const xmlFile) { // // Create a Schema validator to be used for our validation work. Then create // a SAX parser object and pass it our validator. Then, according to what // we were told on the command line, set it to validate or not. He owns // the validator, so we have to allocate it. // SAXParser parser; parser.setValidationScheme(SAXParser::Val_Always); parser.setDoNamespaces(true); parser.setDoSchema(true); parser.parse(xmlFile); if (parser.getErrorCount()) { XERCES_STD_QUALIFIER cout << "\nErrors occurred, no output available\n" << XERCES_STD_QUALIFIER endl; return; } if (!parser.getValidator().handlesSchema()) { XERCES_STD_QUALIFIER cout << "\n Non schema document, no output available\n" << XERCES_STD_QUALIFIER endl; return; } Grammar* rootGrammar = parser.getRootGrammar(); if (!rootGrammar || rootGrammar->getGrammarType() != Grammar::SchemaGrammarType) { XERCES_STD_QUALIFIER cout << "\n Non schema grammar, no output available\n" << XERCES_STD_QUALIFIER endl; return; } // // Now we will get an enumerator for the element pool from the validator // and enumerate the elements, printing them as we go. For each element // we get an enumerator for its attributes and print them also. // SchemaGrammar* grammar = (SchemaGrammar*) rootGrammar; RefHash3KeysIdPoolEnumerator<SchemaElementDecl> elemEnum = grammar->getElemEnumerator(); if (!elemEnum.hasMoreElements()) { XERCES_STD_QUALIFIER cout << "\nThe validator has no elements to display\n" << XERCES_STD_QUALIFIER endl; return; } while(elemEnum.hasMoreElements()) { const SchemaElementDecl& curElem = elemEnum.nextElement(); // Name XERCES_STD_QUALIFIER cout << "Name:\t\t\t" << StrX(curElem.getFullName()) << "\n"; // Model Type XERCES_STD_QUALIFIER cout << "Model Type:\t\t"; switch( curElem.getModelType() ) { case SchemaElementDecl::Empty: XERCES_STD_QUALIFIER cout << "Empty"; break; case SchemaElementDecl::Any: XERCES_STD_QUALIFIER cout << "Any"; break; case SchemaElementDecl::Mixed_Simple: XERCES_STD_QUALIFIER cout << "Mixed_Simple"; break; case SchemaElementDecl::Mixed_Complex: XERCES_STD_QUALIFIER cout << "Mixed_Complex"; break; case SchemaElementDecl::Children: XERCES_STD_QUALIFIER cout << "Children"; break; case SchemaElementDecl::Simple: XERCES_STD_QUALIFIER cout << "Simple"; break; case SchemaElementDecl::ElementOnlyEmpty: XERCES_STD_QUALIFIER cout << "ElementOnlyEmpty"; break; default: XERCES_STD_QUALIFIER cout << "Unknown"; break; } XERCES_STD_QUALIFIER cout << "\n"; // Create Reason XERCES_STD_QUALIFIER cout << "Create Reason:\t"; switch( curElem.getCreateReason() ) { case XMLElementDecl::NoReason: XERCES_STD_QUALIFIER cout << "Empty"; break; case XMLElementDecl::Declared: XERCES_STD_QUALIFIER cout << "Declared"; break; case XMLElementDecl::AttList: XERCES_STD_QUALIFIER cout << "AttList"; break; case XMLElementDecl::InContentModel: XERCES_STD_QUALIFIER cout << "InContentModel"; break; case XMLElementDecl::AsRootElem: XERCES_STD_QUALIFIER cout << "AsRootElem"; break; case XMLElementDecl::JustFaultIn: XERCES_STD_QUALIFIER cout << "JustFaultIn"; break; default: XERCES_STD_QUALIFIER cout << "Unknown"; break; } XERCES_STD_QUALIFIER cout << "\n"; // Content Spec Node processContentSpecNode( curElem.getContentSpec() ); // Misc Flags int mflags = curElem.getMiscFlags(); if( mflags !=0 ) { XERCES_STD_QUALIFIER cout << "Misc. Flags:\t"; } if ( mflags & SchemaSymbols::XSD_NILLABLE ) XERCES_STD_QUALIFIER cout << "Nillable "; if ( mflags & SchemaSymbols::XSD_ABSTRACT ) XERCES_STD_QUALIFIER cout << "Abstract "; if ( mflags & SchemaSymbols::XSD_FIXED ) XERCES_STD_QUALIFIER cout << "Fixed "; if( mflags !=0 ) { XERCES_STD_QUALIFIER cout << "\n"; } // Substitution Name SchemaElementDecl* subsGroup = curElem.getSubstitutionGroupElem(); if( subsGroup ) { const XMLCh* uriText = parser.getURIText(subsGroup->getURI()); XERCES_STD_QUALIFIER cout << "Substitution Name:\t" << StrX(uriText) << "," << StrX(subsGroup->getBaseName()) << "\n"; } // Content Model const XMLCh* fmtCntModel = curElem.getFormattedContentModel(); if( fmtCntModel != NULL ) { XERCES_STD_QUALIFIER cout << "Content Model:\t" << StrX(fmtCntModel) << "\n"; } const ComplexTypeInfo* ctype = curElem.getComplexTypeInfo(); if( ctype != NULL) { XERCES_STD_QUALIFIER cout << "ComplexType:\n"; XERCES_STD_QUALIFIER cout << "\tTypeName:\t" << StrX(ctype->getTypeName()) << "\n"; ContentSpecNode* cSpecNode = ctype->getContentSpec(); processContentSpecNode(cSpecNode, true ); } // Datatype DatatypeValidator* dtValidator = curElem.getDatatypeValidator(); processDatatypeValidator( dtValidator ); // Get an enumerator for this guy's attributes if any if ( curElem.hasAttDefs() ) { processAttributes( curElem.getAttDefList() ); } XERCES_STD_QUALIFIER cout << "--------------------------------------------"; XERCES_STD_QUALIFIER cout << XERCES_STD_QUALIFIER endl; } return; }
void processAttributes(const OC::OCRepresentation &rep, const std::map <std::string, AttrDesc> *attrMap, std::string prefix) { for (auto &attr : *attrMap) { if (rep.hasAttribute(attr.first)) { std::cout << prefix << attr.first << ""; } else { continue; } switch (attr.second.type) { case ATTR_TYPE_BOOL: { bool value; rep.getValue(attr.first, value); std::cout << " (bool):\t " << ((value) ? "TRUE" : "FALSE") << std::endl; break; } case ATTR_TYPE_INT: { int value; rep.getValue(attr.first, value); std::cout << " (int):\t " << value << std::endl; break; } case ATTR_TYPE_INT64: { double value; rep.getValue(attr.first, value); std::cout << " (int64): \t " << value << std::endl; break; } case ATTR_TYPE_STRING: { std::string value; rep.getValue(attr.first, value); std::cout << " (string): \t " << value << std::endl; break; } case ATTR_TYPE_VECTOR: { OC::OCRepresentation internal; rep.getValue(attr.first, internal); std::cout << std::endl; processAttributes(internal, attr.second.composite, prefix + "\t"); break; } default: { std::cout << "not handled yet" << std::endl; break; } } } }
void SchemaValidatorImpl::processElement( store::PUL* pul, TypeManager* typeManager, EventSchemaValidator& schemaValidator, store::Item_t element, const QueryLoc& loc) { ZORBA_ASSERT(element->isNode()); ZORBA_ASSERT(element->getNodeKind() == store::StoreConsts::elementNode); store::Item_t nodeName = element->getNodeName(); zstring baseUri; element->getBaseURI(baseUri); //cout << " vup - processElement: " << nodeName->getLocalName()->c_str() // << " @ " << nodeName->getNamespace()->c_str() << "\n"; cout.flush(); schemaValidator.startElem(nodeName); // namespace declarations must go first processNamespaces( schemaValidator, element); // since the type of an element is determined only after the validator // receives all of it's attributes, and an attribute node needs it's // parent when created we need to go through the attributes twice: once // for validation and once for creation validateAttributes(schemaValidator, element->getAttributes()); store::Item_t typeQName = schemaValidator.getTypeQName(); store::Item_t substitutedElemQName = schemaValidator.getSubstitutedElemQName(); //cout << " vup - elemType old: " // << element->getType()->getLocalName()->c_str() << " @ " // << element->getType()->getNamespace()->c_str() << "\n"; cout.flush(); //cout << " vup - elemType new: " << typeQName->getLocalName()->c_str() // << " @ " << typeQName->getNamespace()->c_str() << "\n"; cout.flush(); bool isInSubstitutionElement = false; if (substitutedElemQName) { isInSubstitutionElement = true; // cout << " vup - substitutes: " << substitutedElemQName->g // etLocalName()->c_str() << " @ " << substitutedElemQName->getNamespace()-> // c_str() << "\n"; cout.flush(); } bool isNewType = false; xqtref_t newType; store::Item_t elm; if ( !typeQName->equals(element->getType()) ) { isNewType = true; newType = typeManager->create_named_type(typeQName, SequenceType::QUANT_ONE, loc); elm = element; } store::NsBindings bindings; element->getNamespaceBindings(bindings); namespace_context nsCtx = namespace_context(theSctx, bindings); processAttributes(pul, nsCtx, typeManager, schemaValidator, element, element->getAttributes(), loc); std::vector<store::Item_t> typedValues; int noOfChildren = processChildren(pul, nsCtx, typeManager, schemaValidator, element->getChildren(), typedValues, loc); if ( isNewType ) { bool tHasValue = Validator::typeHasValue(newType); bool tHasTypedValue = Validator::typeHasTypedValue(typeManager, newType, loc); bool tHasEmptyValue = Validator::typeHasEmptyValue(newType); if ( noOfChildren==0 ) { // workaround for elem of type xsd:string with no text child if ( newType->is_builtin() && newType->getQName()->equals(GENV_TYPESYSTEM.STRING_TYPE_ONE->getQName()) ) { /*store::Item_t result; zstring emptyStr = ""; GENV_ITEMFACTORY->createString( result, emptyStr); typedValues.push_back(result);*/ tHasEmptyValue = true; tHasTypedValue = false; tHasValue = false; } else if ( newType->type_kind()==XQType::USER_DEFINED_KIND ) { const UserDefinedXQType udXQType = static_cast<const UserDefinedXQType&>(*newType); if ( udXQType.isSubTypeOf(typeManager, *GENV_TYPESYSTEM.STRING_TYPE_ONE) ) { tHasEmptyValue = true; tHasTypedValue = false; tHasValue = false; } } } //cout << " vup - addSetElementType: " << elm->getNodeName()-> // getLocalName()->str() << " " << newType->get_qname()->getLocalName() // << " @ " << newType->get_qname()->getNamespace() << "\n"; cout.flush(); //cout << " vup - " << ( tHasTypedValue ? "hasTypedValue" : "" ) // << " values.size: " << typedValues.size() << (typedValues.size()>0 ? // " [0]=" + typedValues[0]->getStringValue()->str() : "" ) << ( tHasValue ? // " hasValue" : "" ) << ( tHasEmptyValue ? " hasEmptyValue" : "" ) << "\n"; // cout.flush(); if ( typedValues.size()==1 ) pul->addSetElementType(&loc, elm, typeQName, typedValues[0], tHasValue, tHasEmptyValue, tHasTypedValue, isInSubstitutionElement); else pul->addSetElementType(&loc, elm, typeQName, (std::vector<store::Item_t>&)typedValues, tHasValue, tHasEmptyValue, tHasTypedValue, isInSubstitutionElement); } schemaValidator.endElem(nodeName); }
short ExpGenerator::buildKeyInfo(keyRangeGen ** keyInfo, // out -- generated object Generator * generator, const NAColumnArray & keyColumns, const ValueIdList & listOfKeyColumns, const ValueIdList & beginKeyPred, const ValueIdList & endKeyPred, const SearchKey * searchKey, const MdamKey * mdamKeyPtr, const NABoolean reverseScan, unsigned short keytag, const ExpTupleDesc::TupleDataFormat tf, // the next few parameters are here // as part of a horrible kludge for // the PartitionAccess::codeGen() // method, which lacks a SearchKey // object and therefore exposes // things like the exclusion // expressions; with luck, later work // in the Optimizer will result in a // much cleaner interface const NABoolean useTheHorribleKludge, ItemExpr * beginKeyExclusionExpr, ItemExpr * endKeyExclusionExpr, ex_expr_lean ** unique_key_expr, ULng32 *uniqueKeyLen, NABoolean doKeyEncodeOpt, Lng32 * firstKeyColOffset, Int32 in_key_atp_index ) { Space * space = generator->getSpace(); const Int32 work_atp = 1; const Int32 key_atp_index = (in_key_atp_index <= 0 ? 2 : in_key_atp_index); const Int32 exclude_flag_atp_index = 3; const Int32 data_conv_error_atp_index = 4; const Int32 key_column_atp_index = 5; // used only for Mdam const Int32 key_column2_atp_index = 6; // used only for Mdam MDAM_BETWEEN pred; // code in BiLogic::mdamPredGenSubrange // and MdamColumn::buildDisjunct // requires this to be 1 more than // key_column_atp_index ULng32 keyLen; // add an entry to the map table for work Atp MapTable *keyBufferPartMapTable = generator->appendAtEnd(); // generate a temporary variable, which will be used for handling // data conversion errors during key building ValueIdList temp_varb_list; ItemExpr * dataConversionErrorFlag = new(generator->wHeap()) HostVar("_sys_dataConversionErrorFlag", new(generator->wHeap()) SQLInt(TRUE,FALSE), // int not null TRUE); ULng32 temp_varb_tupp_len; dataConversionErrorFlag->bindNode(generator->getBindWA()); temp_varb_list.insert(dataConversionErrorFlag->getValueId()); processValIdList(temp_varb_list, ExpTupleDesc::SQLARK_EXPLODED_FORMAT, temp_varb_tupp_len, // out work_atp, data_conv_error_atp_index); NABoolean doEquiKeyPredOpt = FALSE; #ifdef _DEBUG if (getenv("DO_EQUI_KEY_PRED_OPT")) doEquiKeyPredOpt = (searchKey ? searchKey->areAllChosenPredsEqualPreds() : FALSE); #endif if (mdamKeyPtr == NULL) { // check to see if there is a begin key expression; if there // isn't, don't generate a key object if (beginKeyPred.entries() == 0) *keyInfo = 0; else { // For subset and range operators, generate the begin key // expression, end key expression, begin key exclusion expression // and end key exclusion expression. For unique operators, // generate only the begin key exppression. ex_expr *bk_expr = 0; ex_expr *ek_expr = 0; ex_expr *bk_excluded_expr = 0; ex_expr *ek_excluded_expr = 0; short bkey_excluded = 0; short ekey_excluded = 0; generateKeyExpr(keyColumns, beginKeyPred, work_atp, key_atp_index, dataConversionErrorFlag, tf, keyLen, // out &bk_expr, // out doKeyEncodeOpt, firstKeyColOffset, doEquiKeyPredOpt); if (&endKeyPred) generateKeyExpr(keyColumns, endKeyPred, work_atp, key_atp_index, dataConversionErrorFlag, tf, keyLen, // out -- should be the same as above &ek_expr, // out doKeyEncodeOpt, firstKeyColOffset, doEquiKeyPredOpt); if (reverseScan) { // reverse scan - swap the begin and end key predicates // Note: evidently, the Optimizer has already switched // the key predicates in this case, so what we are // really doing is switching them back. ex_expr *temp = bk_expr; bk_expr = ek_expr; ek_expr = temp; } if (searchKey) { generateExclusionExpr(searchKey->getBeginKeyExclusionExpr(), work_atp, exclude_flag_atp_index, &bk_excluded_expr); // out bkey_excluded = (short) searchKey->isBeginKeyExclusive(); generateExclusionExpr(searchKey->getEndKeyExclusionExpr(), work_atp, exclude_flag_atp_index, &ek_excluded_expr); // out ekey_excluded = (short) searchKey->isEndKeyExclusive(); if (reverseScan) { NABoolean x = bkey_excluded; bkey_excluded = ekey_excluded; #pragma nowarn(1506) // warning elimination ekey_excluded = x; #pragma warn(1506) // warning elimination ex_expr* temp = bk_excluded_expr; bk_excluded_expr = ek_excluded_expr; bk_excluded_expr = temp; } } // if searchKey else if (useTheHorribleKludge) { generateExclusionExpr(beginKeyExclusionExpr, work_atp, exclude_flag_atp_index, &bk_excluded_expr); // out generateExclusionExpr(endKeyExclusionExpr, work_atp, exclude_flag_atp_index, &ek_excluded_expr); // out // note that the old PartitionAccess::codeGen() code didn't // set values for bkey_excluded and ekey_excluded, so the // safest choice is to choose inclusion, i.e. let the flags // retain their initial value of 0. } // Build key info if (keytag > 0) keyLen += sizeof(short); if ((unique_key_expr == NULL) || (NOT generator->genLeanExpr())) { // the work cri desc is used to build key values (entry 2) and // to compute the exclusion flag (entry 3) to monitor for data // conversion errors (entry 4) and to compute values on a column // basis (entry 5 - Mdam only) ex_cri_desc * work_cri_desc = new(space) ex_cri_desc(6, space); *keyInfo = new(space) keySingleSubsetGen( keyLen, work_cri_desc, key_atp_index, exclude_flag_atp_index, data_conv_error_atp_index, bk_expr, ek_expr, bk_excluded_expr, ek_excluded_expr, // static exclude flags (if exprs are NULL) bkey_excluded, ekey_excluded); if (unique_key_expr) *unique_key_expr = NULL; } else { if (keyInfo) *keyInfo = NULL; *unique_key_expr = (ex_expr_lean*)bk_expr; *uniqueKeyLen = keyLen; } } } // end of non-mdam case else // Mdam case { // the work cri desc is used to build key values (entry 2) and // to compute the exclusion flag (entry 3) to monitor for data // conversion errors (entry 4) and to compute values on a column // basis (entry 5 - Mdam only, and entry 6 - Mdam only, and only // for MDAM_BETWEEN predtype) ex_cri_desc * work_cri_desc = new(space) ex_cri_desc(7, space); // compute the format of the key buffer -- We need this // so that Mdam will know, for each column, where in the buffer // to move a value and how many bytes that value takes. The // next few lines of code result in this information being stored // in the attrs array. // Some words on the technique: We create expressions whose // result datatype matches the key buffer datatypes for each key // column. Then we use the datatypes of these expressions to // compute buffer format. The expressions themselves are not // used any further; they do not result in compiled expressions // in the plan. At run time we use string moves to move key // values instead. const CollIndex keyCount = listOfKeyColumns.entries(); CollIndex i; // assert at least one column GenAssert(keyCount > 0,"MDAM: at least one key column required."); Attributes ** attrs = new(generator->wHeap()) Attributes * [keyCount]; for (i = 0; i < keyCount; i++) { ItemExpr * col_node = listOfKeyColumns[i].getItemExpr(); ItemExpr *enode = col_node; if ((tf == ExpTupleDesc::SQLMX_KEY_FORMAT) && (enode->getValueId().getType().getVarLenHdrSize() > 0)) { // varchar keys in SQL/MP tables are converted to // fixed length chars in key buffers const CharType& char_type = (CharType&)(enode->getValueId().getType()); if (!CollationInfo::isSystemCollation(char_type.getCollation())) { enode = new(generator->wHeap()) Cast(enode, (new (generator->wHeap()) SQLChar( CharLenInfo(char_type.getStrCharLimit(), char_type.getDataStorageSize()), char_type.supportsSQLnull(), FALSE, FALSE, FALSE, char_type.getCharSet(), char_type.getCollation(), char_type.getCoercibility()))); } } NABoolean desc_flag; if (keyColumns.isAscending(i)) desc_flag = reverseScan; else desc_flag = !reverseScan; #pragma nowarn(1506) // warning elimination enode = new(generator->wHeap()) CompEncode(enode,desc_flag); #pragma warn(1506) // warning elimination enode->bindNode(generator->getBindWA()); attrs[i] = (generator-> addMapInfoToThis(keyBufferPartMapTable, enode->getValueId(), 0))->getAttr(); } // for, over keyCount // Compute offsets, lengths, etc. and assign them to the right // atp and atp index processAttributes((ULng32)keyCount, attrs, tf, keyLen, work_atp, key_atp_index); // Now we have key column offsets and lengths stored in attrs. // Next, for each column, generate expressions to compute hi, // lo, non-null hi and non-null lo values, and create // MdamColumnGen structures. // Notes: In the Mdam network itself, all key values are // encoded. Hence, we generate CompEncode nodes in all of the // expressions, regardless of tuple format. In the Simulator // case, we must at run-time decode the encoded values when // moving them to the key buffer. $$$ We need an expression to // do this. This decoding work has not yet been done, so the // simulator only works correctly for columns that happen to be // correctly aligned and whose encoding function does not change // the value. $$$ MdamColumnGen * first = 0; MdamColumnGen * last = 0; LIST(NAType *) keyTypeList(generator->wHeap());//to keep the type of the keys for later for (i = 0; i < keyCount; i++) { // generate expressions to compute hi, lo, non-null hi, non-null lo NAType * targetType = (keyColumns[i]->getType())->newCopy(generator->wHeap()); // Genesis case 10-971031-9814 fix: desc_flag must take into account // both the ASC/DESC attribute of the key column and the reverseScan // attribute. Before this fix, it only took into account the first of // these. NABoolean desc_flag; if (keyColumns.isAscending(i)) desc_flag = reverseScan; else desc_flag = !reverseScan; // End Genesis case 10-971031-9814 fix. if ((tf == ExpTupleDesc::SQLMX_KEY_FORMAT) && (targetType->getVarLenHdrSize() > 0)) { // 5/9/98: add support for VARNCHAR const CharType* char_type = (CharType*)(targetType); if (!CollationInfo::isSystemCollation(char_type->getCollation())) { targetType = new(generator->wHeap()) SQLChar( CharLenInfo(char_type->getStrCharLimit(), char_type->getDataStorageSize()), char_type -> supportsSQLnull(), FALSE, FALSE, FALSE, char_type -> getCharSet(), char_type -> getCollation(), char_type -> getCoercibility()); /* targetType->getNominalSize(), targetType->supportsSQLnull() */ } } keyTypeList.insert(targetType); // save in ith position for later // don't need to make copy of targetType in next call ItemExpr * lo = new(generator->wHeap()) ConstValue(targetType, !desc_flag, TRUE /* allow NULL */); #pragma nowarn(1506) // warning elimination lo = new(generator->wHeap()) CompEncode(lo,desc_flag); #pragma warn(1506) // warning elimination lo->bindNode(generator->getBindWA()); ValueIdList loList; loList.insert(lo->getValueId()); ex_expr *loExpr = 0; ULng32 dataLen = 0; generateContiguousMoveExpr(loList, 0, // don't add convert nodes work_atp, key_column_atp_index, tf, dataLen, &loExpr); ItemExpr * hi = new(generator->wHeap()) ConstValue(targetType->newCopy(generator->wHeap()), desc_flag, TRUE /* allow NULL */); #pragma nowarn(1506) // warning elimination hi = new(generator->wHeap()) CompEncode(hi,desc_flag); #pragma warn(1506) // warning elimination hi->bindNode(generator->getBindWA()); ValueIdList hiList; hiList.insert(hi->getValueId()); ex_expr *hiExpr = 0; generateContiguousMoveExpr(hiList, 0, // don't add convert nodes work_atp, key_column_atp_index, tf, dataLen, &hiExpr); ex_expr *nonNullLoExpr = loExpr; ex_expr *nonNullHiExpr = hiExpr; if (targetType->supportsSQLnull()) { if (desc_flag) { ItemExpr * nonNullLo = new(generator->wHeap()) ConstValue(targetType->newCopy(generator->wHeap()), !desc_flag, FALSE /* don't allow NULL */); #pragma nowarn(1506) // warning elimination nonNullLo = new(generator->wHeap()) CompEncode(nonNullLo,desc_flag); #pragma warn(1506) // warning elimination nonNullLo->bindNode(generator->getBindWA()); ValueIdList nonNullLoList; nonNullLoList.insert(nonNullLo->getValueId()); nonNullLoExpr = 0; // so we will get an expression back generateContiguousMoveExpr(nonNullLoList, 0, // don't add convert nodes work_atp, key_column_atp_index, tf, dataLen, &nonNullLoExpr); } else { ItemExpr * nonNullHi = new(generator->wHeap()) ConstValue(targetType->newCopy(generator->wHeap()), desc_flag, FALSE /* don't allow NULL */); #pragma nowarn(1506) // warning elimination nonNullHi = new(generator->wHeap()) CompEncode(nonNullHi,desc_flag); #pragma warn(1506) // warning elimination nonNullHi->bindNode(generator->getBindWA()); ValueIdList nonNullHiList; nonNullHiList.insert(nonNullHi->getValueId()); nonNullHiExpr = 0; // so we will get an expression back generateContiguousMoveExpr(nonNullHiList, 0, // don't add convert nodes work_atp, key_column_atp_index, tf, dataLen, &nonNullHiExpr); } } NABoolean useSparseProbes = mdamKeyPtr->isColumnSparse(i); // calculate offset to the beginning of the column value // (including the null indicator and the varchar length // indicator if present) ULng32 column_offset = attrs[i]->getOffset(); if (attrs[i]->getNullFlag()) column_offset = attrs[i]->getNullIndOffset(); else if (attrs[i]->getVCIndicatorLength() > 0) column_offset = attrs[i]->getVCLenIndOffset(); last = new(space) MdamColumnGen(last, dataLen, column_offset, useSparseProbes, loExpr, hiExpr, nonNullLoExpr, nonNullHiExpr); if (first == 0) first = last; } // for over keyCount // generate MdamPred's and attach to MdamColumnGen's const ColumnOrderListPtrArray &columnOrderListPtrArray = mdamKeyPtr->getColumnOrderListPtrArray(); #ifdef _DEBUG // Debug print stataments below depend on this // variable: char *ev = getenv("MDAM_PRINT"); const NABoolean mdamPrintOn = (ev != NULL AND strcmp(ev,"ON")==0); #endif #ifdef _DEBUG if (mdamPrintOn) { fprintf(stdout, "\n\n***Generating the MDAM key for table with index" " columns: "); listOfKeyColumns.display(); } #endif for (CollIndex n = 0; n < columnOrderListPtrArray.entries(); n++) { // get the list of key predicates associated with the n disjunct: const ColumnOrderList &columnOrderList = *columnOrderListPtrArray[n]; #ifdef _DEBUG if (mdamPrintOn) { fprintf(stdout,"\nDisjunct[%d]:----------------\n",n); columnOrderList.print(); } #endif MdamColumnGen * cc = first; CMPASSERT(keyCount == columnOrderList.entries()); const ValueIdSet *predsPtr = NULL; for (i = 0; i < keyCount; i++) { #ifdef _DEBUG if (mdamPrintOn) { fprintf(stdout, "Column(%d) using: ", i); if ( mdamKeyPtr->isColumnSparse(i) ) fprintf(stdout,"SPARSE probes\n"); else fprintf(stdout, "DENSE probes\n"); } #endif // get predicates for column order i: predsPtr = columnOrderList[i]; NAType * keyType = keyTypeList[i]; NABoolean descending; if (keyColumns.isAscending(i)) descending = reverseScan; else descending = !reverseScan; ValueId keyColumn = listOfKeyColumns[i]; MdamCodeGenHelper mdamHelper( n, keyType, descending, work_atp, key_column_atp_index, tf, dataConversionErrorFlag, keyColumn); MdamPred * lastPred = cc->getLastPred(); if (predsPtr != NULL) { for (ValueId predId = predsPtr->init(); predsPtr->next(predId); predsPtr->advance(predId)) { MdamPred * head = 0; // head of generated MdamPred's MdamPred * tail = 0; ItemExpr * orGroup = predId.getItemExpr(); orGroup->mdamPredGen(generator,&head,&tail,mdamHelper,NULL); if (lastPred) { if ( CmpCommon::getDefault(RANGESPEC_TRANSFORMATION) == DF_ON ) { MdamPred* curr = lastPred; while(curr->getNext() != NULL) curr=curr->getNext(); curr->setNext(head); } else lastPred->setNext(head); } cc->setLastPred(tail); lastPred = tail; //@ZXmdam if 1st pred has head != tail, head is lost } // for over preds } // if (predsPtr != NULL) cc = cc->getNext(); } // for every order... } // for every column order list in the array (of disjuncts) // build the Mdam key info if (keytag > 0) keyLen += sizeof(short); *keyInfo = new(space) keyMdamGen(keyLen, work_cri_desc, key_atp_index, exclude_flag_atp_index, data_conv_error_atp_index, key_column_atp_index, first, last, reverseScan, generator->wHeap()); } // end of mdam case if (*keyInfo) (*keyInfo)->setKeytag(keytag); // reset map table to forget about the key object's work Atp // aside: this logic is more bloody than it should be because the // map table implementation doesn't accurately reflect the map table // abstraction generator->removeAll(keyBufferPartMapTable); // deletes anything that might have been // added after keyBufferPartMapTable (at // this writing we don't expect there to // be anything, but we want to be safe) // at this point keyBufferPartMapTable should be the last map table in the // global map table chain generator->removeLast(); // unlinks keyBufferPartMapTable and deletes it return 0; };
/*============================================================================= Desc: Simple routine to display the contents of a document. =============================================================================*/ RCODE printDocument( IF_Db * pDb, IF_DOMNode * pRootNode) { RCODE rc = NE_XFLM_OK; FLMBYTE ucLine[ 200]; FLMBYTE * pszLine; FLMBOOL bHasChildren = FALSE; FLMBOOL bHadAttributes; FLMUINT uiDataType; char szName[ 50]; FLMUINT uiNameLen; IF_DOMNode * pNode = pRootNode; char szTemp[ 200]; FLMUINT uiTemp; FLMBOOL bUnwinding = FALSE; FLMBOOL bHadValue = FALSE; FLMUINT uiThisLevel = 0; FLMUINT uiNextLevel = 0; eDomNodeType eNodeType; pNode->AddRef(); pszLine = &ucLine[0]; bHadAttributes = FALSE; while (pNode) { bHadValue = FALSE; // Write out the current line. if (pszLine != &ucLine[0]) { printMessage( (char *)ucLine, uiThisLevel); pszLine = &ucLine[0]; } // Adjust to the next level uiThisLevel = uiNextLevel; eNodeType = pNode->getNodeType(); if( eNodeType == DOCUMENT_NODE) { if (!bUnwinding) { f_sprintf( (char *)pszLine, "<doc"); } else { f_sprintf( (char *)pszLine, "</doc>"); } pszLine += f_strlen( (char *)pszLine); } else if( eNodeType == ELEMENT_NODE) { if (RC_BAD( rc = pNode->getQualifiedName( pDb, szName, sizeof(szName), &uiNameLen))) { goto Exit; } if (!bUnwinding) { f_sprintf( (char *)pszLine, "<%s", szName); } else { f_sprintf( (char *)pszLine, "</%s>", szName); } pszLine += f_strlen( (char *)pszLine); } if (!bUnwinding) { if (RC_BAD( rc = processAttributes( pDb, pNode, &pszLine))) { goto Exit; } // We need to know if this node has children to // know how to close the line. if (RC_BAD( rc = pNode->hasChildren( pDb, &bHasChildren))) { goto Exit; } if( eNodeType == DATA_NODE || eNodeType == COMMENT_NODE) { if (RC_BAD( rc = pNode->getDataType( pDb, &uiDataType))) { goto Exit; } if( eNodeType == COMMENT_NODE) { f_sprintf( (char *)pszLine, "<!--"); pszLine += 4; } switch (uiDataType) { case XFLM_TEXT_TYPE: case XFLM_NUMBER_TYPE: { bHadValue = TRUE; if (RC_BAD( rc = pNode->getUTF8( pDb, (FLMBYTE *)szTemp, sizeof(szTemp), 0, 200, &uiTemp))) { goto Exit; } f_sprintf( (char *)pszLine, "%s", szTemp); pszLine += uiTemp; break; } default: { // Do nothing at this time. Should generate some // type of error response. } // Could also get binary data, but we won't handle it here. } if( eNodeType == COMMENT_NODE) { f_sprintf( (char *)pszLine, "-->"); pszLine += 3; } } else { if ( !bHasChildren) { f_sprintf( (char *)pszLine, "/>"); pszLine += 2; } else { f_sprintf( (char *)pszLine, ">"); pszLine++; } } // Children if (bHasChildren) { // Get the child node. if (RC_BAD( rc = pNode->getFirstChild( pDb, &pNode))) { goto Exit; } uiNextLevel++; continue; } } bUnwinding = FALSE; if (RC_BAD( rc = pNode->getNextSibling( pDb, &pNode))) { if (rc == NE_XFLM_DOM_NODE_NOT_FOUND) { rc = NE_XFLM_OK; } else { goto Exit; } } else { continue; } // Get the parent if there is one. Otherwise we are done. if (uiNextLevel) { --uiNextLevel; } if (RC_BAD( rc = pNode->getParentNode( pDb, &pNode))) { if (rc != NE_XFLM_DOM_NODE_NOT_FOUND) { goto Exit; } rc = NE_XFLM_OK; pNode->Release(); pNode = NULL; } else { bUnwinding = TRUE; } } printMessage( (char *)ucLine); Exit: return( rc); }