Esempio n. 1
0
ex_expr::exp_return_type ExpLOBinsert::eval(char *op_data[],
					    CollHeap*h,
					    ComDiagsArea** diagsArea)
{
  ex_expr::exp_return_type err;

  err = insertDesc(op_data, h, diagsArea);
  if (err == ex_expr::EXPR_ERROR)
    return err;
    

#ifndef __EID
  char * handle = op_data[0];
  Lng32 handleLen = getOperand(0)->getLength();
  err = insertData(handleLen, handle, op_data, h, diagsArea);
#endif

  return err;
}
ex_expr::exp_return_type ExpLOBupdate::eval(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];

  char * lobHandle = NULL;
  Lng32 handleLen = 0;

  Lng32 sLobType;
  Int64 sUid;
  Lng32 sLobNum;
  Int64 sDescSyskey = -1;
  Int64 sDescTS = -1;
  Int16 sFlags;
  short sSchNameLen = 0;
  char sSchName[500];

  if (getOperand(2)->getNullFlag() &&
      nullValue_)
    {
      ex_expr::exp_return_type err = insertDesc(op_data, h, diagsArea);
      if (err == ex_expr::EXPR_ERROR)
	return err;
     
      char * handle = op_data[0];
      handleLen = getOperand(0)->getLength();
      err = insertData(handleLen, handle, op_data, h, diagsArea);
     
      return err;

    }
  else
    {
      lobHandle = op_data[2];

      handleLen = getOperand(2)->getLength(op_data[-MAX_OPERANDS+2]);
    }
     
  extractFromLOBhandle(&sFlags, &sLobType, &sLobNum, &sUid,
		       &sDescSyskey, &sDescTS, 
		       &sSchNameLen, sSchName,
		       lobHandle); //op_data[2]);

  // get the lob name where data need to be updated
  char tgtLobNameBuf[100];
  char * tgtLobName = ExpGetLOBname(sUid, sLobNum, tgtLobNameBuf, 100);

  if (tgtLobName == NULL)
    return ex_expr::EXPR_ERROR;

  char fromLobNameBuf[100];
  char * fromLobName = NULL;
  Int64 fromDescKey = 0;
  Int64 fromDescTS = 0;
  short fromSchNameLen = 0;
  char  fromSchName[500];
  if (0) // TBD. fromLob())
    {
      Lng32 fromLobType;
      Int64 fromLobUid;
      Lng32 fromLobNum;
      Int16 fromFlags;
      extractFromLOBhandle(&fromFlags, &fromLobType, &fromLobNum, &fromLobUid,
			   &fromDescKey, &fromDescTS, 
			   &fromSchNameLen, fromSchName,
			   op_data[1]);

      // get the lob name where data will be read from
      fromLobName = ExpGetLOBname(fromLobUid, fromLobNum, fromLobNameBuf, 100);
      if (fromLobName == NULL)
	return ex_expr::EXPR_ERROR;
    }

  LobsSubOper so = Lob_None;
  if (fromFile())
    so = Lob_File;
  else if (fromString())
    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;

  // call function with the lobname and source value
  // to update it in the LOB.
  // Get back offset and len of the LOB.
  //  Int64 offset = 0;
  Int64 lobLen = getOperand(1)->getLength();
  char * data = op_data[1];
  if (fromBuffer())
    {
      memcpy(&lobLen, op_data[3],sizeof(Int64)); // user specified buffer length
      memcpy(data,op_data[1],sizeof(Int64)); // user buffer address
    }
  if (isAppend())
    {
      rc = ExpLOBInterfaceUpdateAppend
	(getExeGlobals()->lobGlobal(), 
	 getLobHdfsServer(),
	 getLobHdfsPort(),
	 tgtLobName, 
	 lobStorageLocation(),
	 handleLen, lobHandle,
	 &outHandleLen_, outLobHandle_,
	 requestTag_,
	 getExeGlobals()->lobGlobals()->xnId(),
	 
	 (lobOperStatus == CHECK_STATUS_ ? 1 : 0),
	 waitedOp,
	 so,
	 sDescSyskey,
	 lobLen, 
	 data,
	 fromLobName, fromSchNameLen, fromSchName,
	 fromDescKey, fromDescTS,
	 getLobMaxSize(), getLobMaxChunkMemSize(),getLobGCLimit());
    }
  else
    {
      rc = ExpLOBInterfaceUpdate
	(getExeGlobals()->lobGlobal(), 
	 getLobHdfsServer(),
	 getLobHdfsPort(),
	 tgtLobName, 
	 lobStorageLocation(),
	 handleLen, lobHandle,
	 &outHandleLen_, outLobHandle_,
	 requestTag_,
	 getExeGlobals()->lobGlobals()->xnId(),
	 
	 (lobOperStatus == CHECK_STATUS_ ? 1 : 0),
	 waitedOp,
	 so,
	 sDescSyskey,
	 lobLen, 
	 data,
	 fromLobName, fromSchNameLen, fromSchName,
	 fromDescKey, fromDescTS,
	 getLobMaxSize(), getLobMaxChunkMemSize(),getLobGCLimit());
    }

  if (rc < 0)
    {
      Lng32 intParam1 = -rc;
      ExRaiseSqlError(h, diagsArea, 
		      (ExeErrorCode)(8442), NULL, &intParam1, 
		      &cliError, NULL, (char*)"ExpLOBInterfaceUpdate",
		      getLobErrStr(intParam1));
      return ex_expr::EXPR_ERROR;
    }

  // update lob handle with the returned values
  str_cpy_all(result, lobHandle, handleLen);
  //     str_cpy_all(result, op_data[2], handleLen);
  //     ExpLOBoper::updLOBhandle(sDescSyskey, 0, result); 
  getOperand(0)->setVarLength(handleLen, op_data[-MAX_OPERANDS]);

  return ex_expr::EXPR_OK;
}