void SqlciEnv::pertableStatistics()
{
  // Turn on pertable statistics. This will make queries issued
  // from sqlci to collect pertable statistics and will be the
  // same behavior as sql/mp.
  //
  // This function is called during the initialization phase of MXCI
  // (SqlciEnv_prologue_to_run). Use specialERROR_ as a flag indicating that
  // the querry being executed is invoke during MXCI's initialization phase and
  // that any errors will be fatal.

  char * buf = new char[300];
  sprintf(buf, "select variable_info from table(statistics(null, cast(? as char(256) character set iso88591)))");
  SqlCmd sqlCmd(SqlCmd::DML_TYPE, buf);
  if (!statsStmt_)
    {
      statsStmt_ = new PrepStmt("__SQLCI_GET_STATS__");

      short retcode = sqlCmd.do_prepare(this, statsStmt_, sqlCmd.get_sql_stmt(), FALSE);
    }
  char *collectionType = getenv("SQLMX_REGRESS");
  if (collectionType == NULL)
  {
    strcpy(buf, "SET SESSION DEFAULT STATISTICS_VIEW_TYPE 'PERTABLE';");
    SqlCmd::executeQuery(buf, this);
    if (!specialError_)
    {
      char *noexit = getenv("SQL_MXCI_NO_EXIT_ON_COMPILER_STARTUP_ERROR");
      if (!noexit)
        exit(EXIT_FAILURE);
    }
  }
  delete [] buf;
 }
Exemple #2
0
short Shape::processNextStmt(SqlciEnv * sqlci_env, FILE * fStream)
{
  short retcode = 0;

  enum ShapeState 
   {
     PROCESS_STMT, DONE
   };

  Int32 done = 0;
  Int32 ignore_toggle = 0;
  ShapeState state;
  InputStmt * input_stmt;
  SqlciNode * sqlci_node = NULL;

  state = PROCESS_STMT;

  while (!done)
    {
      input_stmt = new InputStmt(sqlci_env);
      Int32 read_error = 0;
      if (state != DONE)
	{
	  read_error = input_stmt->readStmt(fStream, TRUE);
	  
	  if (feof(fStream) || read_error == -99)
	    {
	      if (!input_stmt->isEmpty() && read_error != -4)
		{
		  // Unterminated statement in obey file.
		  // Make the parser emit an error message.
		  input_stmt->display((UInt16)0, TRUE);
		  input_stmt->logStmt(TRUE);
		  input_stmt->syntaxErrorOnEof();
		}
	      state = DONE;
	    } // feof or error (=-99)
	}
      
      // if there is an eof directly after a statement
      // that is terminated with a semi-colon, process the
      // statement
      if (read_error == -4) state = PROCESS_STMT;
      
      switch (state)
	{
	case PROCESS_STMT:
	  {
	    Int32 ignore_stmt = input_stmt->isIgnoreStmt();
	    if (ignore_stmt)
	      ignore_toggle = ~ignore_toggle;
	    
	    if (ignore_stmt || ignore_toggle || input_stmt->ignoreJustThis())
	      {
		// ignore until stmt following the untoggling ?ignore
		sqlci_DA.clear();
	      }
	    else
	      {
		if (!read_error || read_error == -4)
		  {
		    sqlci_parser(input_stmt->getPackedString(),
				 input_stmt->getPackedString(),
				 &sqlci_node,sqlci_env);
		    if ((sqlci_node) &&
			(sqlci_node->getType() == SqlciNode::SQL_CMD_TYPE))
		      {
			delete sqlci_node;

			SqlCmd sqlCmd(SqlCmd::DML_TYPE, NULL);
			
			short retcode = sqlCmd.showShape(sqlci_env, 
							 input_stmt->getPackedString());
			if (retcode)
			{
			  delete input_stmt;
			  return retcode;
			}
		      }

		    input_stmt->display((UInt16)0, TRUE);
		    input_stmt->logStmt(TRUE);
		  }
		
		sqlci_env->displayDiagnostics() ;
		
		// Clear the DiagnosticsArea for the next command...
		sqlci_DA.clear();
		    
		// if an EXIT statement was seen, then a -1 will be returned
		// from process. We are done in that case.
		if (retcode == -1)
		  state = DONE;
	      }
	  }
	break;
	
	case DONE:
	  {
	    done = -1;
  	  }
	break;
	
	default:
	  {
	  }
	break;
	
	} // switch on state
      
      delete input_stmt;
      
    } // while not done

  return 0;
}