void HdfsClient::deleteHdfsFileInfo() { for (int i = 0; i < numFiles_ ; i ++) { NADELETEBASIC(hdfsFileInfo_[i].mName, getHeap()); NADELETEBASIC(hdfsFileInfo_[i].mOwner, getHeap()); NADELETEBASIC(hdfsFileInfo_[i].mGroup, getHeap()); } if (hdfsFileInfo_ != NULL) NADELETEBASICARRAY(hdfsFileInfo_, getHeap()); numFiles_ = 0; hdfsFileInfo_ = NULL; }
void SessionDefaults::setExSMTraceFilePrefix(const char *attrValue, Int32 attrValueLen) { if (exsmTraceFilePrefix_) { NADELETEBASICARRAY(exsmTraceFilePrefix_, heap_); exsmTraceFilePrefix_ = NULL; } if (attrValue == NULL || attrValue[0] == 0 || attrValueLen == 0) return; exsmTraceFilePrefix_ = new(heap_) char[attrValueLen + 1]; strncpy(exsmTraceFilePrefix_, attrValue, attrValueLen); exsmTraceFilePrefix_[attrValueLen] = 0; }
//Detailed error support for conversions, especially for use in convdoit. ComDiagsArea *ExRaiseDetailSqlError(CollHeap* heap, ComDiagsArea** diagsArea, ExeErrorCode err, char *src, Int32 srcLength, Int16 srcType, Int32 srcScale, Int16 tgtType, UInt32 flags, Int32 tgtLength, Int32 tgtScale, Int32 tgtPrecision, Int32 srcPrecision) { //if looping situation, no need to proceed further, return back. if(flags & CONV_CONTROL_LOOPING) return NULL; NABoolean intermediate; if( flags & CONV_INTERMEDIATE_CONVERSION ) intermediate = TRUE; else intermediate = FALSE; if (diagsArea == NULL) return NULL; if (*diagsArea == NULL){ if (heap == NULL) return NULL; *diagsArea = ComDiagsArea::allocate(heap); } //Allocate buf once, for formatting and opstring[1]. // |--------formatting--------|--opstring[1]------| char *buf = new (heap) char[FORMATTING+ OPVALUE_LEN] ; if( !buf ){ ExRaiseSqlError(heap, diagsArea, err); return *diagsArea; } char *opString = &buf[FORMATTING]; ExConvertErrorToString(heap, diagsArea, src, srcLength, srcType, srcScale, opString, OPVALUE_LEN); char srcDatatypeDetail[200]; char tgtDatatypeDetail[200]; char srcTypeAsText[1000]; char tgtTypeAsText[100]; srcTypeAsText[0] = 0; tgtTypeAsText[0] = 0; if (srcPrecision != -1) { rec_datetime_field startField; rec_datetime_field endField; ExpDatetime::getDatetimeFields(srcPrecision, startField, endField); convertTypeToText_basic(srcTypeAsText, srcType, srcLength, srcPrecision, srcScale, startField, endField, 0, 0, 0, 0, (CharInfo::CharSet)srcScale, NULL, NULL, 0); strcpy(srcDatatypeDetail, getDatatypeAsString(srcType, false)); } else if ((DFS2REC::isCharacterString(srcType)) && (srcLength >= 0) && (srcScale > 0) && (srcPrecision == -1)) str_sprintf(srcDatatypeDetail, "%s,%d BYTES,%s", getDatatypeAsString(srcType, false), srcLength, (srcScale == CharInfo::ISO88591 ? "ISO88591" : "UTF8")); else strcpy(srcDatatypeDetail, getDatatypeAsString(srcType, false)); if (tgtLength != -1) { rec_datetime_field startField; rec_datetime_field endField; ExpDatetime::getDatetimeFields(tgtPrecision, startField, endField); convertTypeToText_basic(tgtTypeAsText, tgtType, tgtLength, tgtPrecision, tgtScale, startField, endField, 0, 0, 0, 0, (CharInfo::CharSet)tgtScale, NULL, NULL, 0); strcpy(tgtDatatypeDetail, getDatatypeAsString(tgtType, false)); } else if ((DFS2REC::isCharacterString(tgtType)) && (tgtLength >= 0) && (tgtScale > 0)) str_sprintf(tgtDatatypeDetail, "%s,%d %s,%s", getDatatypeAsString(tgtType, false), tgtPrecision ? tgtPrecision : tgtLength, tgtPrecision ? "CHARS" : "BYTES", (tgtScale == CharInfo::ISO88591 ? "ISO88591" : "UTF8")); else strcpy(tgtDatatypeDetail, getDatatypeAsString(tgtType, false)); str_sprintf(buf, " %s of Source Type:%s(%s) Source Value:%s to Target Type:%s(%s).", intermediate? "Intermediate conversion" : "Conversion", (strlen(srcTypeAsText) == 0 ? getDatatypeAsString(srcType,true) : srcTypeAsText), srcDatatypeDetail, opString, (strlen(tgtTypeAsText) == 0 ? getDatatypeAsString(tgtType,true) : tgtTypeAsText), tgtDatatypeDetail); **diagsArea << DgSqlCode(-err); **diagsArea<<DgString0(buf); NADELETEBASICARRAY(buf, (heap)); return *diagsArea; }
//Detailed error support for clause expression evaluation. ComDiagsArea *ExRaiseDetailSqlError(CollHeap* heap, ComDiagsArea** diagsArea, ExeErrorCode err, ex_clause *clause, char *op_data[]) { if (diagsArea == NULL) return NULL; if (*diagsArea == NULL){ if (heap == NULL) return NULL; *diagsArea = ComDiagsArea::allocate(heap); } Int16 numOperands = clause->getNumOperands(); Attributes *op; Int16 i; // Single allocation of buf is split up to be used for opstrings, // formatting. See defines at beginning of this header file // for details. char *buf = new (heap) char[(numOperands * (VALUE_TYPE_LEN + OPVALUE_LEN)) + INSTR_LEN + FORMATTING]; if( !buf ){ ExRaiseSqlError(heap, diagsArea, err); return *diagsArea; } char *opStrings = &buf[(numOperands * VALUE_TYPE_LEN) + INSTR_LEN ]; // assign FORMATTING part of address. char *buf1 = &buf[(numOperands * (VALUE_TYPE_LEN + OPVALUE_LEN)) + INSTR_LEN]; for (i = 1; i < numOperands; i++){ op = clause->getOperand(i); ExConvertErrorToString(heap, diagsArea, (char*)op_data[i], op->getLength(), op->getDatatype(), op->getScale(), (char*)&opStrings[(i-1)*OPVALUE_LEN], OPVALUE_LEN); } //initialize buf before entering the loop. buf[0] = '\0'; for(i = 1; i< numOperands; i++){ op = clause->getOperand(i); str_sprintf(buf1, " Operand%d Type:%s(%s) Operand%d Value:%s",i, getDatatypeAsString(op->getDatatype(), true), getDatatypeAsString(op->getDatatype(), false), i, &opStrings[(i-1)*OPVALUE_LEN]); str_cat(buf, buf1, buf); } if(numOperands) { str_sprintf(buf1,"."); str_cat(buf, buf1, buf); } str_sprintf(buf1, " Clause Type:%d Clause number:%d Operation:%s.", clause->getType(), clause->clauseNum(), exClauseGetText(clause->getOperType())); str_cat(buf, buf1, buf); **diagsArea << DgSqlCode(-err); **diagsArea<<DgString0(buf); NADELETEBASICARRAY(buf, (heap)); return *diagsArea; }
//Detailed error support for pcode expression evaluation. ComDiagsArea *ExRaiseDetailSqlError(CollHeap* heap, ComDiagsArea** diagsArea, ExeErrorCode err, Int32 pciInst, char *op1, char *op2, char *op3) { if (diagsArea == NULL) return NULL; if (*diagsArea == NULL){ if (heap == NULL) return NULL; *diagsArea = ComDiagsArea::allocate(heap); } PCIT::Operation operation; PCIT::AddressingMode am[6]; Int32 numAModes; Int32 rangeInst = PCode::isInstructionRangeType((PCIT::Instruction)pciInst)? 1: 0; if(PCode::getOpCodeMapElements( pciInst, operation, am, numAModes ) ){ ExRaiseSqlError(heap, diagsArea, err); return *diagsArea; } // Single allocation of buf is split up to be used for opstrings, // formatting. See defines at beginning of this header file // for details. char *buf = new (heap) char[(numAModes * (VALUE_TYPE_LEN + OPVALUE_LEN)) + INSTR_LEN + FORMATTING]; if( !buf ){ ExRaiseSqlError(heap, diagsArea, err); return *diagsArea; } char *opStrings = &buf[(numAModes * VALUE_TYPE_LEN) + INSTR_LEN ]; char *buf1 = // assign FORMATTING part of address. &buf[(numAModes * (VALUE_TYPE_LEN + OPVALUE_LEN)) + INSTR_LEN]; switch( numAModes ){ case 1: ExConvertErrorToString(heap, diagsArea, op1, PCIT::getOperandLengthForAddressingMode(am[0]), PCIT::getDataTypeForMemoryAddressingMode(am[0]), 0, (char*)&opStrings[0], OPVALUE_LEN); //construct a formated string and assign to diags area **diagsArea << DgSqlCode(-err); if(rangeInst){ str_sprintf( buf, " Source Value:%s not within limits of Target Type:%s(%s).", &opStrings[0], getDatatypeAsString(PCIT::getDataTypeForMemoryAddressingMode(am[0]),true), PCIT::addressingModeString(am[0])); } else{ str_sprintf( buf, " Operand Type:%s(%s) Operand Value:%s.", getDatatypeAsString(PCIT::getDataTypeForMemoryAddressingMode(am[0]),true), PCIT::addressingModeString(am[0]), &opStrings[0]); } str_sprintf( buf1, " Instruction:%s Operation:%s.", PCIT::instructionString((PCIT::Instruction)pciInst), PCIT::operationString(operation)); str_cat(buf, buf1, buf); **diagsArea<<DgString0(buf); break; case 3: case 4: //since we are only interested in left and right operands, just overright //am modes to be processed by case 2 below. am[0] = am[1]; am[1] = am[2]; //do not break here. Flow down to case 2. case 2: ExConvertErrorToString(heap, diagsArea, op1, PCIT::getOperandLengthForAddressingMode(am[0]), PCIT::getDataTypeForMemoryAddressingMode(am[0]), 0, (char*)&opStrings[0], OPVALUE_LEN); ExConvertErrorToString(heap, diagsArea, op2, PCIT::getOperandLengthForAddressingMode(am[1]), PCIT::getDataTypeForMemoryAddressingMode(am[1]), 0, (char*)&opStrings[OPVALUE_LEN], OPVALUE_LEN); //construct a formated string and assign to diags area **diagsArea << DgSqlCode(-err); str_sprintf( buf, " %s Type:%s(%s) %s Value:%s", rangeInst? "Source":"Operand1", getDatatypeAsString(PCIT::getDataTypeForMemoryAddressingMode(am[0]),true), PCIT::addressingModeString(am[0]), rangeInst? "Source":"Operand1", &opStrings[0]); str_sprintf( buf1, " %s Type:%s(%s)%s%s Value:%s.", rangeInst? "Target":"Operand2", getDatatypeAsString(PCIT::getDataTypeForMemoryAddressingMode(am[1]),true), PCIT::addressingModeString(am[1]), rangeInst? (opStrings[OPVALUE_LEN] == '-' ? " Min ": " Max "):" ", rangeInst? "Target":"Operand2", &opStrings[OPVALUE_LEN]); str_cat(buf, buf1, buf); str_sprintf( buf1, " Instruction:%s Operation:%s.", PCIT::instructionString((PCIT::Instruction)pciInst), PCIT::operationString(operation)); str_cat(buf, buf1, buf); **diagsArea<<DgString0(buf); break; //Needs to be enhanced for other types. Just dump what ever we have. default: ExRaiseSqlError(heap, diagsArea, err); }; NADELETEBASICARRAY(buf, (heap)); return *diagsArea; }
charBuf* unicodeTocset(const NAWcharBuf& input, CollHeap *heap, charBuf*& csetString, Int32 cset, Int32 &errorcode, NABoolean addNullAtEnd, NABoolean allowInvalidCodePoint, Int32 *charCount, Int32 *errorByteOff) { char * err_ptr; UInt32 byteCount, lvCharCount; enum cnv_charset cnvSet = convertCharsetEnum (cset); Int32 cwidth = CharInfo::maxBytesPerChar((CharInfo::CharSet)cset); charBuf* output = NULL; if ( input.data() != NULL && input.getStrLen() > 0) { Int32 cSetTargetBufferSizeInBytes = input.getStrLen/*in_NAWchars*/()*cwidth+16; // memory is cheap UInt32 cSetTargetStrLenInBytes = 0; char *pTempTargetBuf = new(heap) char[cSetTargetBufferSizeInBytes]; errorcode = UTF16ToLocale ( cnv_version1 , (const char *)input.data() // source string , input.getStrLen()*BYTES_PER_NAWCHAR // source string length in bytes , (const char *)pTempTargetBuf // buffer for the converted string , cSetTargetBufferSizeInBytes // target buffer size in bytes , cnvSet // convert from UTF16 to cnvSet , err_ptr , &cSetTargetStrLenInBytes // out - length in bytes of the converted string , 0 , addNullAtEnd , allowInvalidCodePoint ); NADELETEBASICARRAY(pTempTargetBuf, heap); pTempTargetBuf = NULL; if (errorcode == 0 && cSetTargetStrLenInBytes > 0) output = checkSpace(heap, cSetTargetStrLenInBytes, csetString, addNullAtEnd); else // invoke the old code (i.e., keep the old behavior) output = checkSpace(heap, input.getStrLen()*cwidth, csetString, addNullAtEnd); } else // invoke the old code (i.e., keep the old behavior) output = checkSpace(heap, input.getStrLen()*cwidth, csetString, addNullAtEnd); if ( output == 0 ) {errorcode = CNV_ERR_BUFFER_OVERRUN; return 0;} unsigned char* target = output->data(); errorcode = UTF16ToLocale( cnv_version1, (const char *)input.data(), input.getStrLen()*BYTES_PER_NAWCHAR, (const char *)target, output->getBufSize(), cnvSet , err_ptr, &byteCount , 0, addNullAtEnd, allowInvalidCodePoint, &lvCharCount); if (errorcode == CNV_ERR_NOINPUT) errorcode=0; // empty string is OK if (errorByteOff) *errorByteOff = err_ptr - (char *)input.data(); if (charCount) *charCount = (Int32)lvCharCount; // If errorcode != 0, LocaleToUTF16 will not add the NULL terminator if (errorcode == 0 && addNullAtEnd && byteCount > 0) { // Exclude the size (in bytes) of the NULL terminator from the byte count. UInt32 nullLen = CharInfo::minBytesPerChar((CharInfo::CharSet) cset); if (byteCount > nullLen) byteCount -= nullLen; else byteCount = 0; } output -> setStrLen(byteCount/*in_bytes*/); // excluding the null terminator from the count return output; }