// Free our allocated memory CacheWA::~CacheWA() { if (tkey_) { NADELETE(tkey_,TextKey,heap_); tkey_ = 0; } if (ckey_) { NADELETE(ckey_,CacheKey,heap_); ckey_ = 0; } if (parmTypes_) { NADELETE(parmTypes_,ParameterTypeList,heap_); parmTypes_ = 0; } if (selTypes_) { NADELETE(selTypes_,SelParamTypeList,heap_); selTypes_ = 0; } if (numberOfScans_ > 0) { heap_->deallocateMemory(tabDescPtr_); tabDescPtr_ = 0; // Release the memory used by the ValueIdSets. for (Int32 i = 0; i < numberOfScans_; i++) delete usedKyPtr_[i]; heap_->deallocateMemory(usedKyPtr_); usedKyPtr_ = 0; } }
ExControlArea::~ExControlArea() { if (controlList_) { controlList_->position(); ExControlEntry * e; while ((e = (ExControlEntry *)controlList_->getNext()) != NULL) { NADELETE(e, ExControlEntry,heap_); } NADELETE(controlList_, Queue, heap_); controlList_ = NULL; } }
NARoutine::~NARoutine() { // Call deepDelete() on NAColumnArray's. // The destructor does not do this. inParams_->deepDelete(); outParams_->deepDelete(); delete inParams_; delete outParams_; delete params_; // Do not do a deepDelete() on params_ the // elements are shared with in|outParams_. delete extRoutineName_; delete extActionName_; delete intActionName_; uecValues_.clear(); // delete all its elements. if (passThruData_ NEQ NULL) { for (Int32 i = 0; i < passThruDataNumEntries_; i++) NADELETEBASIC(passThruData_[i], heap_); // Can't use NADELETEARRAY on C types. NADELETEBASIC(passThruData_, heap_); // Can't use NADELETEARRAY on C types. } if (passThruDataSize_ NEQ NULL) // Use NADELETEARRAY for any 'new(heap)<class>[<size>]' NADELETEARRAY(passThruDataSize_, (UInt32)passThruDataNumEntries_, Int64, heap_); if (privInfo_) NADELETE(privInfo_, PrivMgrUserPrivs, heap_); }
ContextTidMap * CliGlobals::getThreadContext(pid_t tid) { SQLCTX_HANDLE ch; ContextTidMap *contextTidMap; if (tidList_ == NULL) return NULL; cliSemaphore_->get(); tidList_->position((char*)&tid, sizeof(pid_t)); while ((contextTidMap = (ContextTidMap *)tidList_->getNext()) != NULL) { if (contextTidMap->tid_ == tid) { if (contextTidMap->context_ == NULL) { NADELETE(contextTidMap, ContextTidMap, getExecutorMemory()); tidList_->remove((char*)&tid, sizeof(pid_t), contextTidMap); contextTidMap = NULL; } cliSemaphore_->release(); return contextTidMap; } } cliSemaphore_->release(); return NULL; }
charBuf* unicodeToISO88591(const NAWcharBuf& input, CollHeap *heap, charBuf*& iso88591String, NABoolean addNullAtEnd, NABoolean allowInvalidCodePoint) { charBuf* output = checkSpace(heap, input.getStrLen(), iso88591String, addNullAtEnd); if ( output == 0 ) return 0; unsigned char* target = output->data(); Int32 i; for ( i=0; i<input.getStrLen(); i++ ) { if ( input.data()[i] > 0xFF ) { if ( allowInvalidCodePoint ) target[i] = '?'; else { if ( iso88591String == NULL ) { if (heap) NADELETE(output, charBuf, heap); else delete output; } return NULL; } } else target[i] = (unsigned char)(input.data()[i]); } if ( addNullAtEnd ) target[i] = 0; output -> setStrLen(input.getStrLen()); return output; }
// a helper function converting a hexdecimal digit to a single-byte string static NAString * convHexToChar(const NAWchar *s, Int32 inputLen, CharInfo::CharSet cs, CollHeap* heap) { ComASSERT((inputLen % SQL_DBCHAR_SIZE) == 0); NAString *r = new (heap) NAString(heap); if (!s || inputLen <= 0) return r; unsigned char upper4Bits; unsigned char lower4Bits; for (Int32 i = 0; i < inputLen; i=i+2) { if (isHexDigit8859_1(s[i]) AND isHexDigit8859_1(s[i+1])) { #pragma warning (disable : 4244) //warning elimination #pragma nowarn(1506) // warning elimination upper4Bits = getHexDigitValue(s[i]); #pragma warn(1506) // warning elimination #pragma nowarn(1506) // warning elimination lower4Bits = getHexDigitValue(s[i+1]); #pragma warn(1506) // warning elimination #pragma warning (default : 4244) //warning elimination #pragma nowarn(1506) // warning elimination char c = (upper4Bits << 4) | lower4Bits; #pragma warn(1506) // warning elimination r->append(c); } else { NADELETE(r, NAString, heap); return NULL; } } return r; }
void ExExeUtilTcb::deleteServer(IpcServer *ipcServer) { IpcServerClass * sc = ipcServer->getServerClass(); IpcEnvironment *env = sc->getEnv(); ipcServer->release(); NADELETE(sc, IpcServerClass, env->getHeap()); }
// return current query's formal parameter types const ParameterTypeList *CacheWA::getFormalParamTypes() { // parmTypes_ is always derived from actuals_; so, free any previous // parmTypes_ before deriving it again from actuals_ if (parmTypes_) { NADELETE(parmTypes_,ParameterTypeList,wHeap()); } // save pointer in parmTypes_ so ~CacheWA() can free it parmTypes_ = new (wHeap()) ParameterTypeList(&actuals_, wHeap()); return parmTypes_; }
// return current query's formal SelParamTypes const SelParamTypeList *CacheWA::getFormalSelParamTypes() { // selTypes_ is always derived from sels_; so, free any previous // selTypes_ before deriving it again from sels_ if (selTypes_) { NADELETE(selTypes_,SelParamTypeList,wHeap()); } // save pointer in selTypes_ so ~CacheWA() can free it selTypes_ = new (wHeap()) SelParamTypeList(&sels_, wHeap()); return selTypes_; }
void HdfsClient::deleteInstance() { ContextCli *currContext = GetCliGlobals()->currContext(); HdfsClient *hdfsClient = currContext->getHDFSClient(); if (hdfsClient != NULL) { NAHeap *heap = currContext->exHeap(); NADELETE(hdfsClient, HdfsClient, heap); currContext->setHDFSClient(NULL); } }
void HiveClient_JNI::deleteInstance() { ContextCli *currContext = GetCliGlobals()->currContext(); HiveClient_JNI *hiveClient_JNI = currContext->getHiveClient(); if (hiveClient_JNI != NULL) { NAHeap *heap = currContext->exHeap(); NADELETE(hiveClient_JNI, HiveClient_JNI, heap); currContext->setHiveClient(NULL); } }
// // This function frees any resources acquired. // It should only be called by the TCB destructor. // void ExFastExtractTcb::freeResources() { for(Int16 i=0; i < numBuffers_; i++) { if(bufferPool_[i]) { NADELETE(bufferPool_[i], IOBuffer, getHeap()); bufferPool_[i] = NULL; } } }
// a helper function converting a hexdecimal digit to a double-byte string static NAWString * convHexToWChar(const NAWchar *s, Int32 inputLen, CharInfo::CharSet cs, CollHeap* heap) { if ( cs == CharInfo::UNICODE ) { NAWString *r = new (heap) NAWString(heap); if (!s || inputLen <= 0) return r; assert((inputLen % 4) == 0); for (Int32 i = 0; i < inputLen; i=i+4) { if ( isHexDigit8859_1(s[i]) AND isHexDigit8859_1(s[i+1]) AND isHexDigit8859_1(s[i+2]) AND isHexDigit8859_1(s[i+3]) ) { unsigned short first4Bits = getHexDigitValue(s[i]); unsigned short second4Bits = getHexDigitValue(s[i+1]); unsigned short third4Bits = getHexDigitValue(s[i+2]); unsigned short fourth4Bits = getHexDigitValue(s[i+3]); #pragma nowarn(1506) // warning elimination NAWchar wc = (first4Bits << 12) | (second4Bits << 8) | (third4Bits << 4) | fourth4Bits; #pragma warn(1506) // warning elimination r->append(wc); } else { NADELETE(r, NAWString, heap); return NULL; } } #pragma nowarn(1506) // warning elimination if (! CharInfo::checkCodePoint(r->data(), r->length(), cs) ) { #pragma warn(1506) // warning elimination NADELETE(r, NAWString, heap); return NULL; } return r; } return NULL; }
short ExExeUtilLongRunningTcb::finalizeDoLongRunning() { // Close the statements Lng32 rc = cliInterface()->prepareAndExecRowsEpilogue(); NADELETE(initialOutputVarPtrList_, Queue, getHeap()); NADELETE(continuingOutputVarPtrList_, Queue, getHeap()); NADELETEBASIC(lruStmtAndPartInfo_, getHeap()); NADELETEBASIC(lruStmtWithCKAndPartInfo_, getHeap()); // if this is an ESP, deallocate transaction CliGlobals *cliGlobals = GetCliGlobals(); if (cliGlobals->isESPProcess()) { NADELETEBASIC(currTransaction_, getHeap()); currTransaction_ = NULL; } return 0; }
ExHdfsFastExtractTcb::~ExHdfsFastExtractTcb() { if (lobGlob_ != NULL) { lobGlob_ = NULL; } if (sequenceFileWriter_ != NULL) { NADELETE(sequenceFileWriter_, SequenceFileWriter, getHeap()); } } // ExHdfsFastExtractTcb::~ExHdfsFastExtractTcb()
QuasiFileManager::~QuasiFileManager(void) { // delete quasiFile list assert (quasiFileList_->isEmpty()); // delete quasiFileList_; NADELETE(quasiFileList_, Queue, noWaitHeap_); // $$$ need to think about policy here... do we do disassociates // on all Statements? Or do we assume we only get called after // contexts and statements are destroyed? }
UniqueConstraint::~UniqueConstraint() { NAHeap *heap = (NAHeap *)collHeap(); CollIndex entryCount = refConstraintsReferencingMe_.entries(); if (heap != NULL) { for (CollIndex i = 0 ; i < entryCount; i++) { NADELETE(refConstraintsReferencingMe_[i], ComplementaryRIConstraint, heap); } } else { for (CollIndex i = 0 ; i < entryCount; i++) delete refConstraintsReferencingMe_[i]; } refConstraintsReferencingMe_.clear(); }
// Unicode to UTF8 conversion. // // This function takes a Unicode UCS2/UTF16 string and returns its UTF8 equivalent. // The optional utf8String argument holds the buffer into which the Unicode string // will be stored. In case the argument is NULL or it is not big enough, // the function allocates memory from the heap (if the heap pointer is not NULL), // or from the C run-time system heap (if NA_NO_C_RUNTIME is not defined). // If the memory allocation fails, the function returns 0. If any illegal // characters are encountered, the function also returns 0. // charBuf* unicodeToUtf8(const NAWcharBuf& unicodeString, CollHeap *heap, charBuf*& utf8String, NABoolean addNullAtEnd, NABoolean allowInvalidCodePoint) { charBuf* cbufPtr = NULL; // tell unicodeTocset() to allocate a new buffer charBuf* res = NULL; Int32 errorcode = 0; res = unicodeTocset ( unicodeString // in - const NAWcharBuf & , heap // in - CollHeap * , cbufPtr , (Lng32) SQLCHARSETCODE_UTF8 // in - Lng32 targetCharSet , errorcode // out - Int32 & , addNullAtEnd , allowInvalidCodePoint ); if ( res == NULL ) // translation failed return res; charBuf* output = checkSpace(heap, res->getStrLen(), utf8String, addNullAtEnd); if ( output == NULL ) { NADELETE(res, charBuf, heap); return 0; } Int32 finalLengthInBytes = res->getStrLen(); memmove(output->data(), res->data(), finalLengthInBytes); output->setStrLen(res->getStrLen()); if ( addNullAtEnd == TRUE ) output->data()[finalLengthInBytes] = '\0'; NADELETE(res, charBuf, heap); return output; }
AbstractRIConstraint::~AbstractRIConstraint() { NAHeap *heap = (NAHeap *)collHeap(); CollIndex entryCount = keyColumns_.entries(); if (heap != NULL) { for (CollIndex i = 0 ; i < entryCount; i++) { NADELETE(keyColumns_[i], NAColumn, heap); } } else { for (CollIndex i = 0 ; i < entryCount; i++) delete keyColumns_[i]; } keyColumns_.clear(); }
HiveClient_JNI* HiveClient_JNI::newInstance(NAHeap *heap, HVC_RetCode &retCode) { QRLogger::log(CAT_SQL_HDFS, LL_DEBUG, "HiveClient_JNI::newInstance() called."); if (initJNIEnv() != JOI_OK) return NULL; retCode = HVC_OK; HiveClient_JNI *hiveClient_JNI = new (heap) HiveClient_JNI(heap); if (hiveClient_JNI != NULL) { retCode = hiveClient_JNI->initConnection(); if (retCode != HVC_OK) { NADELETE(hiveClient_JNI, HiveClient_JNI, heap); hiveClient_JNI = NULL; } } return hiveClient_JNI; }
// Cleanup file information when another filename is being used. void CmpMemoryMonitor::fileCleanUp() { // Delete memory allocated for the filename. if (logFilename_) { NADELETEBASIC(logFilename_, heap_); logFilename_ = NULL; } // Delete memory allocated for the output file stream and call // the destructor for ofstream. if (logFilestream_) { logFilestream_->close(); NADELETE(logFilestream_, ofstream, heap_); logFilestream_ = NULL; } }
//ss_cc_change : This was relevant only when we supported nowait CLI //LCOV_EXCL_START Lng32 CliGlobals::dropContext(ContextCli* context) { if (!context) return -1; if (context == getDefaultContext()) return 0; CLISemaphore *tmpSemaphore = context->getSemaphore(); tmpSemaphore->get(); try { context->deleteMe(); } catch (...) { tmpSemaphore->release(); return -1; } tmpSemaphore->release(); pid_t tid = syscall(SYS_gettid); cliSemaphore_->get(); contextList_->remove((void*)context); tidList_->position(); ContextTidMap *contextTidMap; while ((contextTidMap = (ContextTidMap *)tidList_->getNext()) != NULL) { if (contextTidMap->context_ == context) { if (contextTidMap->tid_ == tid) { tidList_->remove((char*)&contextTidMap->tid_, sizeof(pid_t), contextTidMap); NADELETE(contextTidMap, ContextTidMap, getExecutorMemory()); tsCurrentContextMap = NULL; } else contextTidMap->context_ = NULL; } } delete context; cliSemaphore_->release(); return 0; }
HdfsClient *HdfsClient::newInstance(NAHeap *heap, ExHdfsScanStats *hdfsStats, HDFS_Client_RetCode &retCode) { QRLogger::log(CAT_SQL_HDFS, LL_DEBUG, "HdfsClient::newInstance() called."); if (initJNIEnv() != JOI_OK) return NULL; retCode = HDFS_CLIENT_OK; HdfsClient *hdfsClient = new (heap) HdfsClient(heap); if (hdfsClient != NULL) { retCode = hdfsClient->init(); if (retCode == HDFS_CLIENT_OK) hdfsClient->setHdfsStats(hdfsStats); else { NADELETE(hdfsClient, HdfsClient, heap); hdfsClient = NULL; } } return hdfsClient; }
HiveClient_JNI* HiveClient_JNI::getInstance() { HVC_RetCode hvcRetcode = HVC_OK; ContextCli *currContext = GetCliGlobals()->currContext(); HiveClient_JNI *hiveClient_JNI = currContext->getHiveClient(); if (hiveClient_JNI == NULL) { NAHeap *heap = currContext->exHeap(); hiveClient_JNI = new (heap) HiveClient_JNI(heap); if ((hvcRetcode = hiveClient_JNI->init()) == HVC_OK) currContext->setHiveClient(hiveClient_JNI); else { NADELETE(hiveClient_JNI, HiveClient_JNI, heap); hiveClient_JNI = NULL; } } return hiveClient_JNI; }
HashQueue::~HashQueue() { if (shadowCopy_) return; // go thru all the chains and delete all entries in // each chain for (currentChain_ = 0; currentChain_ < hashTableSize_; currentChain_++) { HashQueueEntry * q = hashTable_[currentChain_]; while (q) { HashQueueEntry * p = q; q = q->next_; NADELETE(p, HashQueueEntry, heap_); }; }; // delete the hash table itself if (heap_) heap_->deallocateMemory((void *) hashTable_); else delete [] hashTable_; };
HdfsScan *HdfsScan::newInstance(NAHeap *heap, ExHdfsScanTcb::HDFS_SCAN_BUF *hdfsScanBuf, int scanBufSize, HdfsFileInfoArray *hdfsFileInfoArray, Int32 beginRangeNum, Int32 numRanges, int rangeTailIOSize, ExHdfsScanStats *hdfsStats, HDFS_Scan_RetCode &hdfsScanRetCode) { QRLogger::log(CAT_SQL_HDFS, LL_DEBUG, "HdfsScan::newInstance() called."); if (initJNIEnv() != JOI_OK) return NULL; hdfsScanRetCode = HDFS_SCAN_OK; HdfsScan *hdfsScan = new (heap) HdfsScan(heap); if (hdfsScan != NULL) { hdfsScanRetCode = hdfsScan->init(); if (hdfsScanRetCode == HDFS_SCAN_OK) hdfsScanRetCode = hdfsScan->setScanRanges(hdfsScanBuf, scanBufSize, hdfsFileInfoArray, beginRangeNum, numRanges, rangeTailIOSize); if (hdfsScanRetCode == HDFS_SCAN_OK) hdfsScan->setHdfsStats(hdfsStats); else { NADELETE(hdfsScan, HdfsScan, heap); hdfsScan = NULL; } } return hdfsScan; }
short ExExeUtilTcb::createServer(char *serverName, const char * inPName, IpcServerTypeEnum serverType, IpcServerAllocationMethod servAllocMethod, char *nodeName, short cpu, const char *partnName, Lng32 priority, IpcServer* &ipcServer, NABoolean logError, const char * operation) { short error = 0; // Get the globals stucture of the master executor. ExExeStmtGlobals *exeGlob = getGlobals()->castToExExeStmtGlobals(); ExMasterStmtGlobals *masterGlob = exeGlob->castToExMasterStmtGlobals(); IpcEnvironment * env = masterGlob->getCliGlobals()->getEnvironment(); NAHeap *ipcHeap = masterGlob->getCliGlobals()->getIpcHeap(); IpcServerClass * sc = new (ipcHeap) IpcServerClass(env, serverType, servAllocMethod, //IPC_LAUNCH_GUARDIAN_PROCESS, COM_VERS_MXV, nodeName); if (!sc) { if (logError) { char emsText[400+ComMAX_3_PART_EXTERNAL_UTF8_NAME_LEN_IN_BYTES]; str_sprintf(emsText, "Failure creating IpcServerClass on \\%s cpu %d to %s %s for %s.", nodeName, cpu, operation, partnName, (char *)exeUtilTdb().getTableName()); SQLMXLoggingArea::logExecRtInfo(NULL, 0, emsText, 0); } return -1; } const char * pName = NULL; char pNameBuf[20]; short pNameLen = 0; if (inPName) pName = inPName; else { pName = pNameBuf; pNameBuf[pNameLen] = 0; } ipcServer = sc->allocateServerProcess(&diagsArea_, ipcHeap, nodeName, cpu, priority, 1, // espLevel (not relevent) FALSE, // no Xn TRUE, // waited creation 0, // maxNowaitRequests serverName, pName ); if (!ipcServer) { if (logError && diagsArea_) { char emsText[400+ComMAX_3_PART_EXTERNAL_UTF8_NAME_LEN_IN_BYTES]; str_sprintf(emsText, "allocateServerProcess() failed with error %d on \\%s cpu %d to %s %s for %s.", diagsArea_->mainSQLCODE(), nodeName, cpu, operation, partnName, (char *)exeUtilTdb().getTableName()); SQLMXLoggingArea::logExecRtInfo(NULL, 0, emsText, 0); } NADELETE(sc, IpcServerClass, ipcHeap); return -3; } return 0; }
NARoutine::NARoutine(const QualifiedName &name, const TrafDesc *routine_desc, BindWA *bindWA, Int32 &errorOccurred, NAMemory *heap) : name_ (name, heap) , hashKey_ (name, heap) , language_ (routine_desc->routineDesc()->language) , UDRType_ (routine_desc->routineDesc()->UDRType) , sqlAccess_ (routine_desc->routineDesc()->sqlAccess) , transactionAttributes_ (routine_desc->routineDesc()->transactionAttributes) , maxResults_ (routine_desc->routineDesc()->maxResults) , stateAreaSize_ (routine_desc->routineDesc()->stateAreaSize) , externalFile_ ("", heap) , externalPath_ (routine_desc->routineDesc()->libraryFileName, heap) , externalName_ ("", heap) , librarySqlName_ (routine_desc->routineDesc()->librarySqlName, COM_UNKNOWN_NAME, FALSE, heap) //TODO , signature_ (routine_desc->routineDesc()->signature, heap) , paramStyle_ (routine_desc->routineDesc()->paramStyle) , paramStyleVersion_ (COM_ROUTINE_PARAM_STYLE_VERSION_1) , isDeterministic_ (routine_desc->routineDesc()->isDeterministic) , isCallOnNull_ (routine_desc->routineDesc()->isCallOnNull ) , isIsolate_ (routine_desc->routineDesc()->isIsolate) , externalSecurity_ (routine_desc->routineDesc()->externalSecurity) , isExtraCall_ (FALSE) //TODO , hasOutParams_ (FALSE) , redefTime_ (0) //TODO , lastUsedTime_ (0) , routineSecKeySet_ (heap) , passThruDataNumEntries_ (0) , passThruData_ (NULL) , passThruDataSize_ (0) , udfFanOut_ (1) // TODO , uecValues_ (heap,0) , isUniversal_ (0) // TODO , actionPosition_ (0) // TODO , executionMode_ (COM_ROUTINE_SAFE_EXECUTION) , objectUID_ (routine_desc->routineDesc()->objectUID) , dllName_ (routine_desc->routineDesc()->libraryFileName, heap) , dllEntryPoint_ (routine_desc->routineDesc()->externalName, heap) , sasFormatWidth_ ("", heap) //TODO , systemName_ ("", heap) // TODO , dataSource_ ("", heap) // TODO , fileSuffix_ ("", heap) // TODO , schemaVersionOfRoutine_ ((COM_VERSION)0) // TODO , objectOwner_ (routine_desc->routineDesc()->owner) , schemaOwner_ (routine_desc->routineDesc()->schemaOwner) , privInfo_ (NULL) , heap_(heap) { char parallelism[5]; CmGetComRoutineParallelismAsLit(routine_desc->routineDesc()->parallelism, parallelism); comRoutineParallelism_ = ((char *)parallelism); if (paramStyle_ == COM_STYLE_JAVA_CALL) { NAString extName(routine_desc->routineDesc()->externalName); size_t pos=extName.last('.'); externalName_ = extName(pos+1, (extName.length()-pos-1)); // method_name externalFile_ = extName.remove (pos); // package_name.class_name } else { externalName_ = routine_desc->routineDesc()->externalName; if (language_ == COM_LANGUAGE_C || language_ == COM_LANGUAGE_CPP) { // Split the fully-qualified DLL name into a directory name and // simple file name ComUInt32 len = dllName_.length(); if (len > 0) { size_t lastSlash = dllName_.last('/'); if (lastSlash == NA_NPOS) { // No slash was found externalPath_ = "."; externalFile_ = dllName_; } else { // A slash was found. EXTERNAL PATH is everything before the // slash. EXTERNAL FILE is everything after. externalPath_ = dllName_; externalPath_.remove(lastSlash, len - lastSlash); externalFile_ = dllName_; externalFile_.remove(0, lastSlash + 1); } } } // if (len > 0) } ComSInt32 colCount = routine_desc->routineDesc()->paramsCount; NAColumn *newCol = NULL; NAType *newColType = NULL; extRoutineName_ = new (heap) ExtendedQualName( name_, heap ); extActionName_ = new (heap) NAString(heap); intActionName_ = new (heap) ComObjectName(heap); params_ = new (heap) NAColumnArray(heap); inParams_ = new (heap) NAColumnArray(heap); outParams_ = new (heap) NAColumnArray(heap); // to compute java signature ComFSDataType *paramType = new STMTHEAP ComFSDataType[colCount]; ComUInt32 *subType = new STMTHEAP ComUInt32 [colCount]; ComColumnDirection *direction = new STMTHEAP ComColumnDirection[colCount] ; // // Construct the CostVectors // CQDs are checked at Bind time. Int32 initCpuCost = -1; Int32 initIOCost = -1; Int32 initMsgCost = -1; CostScalar initialCpuCost( initCpuCost); CostScalar initialIOCost( initIOCost); CostScalar initialMsgCost( initMsgCost); initialRowCost_.setCPUTime( initCpuCost < 0 ? csMinusOne : initialCpuCost); initialRowCost_.setIOTime( initIOCost < 0 ? csMinusOne : initialIOCost); initialRowCost_.setMSGTime( initMsgCost < 0 ? csMinusOne : initialMsgCost); Int32 normCpuCost = -1; Int32 normIOCost = -1; Int32 normMsgCost = -1; CostScalar normalCpuCost( normCpuCost); CostScalar normalIOCost( normIOCost); CostScalar normalMsgCost( normMsgCost); normalRowCost_.setCPUTime( normCpuCost < 0 ? csMinusOne : normalCpuCost); normalRowCost_.setIOTime( normIOCost < 0 ? csMinusOne : normalIOCost); normalRowCost_.setMSGTime( normMsgCost < 0 ? csMinusOne : normalMsgCost); TrafDesc *params_desc_list = routine_desc->routineDesc()->params; TrafColumnsDesc *param_desc; int i = 0; while (params_desc_list) { param_desc = params_desc_list->columnsDesc(); // Create the new NAType. if (NAColumn::createNAType(param_desc->columnsDesc(), (const NATable *)NULL, newColType, heap_)) { errorOccurred = TRUE; return; } if (param_desc->colname && strncmp(param_desc->colname, "#:", 2) == 0) { memset(param_desc->colname, 0, 2); } ComParamDirection colDirection = param_desc->paramDirection(); // Create the new NAColumn and insert it into the NAColumnArray newCol = new (heap) NAColumn( (const char *)UDRCopyString (param_desc->colname, heap) , param_desc->colnumber , newColType , heap , NULL // NATable * , USER_COLUMN , COM_NO_DEFAULT , NULL // default value , UDRCopyString("", heap) // TODO:heading can it have some value , param_desc->isUpshifted() , FALSE // addedColumn , (ComColumnDirection) colDirection , param_desc->isOptional() , (char *) COM_NORMAL_PARAM_TYPE_LIT ); // We have to check for INOUT in both the // if's below if ( COM_OUTPUT_PARAM == colDirection || COM_INOUT_PARAM == colDirection ) { hasOutParams_ = TRUE; outParams_->insert (newCol); params_->insert (newCol ); } if ( COM_INPUT_PARAM == colDirection || COM_INOUT_PARAM == colDirection ) { inParams_->insert (newCol); if ( COM_INOUT_PARAM != colDirection ) { params_->insert (newCol ); } // if not INOUT } // if IN or INOUT // Gather the param attributes for LM from the paramDefArray previously // populated and from the routineparamList generated from paramDefArray. paramType[i] = (ComFSDataType)newColType->getFSDatatype(); subType[i] = 0; // default // Set subType for special cases detected by LM switch ( paramType[i] ) { case COM_SIGNED_BIN16_FSDT : case COM_SIGNED_BIN32_FSDT : case COM_SIGNED_BIN64_FSDT : case COM_UNSIGNED_BIN16_FSDT : case COM_UNSIGNED_BIN32_FSDT : case COM_UNSIGNED_BPINT_FSDT : { subType[i] = newColType->getPrecision(); break; } case COM_DATETIME_FSDT : { switch ( ((DatetimeType *)newColType)->getSubtype() ) { case DatetimeType::SUBTYPE_SQLDate : subType[i] = 1; break; case DatetimeType::SUBTYPE_SQLTime : subType[i] = 2; break; case DatetimeType::SUBTYPE_SQLTimestamp : subType[i] = 3; break; } } } // end switch paramType[i] direction[i] = (ComColumnDirection) colDirection; params_desc_list = params_desc_list->next; i++; } // for passThruDataNumEntries_ = 0; passThruData_ = NULL; passThruDataSize_ = NULL; #define MAX_SIGNATURE_LENGTH 8193 if ((language_ == COM_LANGUAGE_JAVA)&&(signature_.length() < 2)) { // Allocate buffer for generated signature char sigBuf[MAX_SIGNATURE_LENGTH]; sigBuf[0] = '\0'; // If the syntax specified a signature, pass that to LanguageManager. char* optionalSig = NULL; ComBoolean isJavaMain = ((str_cmp_ne(externalName_.data(), "main") == 0) ? TRUE : FALSE); LmResult createSigResult; LmJavaSignature *lmSignature = new (STMTHEAP) LmJavaSignature(NULL, STMTHEAP); createSigResult = lmSignature->createSig(paramType, subType, direction, colCount, COM_UNKNOWN_FSDT, 0, maxResults_, optionalSig, isJavaMain, sigBuf, MAX_SIGNATURE_LENGTH, CmpCommon::diags()); NADELETE(lmSignature, LmJavaSignature, STMTHEAP); // Lm returned error. Lm fills diags area if (createSigResult != LM_ERR) signature_ = sigBuf; } getPrivileges(routine_desc->routineDesc()->priv_desc); heapSize_ = (heap ? heap->getTotalSize() : 0); }
// ---------------------------------------------------------------------------- // method: getPrivileges // // If authorization is enabled, set privs based on the passed in priv_desc // and set up query invalidation (security) keys for the routine. // ---------------------------------------------------------------------------- void NARoutine::getPrivileges(TrafDesc *priv_desc) { if ( !CmpCommon::context()->isAuthorizationEnabled() || ComUser::isRootUserID()) { privInfo_ = new(heap_) PrivMgrUserPrivs; privInfo_->setOwnerDefaultPrivs(); return; } NAString privMDLoc = CmpSeabaseDDL::getSystemCatalogStatic(); privMDLoc += ".\""; privMDLoc += SEABASE_PRIVMGR_SCHEMA; privMDLoc += "\""; PrivMgrCommands privInterface(privMDLoc.data(), CmpCommon::diags(),PrivMgr::PRIV_INITIALIZED); if (priv_desc == NULL) { privInfo_ = new(heap_) PrivMgrUserPrivs; CmpSeabaseDDL cmpSBD(STMTHEAP); if (cmpSBD.switchCompiler(CmpContextInfo::CMPCONTEXT_TYPE_META)) { if (CmpCommon::diags()->getNumber(DgSqlCode::ERROR_) == 0) *CmpCommon::diags() << DgSqlCode( -4400 ); return; } ComObjectType objectType = (UDRType_ == COM_PROCEDURE_TYPE ? COM_STORED_PROCEDURE_OBJECT : COM_USER_DEFINED_ROUTINE_OBJECT); std::vector <ComSecurityKey *>* secKeyVec = new(heap_) std::vector<ComSecurityKey *>; if (privInterface.getPrivileges(objectUID_, objectType, ComUser::getCurrentUser(), *privInfo_, secKeyVec) != STATUS_GOOD) { NADELETE(privInfo_, PrivMgrUserPrivs, heap_); privInfo_ = NULL; } cmpSBD.switchBackCompiler(); if (privInfo_) { for (std::vector<ComSecurityKey*>::iterator iter = secKeyVec->begin(); iter != secKeyVec->end(); iter++) { // Insertion of the dereferenced pointer results in NASet making // a copy of the object, and then we delete the original. routineSecKeySet_.insert(**iter); delete *iter; } } } else { // get roles granted to current user // SQL_EXEC_GetRoleList returns the list of roles from the CliContext std::vector<int32_t> myRoles; Int32 numRoles = 0; Int32 *roleIDs = NULL; if (SQL_EXEC_GetRoleList(numRoles, roleIDs) < 0) { *CmpCommon::diags() << DgSqlCode(-1034); return; } // At this time we should have at least one entry in roleIDs (PUBLIC_USER) CMPASSERT (roleIDs && numRoles > 0); for (Int32 i = 0; i < numRoles; i++) myRoles.push_back(roleIDs[i]); privInfo_ = new (heap_) PrivMgrUserPrivs; privInfo_->initUserPrivs(myRoles, priv_desc, ComUser::getCurrentUser(),objectUID_, routineSecKeySet_); } }
// LCOV_EXCL_STOP void ex_expr::displayContents(Space * space, short mode, const char * displayStr,ULng32 flag) { char buf[100] = {0}; // Soln 10-041117-1848 ULng32 exprLen = getLength(); #ifndef __EID str_sprintf(buf, "Expression: %s", displayStr); #endif space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short)); #ifndef __EID str_sprintf(buf, "Expr Len: %d, Consts Len: %d", exprLen, getConstsLength()); space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short)); str_sprintf(buf, "flags_ = %b ",flags_ ); #endif space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short)); if (flag & 0x00000004) { Int32 i = 1; ex_clause * clause = getClauses(); while (clause) { clause->displayContents(space, 0, i, constantsArea_); clause = clause->getNextClause(); i++; } } if (flag & 0x00000002) { #ifndef __EID if (getPCodeBinary()) { str_sprintf(buf, " PCode:\n"); space->allocateAndCopyToAlignedSpace(buf, str_len(buf),sizeof(short)); str_sprintf(buf, "PCode Expr Length: %d", getPCodeSize()); space->allocateAndCopyToAlignedSpace(buf, str_len(buf),sizeof(short)); PCodeCfg* cfg = new(heap_) PCodeCfg(this, heap_); cfg->generateShowPlan(getPCodeBinary(), space); NADELETE(cfg, PCodeCfg, heap_); } else if ((flag & 0x00000010) && (getPCodeBinary())) { // LCOV_EXCL_START str_sprintf(buf, " PCode:\n"); space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short)); str_sprintf(buf, "PCode Expr Length: %d", getPCodeSize()); space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short)); PCode::displayContents(getPCodeBinary(), space); // LCOV_EXCL_STOP } else { // Clear the fixup flag, since the expression has not been fixed up // (pCodeGenerate undoes, the fixup of Const and Temp offsets.) // setFixupConstsAndTemps(0); // re-generate pcode for showplan setPCodeGenCompile(0); setPCodeObject(0); pCode_ = 0; Space tempSpace; //create pcode stuff in a different space //the space in PCode::displayContents is used for //creating text for the showplan UInt32 f = 0; ex_expr_base::setForShowplan(f, TRUE); ex_expr_base::setDownrevCompileR2FCS(f, ((flag & 0x00000010) != 0)); ex_expr_base::setDownrevCompileRR(f, ((flag & 0x00000020) != 0)); pCodeGenerate(&tempSpace, &tempSpace, f); if(getPCodeObject()) { // LCOV_EXCL_START str_sprintf(buf, " PCode:\n"); space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short)); str_sprintf(buf, "PCode Expr Length: %d", getPCodeSize()); space->allocateAndCopyToAlignedSpace(buf, str_len(buf), sizeof(short)); PCode::displayContents(getPCodeObject()->getPCIList(), space); // LCOV_EXCL_STOP } } #endif //__EID } }