Exemplo n.º 1
0
short ResetViolation::process(SqlciEnv * sqlciEnv){
  Lng32 firstRetCode = SQL_EXEC_SetUdrAttributes_Internal(mode_, 0/* maxRSets */);
  Lng32 secondRetCode = SQL_EXEC_ResetUdrErrorFlags_Internal();
  if(((enum RETCODE) firstRetCode == SUCCESS) &&
     ((enum RETCODE) secondRetCode == SUCCESS)){
    cerr << "success -- " << endl;
  }
  else{
    cerr << "error -- " << endl;
    if((enum RETCODE) firstRetCode != SUCCESS)
      HandleCLIError(firstRetCode, sqlciEnv);
    else
      HandleCLIError(secondRetCode, sqlciEnv);
  }
  return 0;
}
Exemplo n.º 2
0
short ResetContext::process(SqlciEnv * sqlciEnv)
{
  Lng32 retCode = SQL_EXEC_ResetContext(ctxHdl_, NULL);
  if((enum RETCODE) retCode == SUCCESS){
    cerr << "success --" << endl;
  }
  else{
    cerr << "error --" << endl;
    HandleCLIError(retCode, sqlciEnv);
  }
  return 0;
}
Exemplo n.º 3
0
short CurrentContext::process(SqlciEnv * sqlciEnv)
{
  SQLCTX_HANDLE ctxhdl = 0;
  Lng32 retCode = SQL_EXEC_CurrentContext(&ctxhdl);
  if((enum RETCODE) retCode == SUCCESS){
    cerr << "success -- current handle:" << ctxhdl << endl;
  }
  else{
    cerr << "error -- " << endl;
    HandleCLIError(retCode, sqlciEnv);
  }
  return 0;
}
Exemplo n.º 4
0
short SwitchContext::process(SqlciEnv * sqlciEnv)
{
  SQLCTX_HANDLE ctxhdl = 0;
  Lng32 retCode = SQL_EXEC_SwitchContext(ctxHdl_, &ctxhdl);
  if((enum RETCODE) retCode == SUCCESS){
    cerr << "success -- previous handle: " << ctxhdl << endl;
  }
  else{
    cerr << "error --" << endl;
    HandleCLIError(retCode, sqlciEnv);
  }
  return 0;
}  
Exemplo n.º 5
0
// returns -1, if a transaction is active; 0, otherwise.
// Optionally returns the transaction identifier, if transid is passed in.
short SqlciEnv::statusTransaction(Int64 * transid)
{
  // if a transaction is active, get the transid by calling the CLI procedure. 
  SQLDESC_ID transid_desc; // added for multi charset module names
  SQLMODULE_ID module;

  init_SQLCLI_OBJ_ID(&transid_desc);
  init_SQLMODULE_ID(&module);

  module.module_name = 0;
  transid_desc.module = &module;
  transid_desc.name_mode = desc_handle;

  HandleCLIErrorInit();
  
  Lng32 rc = SQL_EXEC_AllocDesc(&transid_desc, 1);

  HandleCLIError(rc, this);
  
  Int64 transid_;
  rc = SQL_EXEC_SetDescItem(&transid_desc, 1, SQLDESC_VAR_PTR,
			    (Long)&transid_, 0);
  if (rc)
    SQL_EXEC_DeallocDesc(&transid_desc);
  HandleCLIError(rc, this);
  
  rc = SQL_EXEC_Xact(SQLTRANS_STATUS, &transid_desc);
  if (rc == 0)
    {
      if (transid) *transid = transid_;	// return transID if arg was passed in.
      rc = -1;				// transaction is active.
    }
  else
    rc = 0;
  SQL_EXEC_DeallocDesc(&transid_desc);
	
  return (short)rc;
	
}
Exemplo n.º 6
0
short CreateContext::process(SqlciEnv * sqlciEnv)
{
  SQLCTX_HANDLE ctxhdl = 0;
  Lng32 retCode = SQL_EXEC_CreateContext(&ctxhdl, NULL, noAutoXact_);

  if((enum RETCODE) retCode == SUCCESS){
    cerr << "success -- new handle:" << ctxhdl << endl;
  }
  else{
    cerr << "error -- " << endl;
    HandleCLIError(retCode, sqlciEnv);
  }
  return 0;
}
Exemplo n.º 7
0
// Retrieve the database user ID from CLI
Int32 SqlciEnv::getDatabaseUserID(Int32 &uid)
{
  HandleCLIErrorInit();

  Int32 localUID = 0;
  Int32 rc = SQL_EXEC_GetSessionAttr(SESSION_DATABASE_USER_ID,
                                     &localUID,
                                     NULL, 0, NULL);
  HandleCLIError(rc, this);

  if (rc >= 0)
    uid = localUID;

  return rc;
}
Exemplo n.º 8
0
// Retrieve the database user ID from CLI
Int32 SqlciEnv::getAuthState(bool &authenticationEnabled,
                             bool &authorizationEnabled,
                             bool &authorizationReady,
                             bool &auditingEnabled)
{
  HandleCLIErrorInit();

  Int32 localUID = 0;
  Int32 rc = SQL_EXEC_GetAuthState_Internal(authenticationEnabled,
                                            authorizationEnabled,
                                            authorizationReady,
                                            auditingEnabled);
  HandleCLIError(rc, this);

  return rc;
}
Exemplo n.º 9
0
// Retrieve the external database user ID from CLI
Int32 SqlciEnv::getExternalUserName(NAString &username)
{
  HandleCLIErrorInit();

  char buf[1024] = "";
  Int32 rc = SQL_EXEC_GetSessionAttr(SESSION_EXTERNAL_USER_NAME,
                                     NULL,
                                     buf, 1024, NULL);
  HandleCLIError(rc, this);

  if (rc >= 0)
    username = buf;

  if (username.length() == 0)
   username = "******";
  return rc;
}
Exemplo n.º 10
0
// Retrieve the database user name from CLI. This will be the
// USER_NAME column from a USERS row not the EXTERNAL_USER_NAME
// column.
Int32 SqlciEnv::getDatabaseUserName(NAString &username)
{
  HandleCLIErrorInit();

  char buf[1024] = "";
  Int32 rc = SQL_EXEC_GetSessionAttr(SESSION_DATABASE_USER_NAME,
                                     NULL,
                                     buf, 1024, NULL);
  HandleCLIError(rc, this);

  if (rc >= 0)
    username = buf;

  if (rc != 0)
    SQL_EXEC_ClearDiagnostics(NULL);

  return rc;
}
Exemplo n.º 11
0
short CheckViolation::process(SqlciEnv * sqlciEnv){
  Lng32 sqlViolation, xactViolation, xactWasAborted;
  Lng32 udrErrorFlags = 0;
  Lng32 retCode =  SQL_EXEC_GetUdrErrorFlags_Internal(&udrErrorFlags);
  if((enum RETCODE) retCode == SUCCESS){
    sqlViolation = udrErrorFlags & SQLUDR_SQL_VIOL;
    xactViolation = udrErrorFlags & SQLUDR_XACT_VIOL;
    xactWasAborted = udrErrorFlags & SQLUDR_XACT_ABORT; 
    cerr << "success -- " << endl;
    cout << "sqlViolation:" << (sqlViolation ? "YES" : "NO") << endl;
    cout << "xactViolation:" << (xactViolation ? "YES" : "NO") << endl;
    cout << "xactWasAborted:" << (xactWasAborted ? "YES" : "NO") << endl;
  }
  else{
    cerr << "error -- " << endl;
  }
  HandleCLIError(retCode, sqlciEnv);
  return 0;
}
Exemplo n.º 12
0
// If a user name was specified on the command line, call CLI to set
// the database user identity.
void SqlciEnv::setUserIdentityInCLI()
{
  if (userNameFromCommandLine_.length() > 0)
  {
    // Within this function we do not want CLI errors to be
    // fatal. Setting specialError_ to 0 ensures they are not. We also
    // save the current value of specialError_ and restore if after
    // the CLI calls.
    Lng32 previousSpecialError = specialError_;
    specialError_ = 0;

    HandleCLIErrorInit();

    Lng32 sqlcode =
      SQL_EXEC_SetSessionAttr_Internal(SESSION_DATABASE_USER_NAME,
                                       0,
                                       (char *) userNameFromCommandLine_.data());
    HandleCLIError(sqlcode, this);

    if (sqlcode >= 0)
      printf("\nDatabase user: %s\n\n", userNameFromCommandLine_.data());

    if (sqlcode != 0)
      SQL_EXEC_ClearDiagnostics(NULL);

    specialError_ = previousSpecialError;
  }
  else
  {
    // Call CLI to retrieve the current user identity. This is only
    // done to see if CLI generates errors or warnings that we should
    // display. For example, CLI was not able to establish a default
    // user identity, perhaps metadata is corrupt, we should display
    // that information.
    Int32 uid = 0;
    getDatabaseUserID(uid);
  }
}
Exemplo n.º 13
0
short SetInferCharset::process(SqlciEnv * sqlci_env)
{
  HandleCLIErrorInit();

  char* ics = get_argument();
  Int32 ics_len;

#pragma nowarn(1506)   // warning elimination 
  if ( ics != NULL && ((ics_len=strlen(ics)) <= 128) )
#pragma warn(1506)  // warning elimination 
  {
     char ics_uppercase[129];
     str_cpy_convert(ics_uppercase, ics, ics_len, 1);
     ics_uppercase[ics_len] = 0;

     if ( strcmp(ics_uppercase, "FALSE") != 0 &&
          strcmp(ics_uppercase, "TRUE" ) != 0 &&
          strcmp(ics_uppercase, "0"    ) != 0 &&
          strcmp(ics_uppercase, "1"    ) != 0 )
     {
       // 15001 42000 99999 BEGINNER MAJOR DBADMIN
       // A syntax error occurred at or before: $0~string0
       ErrorParam *ep = new ErrorParam(ics);
       SqlciError (15001,
                   ep,
                   (ErrorParam *) 0
                  );
       delete ep;
       return 0;
     }

     char cqd_stmt[200]; // charset name can be up to 128 bytes long

     sprintf(cqd_stmt, "CONTROL QUERY DEFAULT INFER_CHARSET '%s';",
                       ics_uppercase
            );

     Lng32 retcode = SqlCmd::executeQuery(cqd_stmt, sqlci_env);

     if ( retcode == 0 )
     {
       if ( ics_uppercase[0] == '1' || ics_uppercase[0] == 'T'/*RUE*/)
         sqlci_env -> setInferCharset(TRUE);
       else
         sqlci_env -> setInferCharset(FALSE);
     }
     else
       HandleCLIError(retcode, sqlci_env);

  } else {
    // 15001 42000 99999 BEGINNER MAJOR DBADMIN
    // A syntax error occurred at or before: $0~string0
    ErrorParam *ep;
    if (ics)
      ep = new ErrorParam(ics);
    else
      ep = new ErrorParam("INFER_CHARSET");
    SqlciError (15001,
                ep,
                (ErrorParam *) 0
                );
    delete ep;
  }

  return 0;
}
Exemplo n.º 14
0
short SetDefaultCharset::process(SqlciEnv * sqlci_env)
{
  HandleCLIErrorInit();

  char* dcs = get_argument();
  Int32 dcs_len;

#pragma nowarn(1506)   // warning elimination 
  if ( dcs != NULL && ((dcs_len=strlen(dcs)) <= 128) )
#pragma warn(1506)  // warning elimination 
  {
     char dcs_uppercase[129];
     str_cpy_convert(dcs_uppercase, dcs, dcs_len, 1);
     dcs_uppercase[dcs_len] = 0;

     if ( strcmp(dcs_uppercase, "ISO88591") != 0 &&
          strcmp(dcs_uppercase, "UTF8"    ) != 0 &&
          strcmp(dcs_uppercase, "SJIS"    ) != 0
          )
     {
       // 15001 42000 99999 BEGINNER MAJOR DBADMIN
       // A syntax error occurred at or before: $0~string0
       ErrorParam *ep = new ErrorParam(dcs);
       SqlciError (15001,
                   ep,
                   (ErrorParam *) 0
                  );
       delete ep;
       return 0;
     }

     char cqd_stmt[200]; // charset name can be up to 128 bytes long

     sprintf(cqd_stmt, "CONTROL QUERY DEFAULT DEFAULT_CHARSET '%s';",
                       dcs_uppercase
            );

     Lng32 retcode = SqlCmd::executeQuery(cqd_stmt, sqlci_env);

     if ( retcode == 0 )
       sqlci_env -> setDefaultCharset(CharInfo::getCharSetEnum(dcs_uppercase));
     else
       HandleCLIError(retcode, sqlci_env);

  } else {
    // 15001 42000 99999 BEGINNER MAJOR DBADMIN
    // A syntax error occurred at or before: $0~string0
    ErrorParam *ep;
    if (dcs)
      ep = new ErrorParam(dcs);
    else
      ep = new ErrorParam("DEFAULT_CHARSET");
    SqlciError (15001,
                ep,
                (ErrorParam *) 0
                );
    delete ep;
  }

  return 0;
}
Exemplo n.º 15
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;
}