コード例 #1
0
Lng32 SqlciRWInterfaceExecutor::printOutputRow(SqlciEnv * sqlci_env,
					      char * outputBuf,
					      Lng32 outputBufLen)
{
  Logfile *log = sqlci_env->get_logfile();

  log->WriteAll(outputBuf, outputBufLen, 0);

  return 0;
}
コード例 #2
0
short QueryId::process(SqlciEnv * sqlci_env)
{
  Lng32 retcode = 0;

  HandleCLIErrorInit();
  
  char * stmtName = get_argument();

  if ((stmtName) &&
      (! sqlci_env->get_prep_stmts()->get(stmtName)))
    {
       sqlci_env->diagsArea() << DgSqlCode(-SQLCI_STMT_NOT_FOUND)
				 << DgString0(stmtName);
       return 0;
    }

  Logfile *log = sqlci_env->get_logfile();
  char sprintfBuf[225];    

  if (!stmtName)
  {
    //try to find the last executed statement if present
    if (sqlci_env->lastExecutedStmt() && sqlci_env->lastExecutedStmt()->getStmtNameLen() > 0)
      stmtName = sqlci_env->lastExecutedStmt()->getStmtName();
    //if not, try to find the last prepared statement if present
    else if (sqlci_env->getLastAllocatedStmt() && sqlci_env->getLastAllocatedStmt()->identifier_len > 0)
      stmtName = (char *) sqlci_env->getLastAllocatedStmt()->identifier;
  }

  if (!stmtName) 
  // no statement name found Display error.
  {
    sprintf(sprintfBuf, "No statment found. Enter command with valid statement name.");
    log->WriteAll(sprintfBuf);
    return 0;
  }

  SQLSTMT_ID stmt;
  SQLMODULE_ID module;
  init_SQLMODULE_ID(&module);
  init_SQLSTMT_ID(&stmt, SQLCLI_CURRENT_VERSION, 
		  stmt_name, &module);

  char * id = new char[strlen(stmtName) + 1];
#pragma nowarn(1506)   // warning elimination 
  stmt.identifier_len = strlen(stmtName);
#pragma warn(1506)  // warning elimination 
  str_cpy_all(id,stmtName, 
	 stmt.identifier_len);
  id[stmt.identifier_len] = 0;
  stmt.identifier = id;
  char queryId[200];
  Lng32 queryIdLen;

  retcode = SQL_EXEC_GetStmtAttr(&stmt, SQL_ATTR_UNIQUE_STMT_ID,
                      NULL, queryId, 200, &queryIdLen); 
  delete [] id;

  if (queryIdLen < 200)
    queryId[queryIdLen] = 0;
  else
    queryId[199] = 0;

  HandleCLIError(retcode, sqlci_env);

  if (retcode == 0)
  {
    snprintf(sprintfBuf, 225, "QID is %s",queryId);
    log->WriteAll(sprintfBuf);
    log->WriteAll("");
  }  
    
  // display details of this query
  // for string attributes, use {type,maxLength,char[maxLength+1]}
  UNIQUEQUERYID_ATTR queryIdAttrs[11] =
  {
    {UNIQUEQUERYID_SEGMENTNUM, 0, 0},
    {UNIQUEQUERYID_SEGMENTNAME, 10, new char[11]},
    {UNIQUEQUERYID_CPU, 0, 0},
    {UNIQUEQUERYID_PIN, 0, 0},
    {UNIQUEQUERYID_EXESTARTTIME, 0, 0},
    {UNIQUEQUERYID_SESSIONNUM, 0, 0},
    {UNIQUEQUERYID_USERNAME, 24, new char[25]},
    {UNIQUEQUERYID_SESSIONNAME, 32, new char[33]},
    {UNIQUEQUERYID_QUERYNUM, 0, 0},
    {UNIQUEQUERYID_STMTNAME, 110, new char[111]},
    {UNIQUEQUERYID_SESSIONID, 104, new char[105]}
  };

  retcode = SQL_EXEC_GetUniqueQueryIdAttrs(queryId, queryIdLen,
                                           11, queryIdAttrs);
  HandleCLIError(retcode, sqlci_env);
  
  if (retcode == 0)
    {
      snprintf(sprintfBuf, 225, "QID details: ");
      log->WriteAll(sprintfBuf);
      log->WriteAll("============");

      // display UNIQUEQUERYID_SEGMENTNUM
      snprintf(sprintfBuf, 225, "  Segment Num:  " PFLL,queryIdAttrs[0].num_val_or_len);
      log->WriteAll(sprintfBuf);

      // display UNIQUEQUERYID_SEGMENTNAME
      snprintf(sprintfBuf, 225, "  Segment Name: %s",queryIdAttrs[1].string_val);
      log->WriteAll(sprintfBuf);

      // display UNIQUEQUERYID_CPU
      snprintf(sprintfBuf, 225, "  Cpu:          " PFLL,queryIdAttrs[2].num_val_or_len);
      log->WriteAll(sprintfBuf);

      // display UNIQUEQUERYID_PIN
      snprintf(sprintfBuf, 225, "  Pin:          " PFLL,queryIdAttrs[3].num_val_or_len);
      log->WriteAll(sprintfBuf);
 
      // UNIQUEQUERYID_EXESTARTTIME
      short startTimeArray[8];
      _int64 startTime = queryIdAttrs[4].num_val_or_len;
      short error;

      INTERPRETTIMESTAMP( CONVERTTIMESTAMP(startTime, 0, // GMT to LCT
                                                    -1, // use current node
                                                  &error), startTimeArray);
      sprintf(sprintfBuf, "  ExeStartTime: " PF64 "= %02d/%02d/%02d %02d:%02d:%02d.%03d%03d LCT",
                    startTime, startTimeArray[0],startTimeArray[1],startTimeArray[2],
                    startTimeArray[3], startTimeArray[4], startTimeArray[5],
                    startTimeArray[6], startTimeArray[7]);
      log->WriteAll(sprintfBuf);

      // display UNIQUEQUERYID_SESSIONNUM
      sprintf(sprintfBuf,"  SessionNum:   " PFLL,queryIdAttrs[5].num_val_or_len);
      log->WriteAll(sprintfBuf);

      // display UNIQUEQUERYID_USERNAME
      sprintf(sprintfBuf,"  UserName:     %s",queryIdAttrs[6].string_val);
      log->WriteAll(sprintfBuf);

      // display UNIQUEQUERYID_SESSIONNAME
      if (strlen(queryIdAttrs[7].string_val) > 0)
	sprintf(sprintfBuf,"  SessionName:  %s",queryIdAttrs[7].string_val);
      else
        sprintf(sprintfBuf,"  SessionName:  NULL");

      log->WriteAll(sprintfBuf);

      // display UNIQUEQUERYID_QUERYNUM
      sprintf(sprintfBuf,"  QueryNum:     " PFLL,queryIdAttrs[8].num_val_or_len);
      log->WriteAll(sprintfBuf);

      // display UNIQUEQUERYID_STMTNAME:
      sprintf(sprintfBuf,"  StmtName:     %s",queryIdAttrs[9].string_val);
      log->WriteAll(sprintfBuf);

      // display UNIQUEQUERYID_SESSIONID:
      sprintf(sprintfBuf,"  SessionId:    %s",queryIdAttrs[10].string_val);
      log->WriteAll(sprintfBuf);

      log->WriteAll("");
    }  
  
  return 0;
}
コード例 #3
0
short Env::process(SqlciEnv *sqlci_env)
{
  // ## Should any of this text come from the message file,
  // ## i.e. from a translatable file for I18N?


  // When adding new variables, please keep the information in 
  // alphabetic order
  Logfile *log = sqlci_env->get_logfile();

  log->WriteAll("----------------------------------");
  log->WriteAll("Current Environment");
  log->WriteAll("----------------------------------");
 

  bool authenticationEnabled = false;
  bool authorizationEnabled = false;
  bool authorizationReady = false;
  bool auditingEnabled = false;
  Int32 rc = sqlci_env->getAuthState(authenticationEnabled,
                                     authorizationEnabled,
                                     authorizationReady,
                                     auditingEnabled);

  // TDB: add auditing state
  log->WriteAllWithoutEOL("AUTHENTICATION     ");
  if (authenticationEnabled)
    log->WriteAll("enabled");
  else
    log->WriteAll("disabled");

  log->WriteAllWithoutEOL("AUTHORIZATION      ");
  if (authorizationEnabled)
    log->WriteAll("enabled");
  else
    log->WriteAll("disabled");

  log->WriteAllWithoutEOL("CURRENT DIRECTORY  ");

  // NT_PORT (bv 10/24/96) Added NA_MAX_PATH here and in common/Platform.h
  log->WriteAll(getcwd((char *)NULL, NA_MAX_PATH));


  log->WriteAllWithoutEOL("LIST_COUNT         ");
  char buf[100];
  Int32 len = sprintf(buf, "%u", sqlci_env->getListCount());
  if (len-- > 0)
    if (buf[len] == 'L' || buf[len] == 'l')
      buf[len] = '\0';
  log->WriteAll(buf);
  
  if (log->IsOpen())
    {
      log->WriteAllWithoutEOL("LOG FILE           ");
      log->WriteAll(log->Logname());
    }
  else
    {
      log->WriteAll("LOG FILE");
    }

  log->WriteAllWithoutEOL("MESSAGEFILE        ");
  const char *mf = GetErrorMessageFileName();
  log->WriteAll(mf ? mf : "");

#if 0
  log->WriteAllWithoutEOL("ISO88591 MAPPING   ");
  log->WriteAll(CharInfo::getCharSetName(sqlci_env->getIsoMappingCharset()));

  log->WriteAllWithoutEOL("DEFAULT CHARSET    ");
  log->WriteAll(CharInfo::getCharSetName(sqlci_env->getDefaultCharset()));

  log->WriteAllWithoutEOL("INFER CHARSET      ");
  log->WriteAll((sqlci_env->getInferCharset())?"ON":"OFF");
#endif

  // ## These need to have real values detected from the env and written out:

  // "US English" is more "politically correct" than "American English".
  //
  log->WriteAllWithoutEOL("MESSAGEFILE LANG   US English\n");

  log->WriteAllWithoutEOL("MESSAGEFILE VRSN   ");
  char vmsgcode[10];
  sprintf(vmsgcode, "%d", SQLERRORS_MSGFILE_VERSION_INFO);
#pragma nowarn(1506)   // warning elimination 
  Error vmsg(vmsgcode, strlen(vmsgcode), Error::ENVCMD_);
#pragma warn(1506)  // warning elimination 
  vmsg.process(sqlci_env);

  ComAnsiNamePart defaultCat;
  ComAnsiNamePart defaultSch;

  sqlci_env->getDefaultCatAndSch (defaultCat, defaultSch);
  CharInfo::CharSet TCS = sqlci_env->getTerminalCharset();
  CharInfo::CharSet ISOMAPCS = sqlci_env->getIsoMappingCharset();

  if(TCS !=
            CharInfo::UTF8
     )  {
      NAString dCat = defaultCat.getExternalName();
	  NAString dSch = defaultSch.getExternalName();
	  charBuf cbufCat((unsigned char*)dCat.data(), dCat.length());
	  charBuf cbufSch((unsigned char*)dSch.data(), dSch.length());
      NAWcharBuf* wcbuf = 0;
	  Int32 errorcode	= 0;
	  
	  wcbuf = csetToUnicode(cbufCat, 0, wcbuf, CharInfo::UTF8, errorcode);
	  NAString* tempstr;
	  if (errorcode != 0){
	    tempstr = new NAString(defaultCat.getExternalName().data()); 
	  }
	  else {				
	    tempstr = unicodeToChar(wcbuf->data(),wcbuf->getStrLen(), TCS, NULL, TRUE);
	    TrimNAStringSpace(*tempstr, FALSE, TRUE);  // trim trailing blanks
	  }
      log->WriteAllWithoutEOL("SQL CATALOG        ");
      log->WriteAll(tempstr->data());

	  // Default Schema

	  wcbuf = 0;  // must 0 out to get next call to allocate memory.
	  wcbuf = csetToUnicode(cbufSch, 0, wcbuf, CharInfo::UTF8, errorcode);
	  if (errorcode != 0){
	    tempstr = new NAString(defaultSch.getExternalName().data()); 
	  }
	  else {				
	    tempstr = unicodeToChar(wcbuf->data(),wcbuf->getStrLen(), TCS, NULL, TRUE);
	    TrimNAStringSpace(*tempstr, FALSE, TRUE);  // trim trailing blanks
	  }
       log->WriteAllWithoutEOL("SQL SCHEMA         ");
       log->WriteAll(tempstr->data());
	}
	else
	{
  log->WriteAllWithoutEOL("SQL CATALOG        ");
  log->WriteAll(defaultCat.getExternalName());
  log->WriteAllWithoutEOL("SQL SCHEMA         ");
  log->WriteAll(defaultSch.getExternalName());
  }

  // On Linux we include the database user name and user ID in the
  // command output
  NAString username;
  rc = sqlci_env->getExternalUserName(username);
  log->WriteAllWithoutEOL("SQL USER CONNECTED "); 
  if (rc >= 0)
    log->WriteAll(username.data());
  else
    log->WriteAll("?");

  rc = sqlci_env->getDatabaseUserName(username);
  log->WriteAllWithoutEOL("SQL USER DB NAME   ");
  if (rc >= 0)
    log->WriteAll(username.data());
  else
    log->WriteAll("?");
  
  Int32 uid = 0;
  rc = sqlci_env->getDatabaseUserID(uid);
  log->WriteAllWithoutEOL("SQL USER ID        ");
  if (rc >= 0)
    sprintf(buf, "%d", (int) uid);
  else
    strcpy(buf, "?");
  log->WriteAll(buf);
  
  log->WriteAllWithoutEOL("TERMINAL CHARSET   ");
  log->WriteAll(CharInfo::getCharSetName(sqlci_env->getTerminalCharset()));

  Int64 transid;
  if (sqlci_env->statusTransaction(&transid))
    {
      // transaction is active.
      char transid_str[20];
      convertInt64ToAscii(transid, transid_str);
      log->WriteAllWithoutEOL("TRANSACTION ID     ");
      log->WriteAll(transid_str);
      log->WriteAll("TRANSACTION STATE  in progress");
    }  
  else
    {
      log->WriteAll("TRANSACTION ID     ");
      log->WriteAll("TRANSACTION STATE  not in progress");
    }

  if (log->isVerbose())
    log->WriteAll("WARNINGS           on");
  else
    log->WriteAll("WARNINGS           off");
  
  return 0;  
}