CmpStatement::ReturnStatus
CmpStatement::process (const CmpMessageSQLText& sqltext)
{
  CmpMain cmpmain;

  CMPASSERT(sqltext.getCmpCompileInfo());
  
  char * sqlStr = NULL;
  Int32 sqlStrLen = 0;
  Lng32 inputCS = 0;
  NAString currCatName;
  NAString currSchName;
  char * recompControlInfo = NULL;
  NABoolean isSchNameRecvd;
  NABoolean nametypeNsk;
  NABoolean odbcProcess;
  NABoolean noTextCache;
  NABoolean aqrPrepare;
  NABoolean standaloneQuery;
  if (processRecvdCmpCompileInfo(this,
				 sqltext,
  				 sqltext.getCmpCompileInfo(),
				 context_,
				 sqlStr, 
				 sqlStrLen, // out - long &
				 inputCS,
				 isSchNameRecvd, 
				 currCatName, currSchName, 
				 recompControlInfo,
				 nametypeNsk,
				 odbcProcess,
				 noTextCache,
				 aqrPrepare,
				 standaloneQuery))
    return CmpStatement_ERROR;

  reply_ = new(outHeap_) CmpMessageReplyCode( outHeap_, sqltext.id(), 0, 0, outHeap_);
  
  if ((sqlStr) && inputCS == SQLCHARSETCODE_ISO88591 &&
      (strncmp(sqlStr, "select $ZZDEBUG", strlen("select $ZZDEBUG")) == 0))
    {
      NADebug();
    }


 // If this is an ODBC query transmit inputArrayMaxsize and rowsetAtomicity information 
 // (used for binding rowsets as input parameters) from CLI into cmpmain
 // so that it can be used during binding.
  if ((CmpCommon::getDefault(ODBC_PROCESS) == DF_ON) ||
      (CmpCommon::getDefault(JDBC_PROCESS) == DF_ON))
  {
    cmpmain.setInputArrayMaxsize(sqltext.getCmpCompileInfo()->getInputArrayMaxsize());
    cmpmain.setRowsetAtomicity(sqltext.getCmpCompileInfo()->getRowsetAtomicity());
  }
  cmpmain.setHoldableAttr(sqltext.getCmpCompileInfo()->getHoldableAttr());
 
  FragmentDir * fragmentDir = NULL;
  IpcMessageObjType typ = sqltext.getType();

  //
  //if this is a recompilation
  if (typ == CmpMessageObj::SQLTEXT_RECOMPILE) {
    recompiling_ = TRUE;
  }
 
  // A pointer to user SQL query is stored in CmpStatement; if an exception is
  // thrown the user query is copied from here. It is reset upon return from
  // sqlcomp() method.
  sqlTextStr_ = sqlStr;
  sqlTextLen_ = sqlStrLen;
  sqlTextCharSet_ = inputCS;

  QueryText qText(sqlStr, inputCS);
  cmpmain.setSqlParserFlags(sqltext.getFlags());

  NABoolean qtcChanged = FALSE;
  if ((CmpCommon::getDefault(QUERY_TEXT_CACHE) == DF_SYSTEM) &&
      (aqrPrepare || noTextCache))
    {
      CMPASSERT(NOT (aqrPrepare && noTextCache));

      qtcChanged = TRUE;
      NAString op(((aqrPrepare && standaloneQuery) ? "SKIP" : "OFF"));
      context_->schemaDB_->getDefaults().validateAndInsert("QUERY_TEXT_CACHE", op, FALSE);
    }

  CmpMain::ReturnStatus rs = CmpMain::SUCCESS;
  try
  {
    rs =
    cmpmain.sqlcomp(qText, 0, 
		    &(reply_->data()), &(reply_->size()),
		    reply_->outHeap(), CmpMain::END, 
		    &fragmentDir, typ);
  }
  catch (...)
  {
    error(arkcmpErrorNoDiags,sqlStr);
    return CmpStatement_ERROR;
  }

  sqlTextStr_ = NULL;
  
  ((CmpMessageReplyCode *)reply_)->setFragmentDir(fragmentDir);

  // restore the original cat & schema names before returning.
  if (isSchNameRecvd)
    {
      context_->schemaDB_->getDefaults().setCatalogTrustedFast(currCatName);
      context_->schemaDB_->getDefaults().setSchemaTrustedFast(currSchName);
    }

  if (qtcChanged)
    {
      // restore the original query text cache setting
      NAString op("SYSTEM");
      context_->schemaDB_->getDefaults().validateAndInsert("QUERY_TEXT_CACHE", op, FALSE);
    }

  if (rs)
    {
      error(arkcmpErrorNoDiags,sqlStr);
      return CmpStatement_ERROR;
    }

  return CmpStatement_SUCCESS;
}
Пример #2
0
void DoEspStartup(Int32 argc,
		  char **argv,
		  IpcEnvironment &env,
		  ExEspFragInstanceDir &fragInstanceDir,
		  GuaReceiveFastStart *guaReceiveFastStart)
{
  // make the compiler happy by using fragInstanceDir for something
  if (fragInstanceDir.getNumEntries() < 0)
    {}

  // interpret command line arguments
  IpcServerAllocationMethod allocMethod = IPC_ALLOC_DONT_CARE;

  Int32 currArg = 1;

  Int32 socketArg = 0;
  Int32 portArg = 0;

  while (currArg < argc)
    {
      if (strcmp("-fork", argv[currArg]) == 0)
        {
	  allocMethod = IPC_POSIX_FORK_EXEC;
        }
      else if (strcmp("-service", argv[currArg]) == 0)
	{
	  // /etc/inetd.conf should be configured such that the "-service"
	  // command line option is given
	  allocMethod = IPC_INETD;
	}
      else if (strcmp("-guardian", argv[currArg]) == 0)
	{
	  allocMethod = IPC_LAUNCH_GUARDIAN_PROCESS;
	}
      else if (strcmp("-noespfaststart", argv[currArg]) == 0)
	;
      else if (strcmp("-debug", argv[currArg]) == 0)
	{
	  NADebug();
	}
      else
	{
	  // bad arguments, die
	  NAExit(-1);
	}

      currArg++;
    }


  // create control connection (open $RECEIVE in Tandemese)
  switch (allocMethod)
    {
    case IPC_LAUNCH_GUARDIAN_PROCESS:
    case IPC_SPAWN_OSS_PROCESS:
      {
      // open $RECEIVE with a receive depth of 4000

	 GuaReceiveControlConnection *cc =
				  
	 new(&env) EspGuaControlConnection(&env,
					  &fragInstanceDir,
					  4000,
					  guaReceiveFastStart);
      env.setControlConnection(cc);

      // wait for the first open message to come in
      cc->waitForMaster();
      // set initial timeout in case the master never send first plan message
      env.setIdleTimestamp();
      }
     break;
      
    case IPC_INETD:
    case IPC_POSIX_FORK_EXEC:
      env.setControlConnection(
	   new(&env) EspSockControlConnection(&env,&fragInstanceDir));

      break;
      // NEEDS PORT (12/16/96) 
      //	handle the local NT process case without NSK-like

    case IPC_LAUNCH_NT_PROCESS:

      //debugging code - figure out later
      // the name of this machine on which this process is executing
      char myMachine[IpcNodeNameMaxLength];
      char errorLine[64];
      Int32  result;

      // who am I?
      result = gethostname(myMachine,IpcNodeNameMaxLength);
      if (!result)
	{
	  sprintf(errorLine," DoEspStartup : gethostname : error %d",result);
	  ABORT(errorLine);
	};
      // end debugging code
      env.setControlConnection(
	   new(&env) EspSockControlConnection(
		&env,&fragInstanceDir,socketArg, portArg));
      break;
      
    default:
      // bad command line arguments again
      NAExit(-1);
    }
}