Exemplo n.º 1
0
short SetTerminalCharset::process(SqlciEnv * sqlci_env)
{
  HandleCLIErrorInit();

  char* tcs = get_argument();
  Int32 tcs_len;

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

     if ( CharInfo::isCharSetSupported(tcs_uppercase) == FALSE )
     {
      SqlciError (SQLCI_INVALID_TERMINAL_CHARSET_NAME_ERROR,
		  (ErrorParam *) 0
		 );
      return 0;
     }

     if ( CharInfo::isTerminalCharSetSupported(tcs_uppercase) == FALSE ) 
     {
      ErrorParam *ep = new ErrorParam(tcs);
      SqlciError (2038,
		  ep,
		  (ErrorParam *) 0
		 );
      delete ep;
      return 0;
     }

// The following code had been commented out but has been restored
//  for the charset project		CQD removed on 12/11/2007
/*
     char cqd_stmt[200]; // charset name can be up to 128 bytes long

     sprintf(cqd_stmt, "CONTROL QUERY DEFAULT TERMINAL_CHARSET '%s';",
                       tcs_uppercase
            );

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

     if ( retcode == 0 )*/
       sqlci_env -> setTerminalCharset(
                     CharInfo::getCharSetEnum(tcs_uppercase)
                                      );
//     else
//       HandleCLIError(retcode, sqlci_env);


  } else 
      SqlciError (SQLCI_INVALID_TERMINAL_CHARSET_NAME_ERROR,
		  (ErrorParam *) 0
		 );

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


  char* omcs = get_argument();
  Int32 omcs_len;

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

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


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

  return 0;
}
void SessionDefaults::setIsoMappingName(const char * attrValue, Lng32 attrValueLen)
{
  if (isoMappingName_)
    {
      NADELETEBASIC(isoMappingName_, heap_);
    }
  
  isoMappingName_ = new(heap_) char[attrValueLen + 1];
  strncpy(isoMappingName_, attrValue, attrValueLen);
  isoMappingName_[attrValueLen] = '\0';
  
  // upcase isoMappingName_
  str_cpy_convert(isoMappingName_, isoMappingName_, attrValueLen, 1);

  setIsoMappingEnum();
}
Exemplo n.º 4
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.º 5
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.º 6
0
// We come here from syntax like
//	SELECT * FROM :hv PROTOTYPE 'cat.sch.tbl';  -- host variable, static SQL
//	TABLE $ev;				    -- env var, static or dynam
// (Internally, both host vars and env vars are HostVar objects.)
//
// If there's an environment variable, get its value at time of compilation,
// and stick that into the internal prototype value.  Generator will need
// to save these env var name/value pairs in the generated code;
// Executor needs to use the saved compile-time value of any name that is not
// defined at run-time.
//
// If there's a prototype value, parse it as an actual table name
// (1, 2, or 3-part name) and overwrite the bogus values in *this with the
// parsed prototype value.  Our caller, applyDefaults, will overwrite any
// remaining blank name parts.  Generator needs to save the host var names
// for actual input at run-time, and to save the prototype values for
// similarity check at run-time.
//
// We avoid re-parsing and re-overwriting this CorrName by checking/setting
// its bound state.  Note that we do not rely on its prototype's bound state
// because that is a separate, pointed at object: some Binder subroutines
// make local copies of CorrNames, and any apply methods invoked on the locals
// would not be propagated to the caller's originals: relying on the then True
// value of the prototype's bound state would be fallacious.
//
// If no error in proto, node is bound and bindWA errStatus unchanged
// (note that not having a proto is not an error).
// If error in proto, node is left unbound and bindWA errStatus is set.
//
void CorrName::applyPrototype(BindWA *bindWA)
{
  if (nodeIsBound()) return;
  HostVar *proto = getPrototype();
  if (!proto) {
    markAsBound();
    return;
  }

  // CMPASSERT(this == proto->getPrototypeTarget());
  CMPASSERT(!proto->getName().isNull());
  if (proto->isEnvVar()) {
    char *value = getenv(proto->getName());
    if (!value) {
      // Environment variable has no defined value.
      *CmpCommon::diags() << DgSqlCode(-4086) << DgString0(proto->getName());
      bindWA->setErrStatus();
      return;
    }
    // upcase value returned by getenv
#pragma nowarn(1506)   // warning elimination 
    Int32 len = strlen(value);
#pragma warn(1506)  // warning elimination 
    char * ucValue = new (bindWA->wHeap()) char[len+1];
    str_cpy_convert(ucValue, value, len, -1/*upshift*/);
    ucValue[len] = 0;
    proto->getPrototypeValue() = ucValue;
    // do not free "ucValue" here, it is still used in "proto"
    // to prevent Coverity RESOURCE_LEAK error, add the following
    // coverity[leaked_storage]
  }

  // defines can not be used on linux platform
  if (proto->isDefine()) {
      *CmpCommon::diags() << DgSqlCode(-4155) << DgString0(proto->getName());
      bindWA->setErrStatus();
      return;
  }

  CMPASSERT(!proto->getPrototypeValue().isNull());

  // Some of the following code is cloned from the QualifiedName ctor above
  Parser parser(bindWA->currentCmpContext());
  NAString ns("TABLE " + proto->getPrototypeValue() + ";",
              CmpCommon::statementHeap());
#pragma nowarn(1506)   // warning elimination 
  // save the current parserflags setting
  ULng32 savedParserFlags = Get_SqlParser_Flags (0xFFFFFFFF);
  StmtQuery *stmt = (StmtQuery *)parser.parseDML(ns, ns.length(), GetAnsiNameCharSet());
  // Restore parser flags settings 
  Set_SqlParser_Flags (savedParserFlags);
#pragma warn(1506)  // warning elimination 
  if (stmt) {
    CMPASSERT(stmt->getOperatorType() == STM_QUERY);
    CorrName &protoCorrName = 
      		stmt->getQueryExpression()->getScanNode()->getTableName();

    // Unless the hostvar type was forced directly,
    // copy the special table type to me, the prototype may be a
    // resource fork
    if (getSpecialType() == ExtendedQualName::NORMAL_TABLE)
      setSpecialType(protoCorrName);

    // This if-test prevents pathologies such as
    //	   SELECT col FROM :hv1 PROTOTYPE ':hv2 PROTOTYPE ''tbl''';
    // but allows
    //	   SELECT col FROM :hv1 PROTOTYPE '$ev';
    //
    // (The assertion below ensures that only host var syntax allows prototypes,
    // that you can't say ... FROM $ev PROTOTYPE '...'.)
    //
    HostVar *proto2 = protoCorrName.getPrototype();
    CMPASSERT(!proto2 || !proto->isEnvVar());
    if (!proto2 || proto2->isEnvVar()) {

      if (proto2) {
        // Here if proto2->isEnvVar.
	// Recurse (once only; the assertion above ensures that)
	// to get the value of the var, parse it and all.
	protoCorrName.applyPrototype(bindWA);
	if (bindWA->errStatus()) return;
      }

      #ifndef NDEBUG
	if (getenv("HV_DEBUG"))
	  cout << "HostVar/Prototype: parsed (" 
	       << (Int32)proto->nodeIsBound() << ") "
	       << proto->getName() << " " 
	       << protoCorrName.getExposedNameAsAnsiString() << endl;
      #endif

      // assert *before* overwriting with 0
	//      CMPASSERT(!getQualifiedNameObj().getNamePosition());
      getQualifiedNameObj() = protoCorrName.getQualifiedNameObj();

      proto->setPrototypeType(HostVar::QUALIFIEDNAME);

      // mark that we, the trusted CorrName, are bound
      markAsBound();
    }
  }

  if (!nodeIsBound()) {
    // Clear parser syntax error and emit "Prototype value not valid"
    #ifndef NDEBUG
      if (!getenv("HV_DEBUG"))
    #endif
    CmpCommon::diags()->clear();
    *CmpCommon::diags() << DgSqlCode(-4087) 
      << DgString0(proto->getPrototypeValue());
    bindWA->setErrStatus();
  }

  delete stmt;

} // applyPrototype