ExpLOBiud::ExpLOBiud(OperatorTypeEnum oper_type, Lng32 numAttrs, Attributes ** attr, Int64 objectUID, short descSchNameLen, char * descSchName, Space * space) : ExpLOBoper(oper_type, numAttrs, attr, space), objectUID_(objectUID), liudFlags_(0) // descSchNameLen_(descSchNameLen), // liFlags_(0) { str_cpy_and_null(descSchName_, descSchName, descSchNameLen, '\0', ' ', TRUE); setDescSchNameLen(descSchNameLen); };
ex_expr::exp_return_type ExpLOBiud::insertData(Lng32 handleLen, char * handle, char *op_data[], CollHeap*h, ComDiagsArea** diagsArea) { Lng32 rc = 0; Lng32 lobOperStatus = checkLobOperStatus(); if (lobOperStatus == DO_NOTHING_) return ex_expr::EXPR_OK; Lng32 lobType; Int64 uid; Lng32 lobNum; Int64 lobLen; // Lng32 flags; Int64 descSyskey = -1; // Int64 descTS = -1; short numChunks = 0; // short schNameLen = 0; // char schName[500]; extractFromLOBhandle(NULL, &lobType, &lobNum, &uid, &descSyskey, NULL, //&descTS, NULL, NULL, //&schNameLen, schName, handle); // get the lob name where data need to be inserted char tgtLobNameBuf[100]; char * tgtLobName = ExpGetLOBname(uid, lobNum, tgtLobNameBuf, 100); if (tgtLobName == NULL) return ex_expr::EXPR_ERROR; lobLen = getOperand(1)->getLength(); char * lobData = NULL; if(fromFile()) { lobData = new (h) char[lobLen]; str_cpy_and_null(lobData,op_data[1],lobLen,'\0',' ',TRUE); } else lobData = op_data[1]; if (fromBuffer()) { memcpy(&lobLen, op_data[2],sizeof(Int64)); // user specified buffer length memcpy(lobData,op_data[1],sizeof(Int64)); // user buffer address } LobsOper lo ; if (lobOperStatus == CHECK_STATUS_) lo = Lob_Check_Status; else if (handle == NULL) lo = Lob_InsertDataSimple; else lo = Lob_InsertData; LobsSubOper so = Lob_None; if (fromFile()) so = Lob_File; else if (fromString() || fromLoad()) so = Lob_Memory; else if (fromLob()) so = Lob_Foreign_Lob; else if(fromBuffer()) so = Lob_Buffer; Lng32 waitedOp = 0; #ifdef __EID waitedOp = 0; // nowaited op from EID/TSE process #else waitedOp = 1; #endif //temptemp. Remove after ExLobsOper adds nowaited support. waitedOp = 1; Lng32 cliError = 0; blackBoxLen_ = 0; if (fromLob()) { Int64 srcDescKey = -1; Int64 srcDescTS = -1; char srcLobNameBuf[100]; char * srcLobName = NULL; short srcSchNameLen = 0; char srcSchName[500]; extractFromLOBhandle(NULL, &lobType, &lobNum, &uid, &srcDescKey, &srcDescTS, &srcSchNameLen, srcSchName, op_data[1]); // get the lob name where data will be read from srcLobName = ExpGetLOBname(uid, lobNum, srcLobNameBuf, 100); if (srcLobName == NULL) return ex_expr::EXPR_ERROR; } else { rc = ExpLOBInterfaceInsert(getExeGlobals()->lobGlobal(), tgtLobName, lobStorageLocation(), lobType, getLobHdfsServer(), getLobHdfsPort(), handleLen, handle, &outHandleLen_, outLobHandle_, blackBoxLen_, blackBox_, requestTag_, getExeGlobals()->lobGlobals()->xnId(), descSyskey, lo, &cliError, so, waitedOp, lobData, lobLen,getLobMaxSize(), getLobMaxChunkMemSize(), getLobGCLimit()); } if (rc == LOB_ACCESS_PREEMPT) { return ex_expr::EXPR_PREEMPT; } if (rc < 0) { Lng32 intParam1 = -rc; ExRaiseSqlError(h, diagsArea, (ExeErrorCode)(8442), NULL, &intParam1, &cliError, NULL, (char*)"ExpLOBInterfaceInsert", getLobErrStr(intParam1)); return ex_expr::EXPR_ERROR; } return ex_expr::EXPR_OK; }
ex_expr::exp_return_type ExpLOBiud::insertDesc(char *op_data[], CollHeap*h, ComDiagsArea** diagsArea) { Lng32 rc; Lng32 lobOperStatus = checkLobOperStatus(); if (lobOperStatus == DO_NOTHING_) return ex_expr::EXPR_OK; char * result = op_data[0]; // get the lob name where data need to be inserted char tgtLobNameBuf[100]; char * tgtLobName = ExpGetLOBname(objectUID_, lobNum(), tgtLobNameBuf, 100); if (tgtLobName == NULL) return ex_expr::EXPR_ERROR; // call function with the lobname and source value // to insert it in the LOB. // Get back offset and len of the LOB. Int64 descSyskey = 0; char * lobHandle = NULL; Lng32 handleLen = 0; char lobHandleBuf[LOB_HANDLE_LEN]; // if (getExeGlobals()->lobGlobals()->getCurrLobOperInProgress()) if (lobOperStatus == CHECK_STATUS_) { lobHandle = lobHandleSaved_; handleLen = lobHandleLenSaved_; } else { Int64 descTS = NA_JulianTimestamp(); lobHandle = lobHandleBuf; ExpLOBoper::genLOBhandle(objectUID_, lobNum(), (short)lobStorageType(), -1, descTS, -1, descSchNameLen_, descSchName(), handleLen, lobHandle); } LobsSubOper so = Lob_None; if (fromFile()) so = Lob_File; else if (fromString() || fromLoad()) so = Lob_Memory; else if (fromLob()) so = Lob_Foreign_Lob; else if (fromBuffer()) so = Lob_Buffer; Lng32 waitedOp = 0; #ifdef __EID waitedOp = 0; // nowaited op from EID/TSE process #else waitedOp = 1; #endif //temptemp. Remove after ExLobsOper adds nowaited support. waitedOp = 1; // temp. Pass lobLen. When ExLobsOper fixes it so len is not needed during // lob desc update, then remove this. Int64 lobLen = getOperand(1)->getLength(); blackBoxLen_ = 0; if (fromExternal()) { blackBoxLen_ = getOperand(1)->getLength(); str_cpy_and_null(blackBox_, op_data[1], (Lng32)blackBoxLen_, '\0', ' ', TRUE); } Lng32 cliError = 0; char * lobData = NULL; lobData= new(h) char[lobLen]; //send lobData only if it's a lob_file operation if (so == Lob_File) { str_cpy_and_null(lobData,op_data[1],lobLen,'\0',' ',TRUE); } if (so == Lob_Buffer) { memcpy(&lobLen, op_data[2],sizeof(Int64)); } LobsOper lo ; if (lobOperStatus == CHECK_STATUS_) lo = Lob_Check_Status; else if (lobHandle == NULL) lo = Lob_InsertDataSimple; else lo = Lob_InsertDesc; rc = ExpLOBInterfaceInsert (getExeGlobals()->lobGlobal(), tgtLobName, lobStorageLocation(), lobStorageType(), getLobHdfsServer(), getLobHdfsPort(), handleLen, lobHandle, &outHandleLen_, outLobHandle_, blackBoxLen_, blackBox_, requestTag_, getExeGlobals()->lobGlobals()->xnId(), descSyskey, lo, &cliError, so, waitedOp, lobData, lobLen, getLobMaxSize(), getLobMaxChunkMemSize(),getLobGCLimit()); if (rc == LOB_ACCESS_PREEMPT) { // save the handle so it could be used after return from preempt lobHandleLenSaved_ = handleLen; str_cpy_all(lobHandleSaved_, lobHandle, handleLen); return ex_expr::EXPR_PREEMPT; } if (rc < 0) { Lng32 intParam1 = -rc; ExRaiseSqlError(h, diagsArea, (ExeErrorCode)(8442), NULL, &intParam1, &cliError, NULL, (char*)"ExpLOBInterfaceInsert", getLobErrStr(intParam1)); return ex_expr::EXPR_ERROR; } // extract and update lob handle with the returned values if (outHandleLen_ > 0) { ExpLOBoper::extractFromLOBhandle(NULL, NULL, NULL, NULL, &descSyskey, NULL, NULL, NULL, outLobHandle_); ExpLOBoper::updLOBhandle(descSyskey, 0, lobHandle); } str_cpy_all(result, lobHandle, handleLen); getOperand(0)->setVarLength(handleLen, op_data[-MAX_OPERANDS]); if (NOT fromExternal()) { getExeGlobals()->lobGlobals()->lobLoadInfo()-> setLobHandle(lobNum(), handleLen, lobHandle); } return ex_expr::EXPR_OK; }
// Extracts values from the string format of LOB handle Lng32 ExpLOBoper::extractFromLOBstring(Int64 &uid, Lng32 &lobNum, Int64 &descPartnKey, Int64 &descSyskey, Int16 &flags, Lng32 &lobType, short &schNameLen, char * schName, char * handle, Lng32 handleLen) { // opp of: //// // str_sprintf(lobHandleBuf, "LOBH%04d%020Ld%04d%02d%Ld%02d%Ld%03d%s", // str_sprintf(lobHandleBuf, "LOBH%04d%02d%04d%020d%02d%Ld%02d%Ld%03d%s", // header, flags, lobtype, lobNum, uid, descPartnKey, descSyskey, schNameLen/SchName if (handleLen < (4 + 4 + 2 + 4 + 20 + 2)) return -1; Lng32 curPos = 4; flags = (Lng32)str_atoi(&handle[curPos], 4); curPos += 4; lobType = (Lng32)str_atoi(&handle[curPos], 2); curPos += 2; lobNum = (Lng32)str_atoi(&handle[curPos], 4); curPos += 4; uid = str_atoi(&handle[curPos], 20); curPos += 20; short len1; len1 = (short)str_atoi(&handle[curPos], 2); curPos += 2; if (handleLen < (curPos + len1 + 2)) return -1; descPartnKey = str_atoi(&handle[curPos], len1); curPos += len1; short len2; len2 = (short)str_atoi(&handle[curPos], 2); curPos += 2; if (handleLen < (curPos + len2 + 3)) return -1; descSyskey = str_atoi(&handle[curPos], len2); curPos += len2; schNameLen = (short)str_atoi(&handle[curPos], 3); curPos += 3; if (handleLen < (curPos + schNameLen)) return -1; str_cpy_and_null(schName, &handle[curPos], schNameLen, '\0', ' ', TRUE); // flags = 0; return 0; }
// select exact bool CmpSeabaseDDLauth::selectExactRow(const NAString & cmd) { ExeCliInterface cliInterface(STMTHEAP); Int32 cliRC = cliInterface.fetchRowsPrologue(cmd.data(), true/*no exec*/); if (cliRC < 0) { cliInterface.retrieveSQLDiagnostics(CmpCommon::diags()); DDLException excp (cliRC, NULL, 0); excp.throwException(); } cliRC = cliInterface.clearExecFetchClose(NULL, 0); if (cliRC < 0) { cliInterface.retrieveSQLDiagnostics(CmpCommon::diags()); DDLException excp (cliRC, NULL, 0); excp.throwException(); } // if diags not cleared, then no error is returned -- ?? if (cliRC == 100) // did not find the row { cliInterface.clearGlobalDiags(); return false; } char * ptr = NULL; Lng32 len = 0; char type [6]; // value 1: auth_id (int32) cliInterface.getPtrAndLen(1, ptr, len); setAuthID(*(Int32*)ptr); // value 2: auth_db_name (NAString) cliInterface.getPtrAndLen(2,ptr,len); NAString dbName(ptr,len); setAuthDbName(dbName); // value 3: auth_ext_name (NAString) cliInterface.getPtrAndLen(3,ptr,len); NAString extName(ptr,len); setAuthExtName(extName); // value 4: auth_type (char) // str_cpy_and_null params: *tgt, *src, len, endchar, blank, null term cliInterface.getPtrAndLen(4,ptr,len); str_cpy_and_null(type, ptr, len, '\0', ' ', true); if ( type[0] == 'U') setAuthType(COM_USER_CLASS); else if (type[0] == 'R') setAuthType(COM_USER_CLASS); else setAuthType(COM_UNKNOWN_ID_CLASS); // value 5: auth_creator (int32) cliInterface.getPtrAndLen(5,ptr,len); setAuthCreator(*(Int32*)ptr); // value 6: auth_is_valid (char) cliInterface.getPtrAndLen(6,ptr,len); str_cpy_and_null(type, ptr, len, '\0', ' ', true); if (type[0] == 'Y') setAuthValid(true); else setAuthValid(false); // value 7: auth_create_time (int64) cliInterface.getPtrAndLen(7,ptr,len); Int64 intValue = *(Int64*)ptr; setAuthCreateTime((ComTimestamp) intValue); // value 8: auth_redef_time (int64) cliInterface.getPtrAndLen(8,ptr,len); intValue = *(Int64*)ptr; setAuthRedefTime((ComTimestamp) intValue); cliInterface.fetchRowsEpilogue(NULL, true); return true; }