Esempio n. 1
0
//ss_cc_change : This file is obsolete and is not used
//LCOV_EXCL_START
// read and return module header structure
module_header_struct*
readModuleHeader
(fstream              &mf,     // (IN): binary module file
 module_header_struct &hdr,    // (IN): target of read
 const char *         name,    // (IN): name of module (for error msg)
 ComDiagsArea         &diags)  // (IN): deposit any error msg here
{
  // read the module header
  mf.seekg(0, ios::beg);
  mf.read((char *)&hdr, sizeof(module_header_struct));
  if (mf.fail()) {
    diags << DgSqlCode(-CLI_READ_ERROR) << DgString0(name);
    return NULL;
  }

  // give versioning a chance to massage/migrate it to this version
  module_header_struct modHdrCls, *latestModHdr = (module_header_struct*)
    hdr.driveUnpack(&hdr, &modHdrCls, NULL);
  if (!latestModHdr) {
    // error: version is no longer supported
    diags << DgSqlCode(-CLI_MODULE_HDR_VERSION_ERROR) 
          << DgString0(name);
    return NULL;
  }

  // verify its validity
  Lng32 errCode = latestModHdr->RtduStructIsCorrupt();
  if (errCode) {
    // the module file is corrupted or has invalid data
    diags << DgSqlCode(errCode) << DgString0(name);
    return NULL;
  }
  return latestModHdr;
}
Esempio n. 2
0
Lng32 CliGlobals::sendEnvironToMxcmp()
{
  ComDiagsArea & diags = currContext()->diags();
  
  if (NOT getArkcmp()->isConnected())
    return 0;
  
  // send the current environment to mxcmp
  ExSqlComp::ReturnStatus sendStatus = 
    getArkcmp()->sendRequest(CmpMessageObj::ENVS_REFRESH, NULL,0);
  if (sendStatus != ExSqlComp::SUCCESS)
    {
      if (sendStatus == ExSqlComp::ERROR)
	{
	  diags << DgSqlCode(-CLI_SEND_REQUEST_ERROR) 
		<< DgString0("SET ENVIRON");
	  return -CLI_SEND_REQUEST_ERROR;
	  //	  return SQLCLI_ReturnCode(&currContext,-CLI_SEND_REQUEST_ERROR);
	}
      //else
      //  retcode = WARNING;
    }
  
  if (getArkcmp()->status() != ExSqlComp::FINISHED)
    {
      diags << DgSqlCode(-CLI_IO_REQUESTS_PENDING)
	    << DgString0("SET ENVIRON");
      return -CLI_IO_REQUESTS_PENDING;
      //return SQLCLI_ReturnCode(&currContext,-CLI_IO_REQUESTS_PENDING); 
    }
  
  return 0;
}
void ElemDDLUdfOptimizationHint::synthesize(void)
{
  if (getOptimizationKind() NEQ COM_UDF_NUMBER_OF_UNIQUE_OUTPUT_VALUES OR
      uniqueOutputValuesParseTree_ EQU NULL)
    return;

  NABoolean    isErrMsgIssued = FALSE;
  ComSInt64    value = 0;
  ItemExpr   * pItemExpr = NULL;
  ConstValue * pConstVal = NULL;
  for (CollIndex i = 0; i < uniqueOutputValuesParseTree_->entries(); i++)
  {
    pItemExpr = (*uniqueOutputValuesParseTree_)[i];
    pConstVal = (ConstValue *)pItemExpr;
    if (NOT pConstVal->canGetExactNumericValue() AND NOT isErrMsgIssued)
    {
      *SqlParser_Diags << DgSqlCode(-3017) << DgString0(pConstVal->getConstStr());
      isErrMsgIssued = TRUE;
    }
    value = pConstVal->getExactNumericValue();
    uniqueOutputValues_.insert(value);
    if (value < -1 AND NOT isErrMsgIssued) // only issue the error message once
    {
      // Error: Expected a positive value or -1 (representing the default SYSTEM setting option)
      NAString valueStr = Int64ToNAString(value);
      *SqlParser_Diags << DgSqlCode(-3017) << DgString0(valueStr);
      isErrMsgIssued = TRUE;
    }
  } // for
} // ElemDDLUdfOptimizationHint::synthesize()
LmResult LmRoutineCppObj::dealloc(ComDiagsArea *diagsArea)
{
  LmResult result = LM_OK;

  delete invocationInfo_;
  invocationInfo_ = NULL;

  for (CollIndex i=0; i<planInfos_.getUsedLength(); i++)
    if (planInfos_.used(i))
      delete planInfos_[i];
  planInfos_.clear();

  if (paramRow_)
    {
      NADELETEBASIC(paramRow_, collHeap());
      paramRow_ = NULL;
    }

  if (inputRows_)
    {
      for (int i=0; i<numInputTables_; i++)
        if (inputRows_[i])
          NADELETEBASIC((inputRows_[i]), collHeap());
      NADELETEBASIC(inputRows_, collHeap());
      inputRows_ = NULL;
    }
  if (outputRow_)
    {
      // actually allocated buffer started where the wall starts
      NADELETEBASIC((outputRow_ - WALL_STRING_LEN), collHeap());
      outputRow_ = NULL;
    }

  try
    {
      // delete the interface object, the virtual destructor may call user code
      delete interfaceObj_;
    }
  catch (tmudr::UDRException e)
    {
      *diagsArea << DgSqlCode(-LME_UDR_METHOD_ERROR)
                 << DgString0("destructor")
                 << DgString1(getNameForDiags())
                 << DgString2(e.getMessage().c_str());
      result = LM_ERR;
    }
  catch (...)
    {
      *diagsArea << DgSqlCode(-LME_UDR_METHOD_ERROR)
                 << DgString0("destructor")
                 << DgString1(getNameForDiags())
                 << DgString2("General exception.");
      result = LM_ERR;
    }

  interfaceObj_ = NULL;

  return result;
}
Int32 main(Int32 argc, char **argv)
{

  _set_new_handler(mainNewHandler);

  // for NA_YOS newHandler_NSK needs to be added, once it is ready -- Sri gadde

  mxCompileUserModule mxCUM;
  mxCUMptr = &mxCUM;

  // process command line arguments
  Cmdline_Args args;
  args.processArgs(argc, argv);
  ApplicationFile *appFile=NULL;

  // check if application file exists
  if (ACCESS(args.application().c_str(), READABLE) != 0) {
    mxCUM << ERROR << DgSqlCode(-2223)
          << DgString0(args.application().c_str());
  }
  else {
    // ask factory to create an ELFFile or a SQLJFile
    appFile = ApplicationFile::makeApplicationFile(args.application());
    if (!appFile) { // no, it's not an application file
      mxCUM << ERROR << DgSqlCode(-2202)
            << DgString0(args.application().c_str());
    }
    else {
      // open the application file
      if (appFile->openFile(args)) {
        // process appFile's embedded module definitions
        std::string modName;
        while (appFile->findNextModule(modName)) {
          // extract embedded module definition & SQL compile it
          if (!appFile->processModule()) {
            mxCUM << WARNING << DgSqlCode(-2204) << DgString0(modName.c_str());
            // set mxCUM to WARNING at least. processModule may have set
            // it to WARNING, ERROR, or FAIL. If we get here, mxCUM
            // should never be set to SUCCEED.
          }
        }
        // close the application file
        appFile->closeFile();
        appFile->logErrors();
      }
    }
  }
  mxCUM.dumpDiags();
  if (appFile) {
    appFile->printSummary();
    delete appFile;
  }
  return mxCUM.returnCode();
}
LmHandle loadDll(
  const char   *containerName,
  const char   *externalPath,
  LmHandle     extLoader,
  ComUInt32    *containerSize,
  ComDiagsArea *da,
  NAMemory *heap)
{
#ifdef LMCOMMON_CANNOT_CALL_DLOPEN
  *da << DgSqlCode(-LME_INTERNAL_ERROR)
      << DgString0(": dlopen() is not supported");
  *da << DgSqlCode(-LME_DLL_CONT_NOT_FOUND)
      << DgString0(containerName)
      << DgString1(externalPath);
  return NULL;
#else
  char *libraryName = NULL;
  if (str_len(externalPath) == 0)
    externalPath = ".";
  libraryName = new (heap)
	  char[str_len(externalPath) + str_len(containerName) + 2];
  sprintf(libraryName, "%s/%s", externalPath, containerName);

  // TBD: For now, set container size to 0. Need to see how to get
  // the actual size
  if (containerSize)
    *containerSize = 0;

  // extLoader is an object of LmCLoader class. It's not used to
  // load the library. We can simply load the DLL.
  LmHandle container = NULL;
  const char *operation = "dlopen";
  container = (LmHandle) dlopen(libraryName, RTLD_NOW | RTLD_GLOBAL);

  LM_DEBUG3("%s(%s) returned 0x%08x\n", operation, libraryName, container);
  
  if (container == NULL)
  {
    *da << DgSqlCode(-LME_DLL_CONT_NOT_FOUND)
        << DgString0(containerName)
        << DgString1(externalPath);
    addDllErrors(*da, operation, FALSE);
  }

  NADELETEBASIC(libraryName, heap);
  return container;
#endif // LMCOMMON_CANNOT_CALL_DLOPEN
}
void addDllErrors(ComDiagsArea &diags,
                  const char *operation,
                  NABoolean isWarningOnly)
{
  Int32 errorCode = 0;
  Int32 errorDetail = 0;
  char *errorString = (char *)"";


#ifndef LMCOMMON_CANNOT_CALL_DLOPEN
  // dlresultcode() is not applicable to Linux
  errorString = dlerror();
#endif


  // Remove trailing period and linefeed characters from the message
  // string
  ComUInt32 msglen = 0;
  while (errorString && (msglen = strlen(errorString)) > 0)
  {
    ComUInt32 idx = msglen - 1;
    if (errorString[idx] == '\n' || errorString[idx] == '\r' ||
        errorString[idx] == '.')
      errorString[idx] = 0;
    else
      break;
  }

  diags << DgSqlCode((isWarningOnly ? LME_DLFCN_ERROR : -LME_DLFCN_ERROR))
        << DgString0(operation)
        << DgInt0(errorCode)
        << DgInt1(errorDetail)
        << DgString1(errorString);

}
short SqlciRWExecuteCmd::process(SqlciEnv * sqlci_env)
{
  short rc = 0;

  PrepStmt * prepStmt = sqlci_env->get_prep_stmts()->get(stmtName_);
  if (! prepStmt)
    {
      sqlci_env->diagsArea() << DgSqlCode(-SQLCI_STMT_NOT_FOUND)
			     << DgString0(stmtName_);

      return 0;
    }

  sqlci_env->sqlciRWEnv()->rwExe()->setExecutePrepStmt(prepStmt);
  sqlci_env->sqlciRWEnv()->rwExe()->setExecuteCmd(stmtName_);

  if (usingParamStr_)
    {
      rc = 
	sqlci_env->sqlciRWEnv()->rwExe()->setUsingParamInfo(usingParamStr_);
      if (rc)
	return 0;
    }

  sqlci_env->sqlciRWEnv()->rwExe()->setState(SqlciRWInterfaceExecutor::SELECT_STARTED_);

  sqlci_env->sqlciRWEnv()->rwExe()->setResetListFlag(FALSE);

  rc = sqlci_env->sqlciRWEnv()->rwExe()->process(sqlci_env);
  sqlci_env->sqlciRWEnv()->setSelectInProgress(TRUE);

  return rc;
}
Esempio n. 9
0
// read and return descriptor area (headers + entries)
Int32
readDescArea
(fstream              &mf,          // (IN) : binary module file
 module_header_struct &latestModHdr,// (IN) : its module header
 NAHeap               &heap,        // (IN) : allocate DESC area from here
 const char *         name,       // (IN) : module name (for error msg)
 ComDiagsArea         &diags,       // (IN) : deposit any error msg here
 char                *&descArea)    // (OUT): desc headers + entries
{
  // make sure we have reasonable arguments
  if (latestModHdr.descriptor_area_offset <= 0 ||
      latestModHdr.descriptor_area_length <= 0)
    return -1;

  // allocate space for DESC headers + entries
  descArea = (char*)
    heap.allocateMemory((size_t)latestModHdr.descriptor_area_length);
	  
  // read DESC headers + entries
  mf.seekg(latestModHdr.descriptor_area_offset, ios::beg);
  mf.read(descArea, (Int32)latestModHdr.descriptor_area_length);
  if (mf.fail()) {
    diags << DgSqlCode(-CLI_READ_ERROR) << DgString0(name);
    return -1;
  }
  return 1; // all OK
}
// *****************************************************************************
// *                                                                           *
// * Function: validateLibraryFileExists                                       *
// *                                                                           *
// *    Determines if a library file exists, and if not, reports an error.     *
// *                                                                           *
// *                                                                           *
// *****************************************************************************
// *                                                                           *
// *  Parameters:                                                              *
// *                                                                           *
// *  <libraryFilename>               const ComString &               In       *
// *    is the file whose existence is to be validated.                        *
// *                                                                           *
// *  <isSystemObject>                bool                            In       *
// *    if true, indicates the filename should be prepended with the value of  *
// *  MY_SQROOT before validating existence.                                   *
// *                                                                            *
// *****************************************************************************
static int validateLibraryFileExists(
   const NAString    &libraryFilename,
   bool                isSystemObject)
   
{
      
  NAString completeLibraryFilename(libraryFilename);
  
  if (isSystemObject) {
    completeLibraryFilename.insert(0,'/');
    completeLibraryFilename.insert(0,getenv("MY_SQROOT"));
  }
  else
    if (CmpCommon::getDefault(CAT_LIBRARY_PATH_RELATIVE) == DF_ON)
      completeLibraryFilename.insert(0,getenv("MY_UDR_ROOT"));
   
  char *libraryFilenameString = convertNAString(completeLibraryFilename,STMTHEAP);
  struct stat sts;

  if ((stat(libraryFilenameString,&sts)) == -1 && errno == ENOENT) {
    *CmpCommon::diags() << DgSqlCode(-1382)
                        << DgString0(libraryFilename);
    return 1;
  }
 
  return 0;
}
Esempio n. 11
0
short ExExeUtilLongRunningTcb::processContinuing(Lng32 &rc) 
{

  Int64 rowsAffected = 0;

  rc = cliInterface()->execContinuingRows(getContinuingOutputVarPtrList(),
                                          rowsAffected);

  if (rc < 0)
    {
      return -1;
    }

  if (rowsAffected > 0)
    addRowsDeleted(rowsAffected);

#ifdef _DEBUG

   if ((rowsAffected > 0) && lrTdb().longRunningQueryPlan()) {

        char lruQPInfo[100];

        str_sprintf(lruQPInfo, "Continuing rows deleted: %ld\n\n", 
                                rowsAffected);

        ComDiagsArea * diagsArea = getDiagAreaFromUpQueueTail();
        (*diagsArea) << DgSqlCode(8427) << DgString0(lruQPInfo);
   }
#endif
 
  return 0;
}
Esempio n. 12
0
// ----------------------------------------------------------------------------
// method:  getAuthDetails
//
// Create the CmpSeabaseDDLauth class containing auth details for the
// request authID
//
// Input:
//    authID - the database authorization ID to search for
//
//  Output:
//    A returned parameter:
//       0 - authorization details are available
//       < 0 - an error was returned trying to get details
//       100 - authorization details were not found
//       > 0 - (not 100) warning was returned
// ----------------------------------------------------------------------------
Int32 CmpSeabaseDDLauth::getAuthDetails (Int32 authID)
{
  try
  {
    NAString sysCat = CmpSeabaseDDL::getSystemCatalogStatic();
    char buf[1000];
   str_sprintf(buf, "select auth_id, auth_db_name, auth_ext_name, auth_type, auth_creator, auth_is_valid, auth_create_time, auth_redef_time from %s.\"%s\".%s where auth_id = %s ",
              sysCat.data(), SEABASE_MD_SCHEMA, SEABASE_AUTHS, authID);
    NAString cmd (buf);

    if (selectExactRow(cmd))
      return 0;
    return 100;
  }
  catch (DDLException e)
  {
    // At this time, an error should be in the diags area.
    return e.getSqlcode();
  }
  catch (...)
  {
    // If there is no error in the diags area, set up an internal error
    Int32 numErrors = CmpCommon::diags()->getNumber(DgSqlCode::ERROR_);
    if (numErrors == 0)
      *CmpCommon::diags() << DgSqlCode (-CAT_INTERNAL_EXCEPTION_ERROR)
                          << DgInt0(__LINE__)
                          << DgString0("getAuthDetails for authID");

    return -CAT_INTERNAL_EXCEPTION_ERROR;
  }
}
Esempio n. 13
0
NABoolean CmpSqlSession::validateVolatileSchemaName(NAString &schName)
{
  if (NOT schName.isNull())
    {
      ComSchemaName csn(schName);

      if (NOT csn.isValid())
	{
	  // Schema name $0~SchemaName is not valid.
	  *CmpCommon::diags() << DgSqlCode(-8009) 
			      << DgSchemaName(schName);
	  return FALSE;
	}

      Lng32 len = MINOF(strlen(csn.getSchemaNamePartAsAnsiString().data()),
		       strlen(COM_VOLATILE_SCHEMA_PREFIX));
      NAString upSch(csn.getSchemaNamePartAsAnsiString().data());
      upSch.toUpper();
      if ((NOT Get_SqlParser_Flags(ALLOW_VOLATILE_SCHEMA_IN_TABLE_NAME)) &&
	  (len > 0) &&
	  (strncmp(upSch.data(), COM_VOLATILE_SCHEMA_PREFIX, len) == 0))
	{
	  *CmpCommon::diags() << DgSqlCode(-4193) 
			      << DgString0(COM_VOLATILE_SCHEMA_PREFIX);
	  return FALSE;
	}
    }

  return TRUE;
}
Esempio n. 14
0
//CmpStoredProc::Status CmpInternalSP::open(CmpISPDataObject& data)
CmpStoredProc::ExecStatus CmpInternalSP::open(CmpISPDataObject& data)
{
  CMPASSERT(state_ == NONE);
  procFuncs_ = procFuncsLookupTable_[procName()];
  if (!procFuncsLookupTable_.ValidPFuncs(procFuncs_))
  {
    *(cmpContext()->diags()) << DgSqlCode(arkcmpErrorISPNotFound) 
      << DgString0(procName().data());
    return FAIL;       
  }

  initSP_ERROR_STRUCT();
  SP_STATUS spStatus =
      (*(procFuncs_.procFunc_))( SP_PROC_OPEN, 
				(SP_ROW_DATA)data.input(),
				CmpSPExtractFunc,
				(SP_ROW_DATA)data.output(), 
				CmpSPFormatFunc,
				(SP_KEY_VALUE)data.key(), 
				CmpSPKeyValueFunc,
				&procHandle_, 
				procFuncs_.spHandle_, 
				&spError_[0]);

  if (spStatus == SP_FAIL || spStatus == SP_SUCCESS_WARNING)
  {
    // Errors or warnings, go get them
    data.output()->MoveDiags(spError_, spStatus);
    if (spStatus == SP_FAIL)
      return FAIL;
  }
  state_ = PROCESS;
  return SUCCESS; 
}
Esempio n. 15
0
// This function copies the above applyDefaults() function
// and includes checking for the object existence and 
// search in the public schema if necessary.
// This is used to replace the above function when 
// we need to consider PUBLIC_SCHEMA_NAME
Int32 QualifiedName::applyDefaultsValidate(const SchemaName& defCatSch,
                                         ComAnsiNameSpace nameSpace)
{
  // need to try public schema if it is specified
  // and the object schema is not specified
  NAString publicSchema = "";
  CmpCommon::getDefault(PUBLIC_SCHEMA_NAME, publicSchema, FALSE);
  ComSchemaName pubSchema(publicSchema);
  NAString pubSchemaIntName = "";
  if ( getSchemaName().isNull() && 
       !pubSchema.isEmpty() )
  {
    pubSchemaIntName = pubSchema.getSchemaNamePart().getInternalName();
  }

  Int32 ret = extractAndDefaultNameParts( defCatSch 
				                              , catalogName_
                                      , schemaName_
                                      , objectName_
                                   );

  // try public schema if the table does not exist 
  if (!pubSchemaIntName.isNull())
  {
    *(CmpCommon::diags()) << DgSqlCode(-4222)
                          << DgString0("Public Access Schema");
  }

  return ret;
}
Esempio n. 16
0
// -----------------------------------------------------------------------------
// Method:  describe
//
// This method returns the showddl text for the requested user in string format
//
// Input:
//   authName - name of user to describe
//
// Input/Output:  
//   authText - the REGISTER USER text
//
// returns result:
//    true -  successful
//    false - failed (ComDiags area will be set up with appropriate error)
//-----------------------------------------------------------------------------
bool CmpSeabaseDDLuser::describe (const NAString &authName, NAString &authText)
{
  Int32 retcode = 0;
  try
  {
    retcode = getUserDetails(authName.data());
    if (retcode == 100)
    {
      *CmpCommon::diags() << DgSqlCode(-CAT_USER_NOT_EXIST)
                          << DgString0 (authName.data());
      return false;
    }
    
    // throw an exception so the catch handler will put a value in ComDiags
    // area in case no message exists
    if (retcode < 0)
    {
      UserException excp (NULL, 0);
      throw excp;
    }
  
    authText = "REGISTER USER ";
    authText += getAuthExtName();
    if (getAuthExtName() != getAuthDbName())
    {
      authText += " AS ";
      authText += getAuthDbName();
    }
    authText += ";\n";
  }

  catch (...)
  {
   // At this time, an error should be in the diags area.
   // If there is no error, set up an internal error
   Int32 numErrors = CmpCommon::diags()->getNumber(DgSqlCode::ERROR_);
   if (numErrors == 0)
    *CmpCommon::diags() << DgSqlCode(-CAT_INTERNAL_EXCEPTION_ERROR)
                        << DgInt0(__LINE__)
                        << DgString0("describe");

    return false;
  }

  return true;
}
// *****************************************************************************
// *                                                                           *
// * Function: CmpSeabaseDDL::createSeabaseSchema                              *
// *                                                                           *
// *    Implements the CREATE SCHEMA command.                                  *
// *                                                                           *
// *****************************************************************************
// *                                                                           *
// *  Parameters:                                                              *
// *                                                                           *
// *  <createSchemaNode>              StmtDDLCreateSchema  *          In       *
// *    is a pointer to a create schema parser node.                           *
// *                                                                           *
// *  <currentCatalogName>            NAString &                      In       *
// *    is the name of the current catalog.                                    *
// *                                                                           *
// *****************************************************************************
void CmpSeabaseDDL::createSeabaseSchema(
   StmtDDLCreateSchema  * createSchemaNode,
   NAString             & currentCatalogName)
   
{

ComSchemaName schemaName (createSchemaNode->getSchemaName());
  
   if (schemaName.getCatalogNamePart().isEmpty())
      schemaName.setCatalogNamePart(currentCatalogName);  
  
NAString catName = schemaName.getCatalogNamePartAsAnsiString();
ComAnsiNamePart schNameAsComAnsi = schemaName.getSchemaNamePart();
NAString schName = schNameAsComAnsi.getInternalName();

ExeCliInterface cliInterface(STMTHEAP, NULL, NULL,
CmpCommon::context()->sqlSession()->getParentQid());
ComSchemaClass schemaClass;
Int32 objectOwner = NA_UserIdDefault;
Int32 schemaOwner = NA_UserIdDefault;

int32_t retCode = verifyDDLCreateOperationAuthorized(&cliInterface,
                                                     SQLOperation::CREATE_SCHEMA,
                                                     catName,
                                                     schName,
                                                     schemaClass,
                                                     objectOwner,
                                                     schemaOwner);
   if (retCode != 0)
   {
      handleDDLCreateAuthorizationError(retCode,catName,schName);
      return;
   }
   
Int32 schemaOwnerID = NA_UserIdDefault; 

// If the AUTHORIZATION clause was not specified, the current user becomes
// the schema owner. 

   if (createSchemaNode->getAuthorizationID().isNull())
      schemaOwnerID = ComUser::getCurrentUser();
   else
      if (ComUser::getAuthIDFromAuthName(createSchemaNode->getAuthorizationID().data(),
                                         schemaOwnerID) != 0)
      {
         *CmpCommon::diags() << DgSqlCode(-CAT_AUTHID_DOES_NOT_EXIST_ERROR)
                             << DgString0(createSchemaNode->getAuthorizationID().data());
         return;
      }
   
   addSchemaObject(cliInterface,
                   schemaName,
                   createSchemaNode->getSchemaClass(),
                   schemaOwnerID,
                   createSchemaNode->createIfNotExists());

}
void ExtQualModuleNames::parseModule
(std::string& cat, std::string& sch, std::string& mod)
{
  // parse [[<catalog>.]<schema>.]<module>
  std::string id1, id2;
  if (nextToken() == ID) {
    id1 = currentToken_;
    match(ID);
    if (nextToken() == DOT) {
      match(DOT);
      if (nextToken() == ID) {
        id2 = currentToken_;
        match(ID);
        if (nextToken() == DOT) {
          match(DOT);
          if (nextToken() == ID) { // module is <cat>.<sch>.<mod>
            cat = id1;
            sch = id2;
            mod = currentToken_;
            match(ID);
          }
          else {
            *mxCUMptr << FAIL << DgSqlCode(-2213)
                      << DgString0(currentToken_.c_str());
          }
        }
        else { // nextToken != DOT
          sch = id1; // module is <sch>.<mod>
          mod = id2;
          cat = moduleCatalog_;
        }
      }
      else {
        *mxCUMptr << FAIL << DgSqlCode(-2213)
                  << DgString0(currentToken_.c_str());
      }
    }
    else { // nextToken != DOT
      mod = id1; // module is just <mod>
      sch = moduleSchema_;
      cat = moduleCatalog_;
    }
  }
}
NABoolean
CmpStatement::error(Lng32 no, const char* s)
{
  if ( diags()->getNumber() )
    return TRUE;  // means the underlying routines have put the errors into
	          // diags.
  *diags() << DgSqlCode(no) << DgString0(s);

  return TRUE;
}
// match a terminal symbol t
void ExtQualModuleNames::match(tokenType t)
{
  if (nextToken() == t) { // matches t. all is OK.
    currentTokenCode_ = scanner(); // get next token
  }
  else {
    *mxCUMptr << FAIL << DgSqlCode(-2212) << DgString0(tokenString(t))
              << DgString1(currentTokenString());
  }
}
LmResult LmRoutineCppObj::invokeRoutine(void *inputRow,
                                        void *outputRow,
                                        ComDiagsArea *da)
{
  // This type of routine does not support the old C interface,
  // must call invokeRoutineMethod instead
  *da << DgSqlCode(-11111)
      << DgString0("Called LmRoutineCppObj::invokeRoutine()");

  return LM_ERR;
}
Esempio n. 22
0
// ----------------------------------------------------------------------------
// method: getUserDetails
//
// Create the CmpSeabaseDDLuser class containing user details for the
// request userID
//
// Input:
//    userID - the database authorization ID to search for
//
//  Output:
//    A returned parameter:
//       0 - authorization details are available
//       < 0 - an error was returned trying to get details
//       100 - authorization details were not found
//       > 0 - (not 100) warning was returned
// ----------------------------------------------------------------------------
Int32 CmpSeabaseDDLuser::getUserDetails(Int32 userID)
{
  Int32 retcode = getAuthDetails(userID);
  if (retcode == 0)
  {
    if (!isUser())
      *CmpCommon::diags() << DgSqlCode (-CAT_IS_NOT_A_USER)
                          << DgString0 (getAuthDbName());
    return -CAT_IS_NOT_A_USER;
  }
  return retcode;
}
LmResult LmRoutineCppObj::validateWall(char *userBuf,
                                       int userBufLen,
                                       ComDiagsArea *da,
                                       const char *bufferName)
{
  if (memcmp(userBuf - WALL_STRING_LEN, WALL_STRING, WALL_STRING_LEN) != 0)
    {
      if (da)
        *da << DgSqlCode(LME_BUFFER_OVERWRITE)
            << DgString0(invocationInfo_->getUDRName().data())
            << DgString1(bufferName)
            << DgString2("beginning");
      else
        throw tmudr::UDRException(
             38900,
             "UDR %s overwrote space before its %s buffer",
             invocationInfo_->getUDRName().data(),
             bufferName);
    }

  if (memcmp(userBuf + userBufLen, WALL_STRING, WALL_STRING_LEN) != 0)
    {
      if (da)
        *da << DgSqlCode(LME_BUFFER_OVERWRITE)
            << DgString0(invocationInfo_->getUDRName().data())
            << DgString1(bufferName)
            << DgString2("end");
      else
        throw tmudr::UDRException(
             38900,
             "UDR %s overwrote space after its %s buffer",
             invocationInfo_->getUDRName().data(),
             bufferName);
    }

  return LM_OK;
}
Esempio n. 24
0
// ----------------------------------------------------------------------------
// method: getUserDetails
//
// Create the CmpSeabaseDDLuser class containing user details for the
// requested username
//
// Input:
//    userName - the database username to retrieve details for
//    isExternal -
//       true - the username is the external name (auth_ext_name)
//       false - the username is the database name (auth_db_name)
//
//  Output:
//    A returned parameter:
//       0 - authorization details are available
//       < 0 - an error was returned trying to get details
//       100 - authorization details were not found
//       > 0 - (not 100) warning was returned
// ----------------------------------------------------------------------------
Int32 CmpSeabaseDDLuser::getUserDetails(const char *pUserName,
                                        bool isExternal)
{
  Int32 retcode = getAuthDetails(pUserName, isExternal);
  if (retcode == 0)
  {
    if (!isUser())
    {
      *CmpCommon::diags() << DgSqlCode (-CAT_IS_NOT_A_USER)
                          << DgString0 (pUserName);
      return -CAT_IS_NOT_A_USER;
    }
  }
  return retcode;
}
void ExFastExtractTcb::updateWorkATPDiagsArea(const char *file, 
                                              int line, const char *msg)
{
    ComDiagsArea *da = workAtp_->getDiagsArea();
    if(!da)
    {
      da = ComDiagsArea::allocate(getHeap());
      workAtp_->setDiagsArea(da);
    }
   
    *da << DgSqlCode(-1001)
        << DgString0(file)
        << DgInt0(line)
        << DgString1(msg);
}
// LCOV_EXCL_START :cnu
Int32 ValidateAnsiList::validate( const char *value,  
				const NADefaults *nad,
			 Int32 attrEnum,
			 Int32 errOrWarn,
				float *) const
{
  // Validate using a copy of "*value"
  char tempStr[1000];  // max length of ATTR_VALUE 
  if ( strlen(value) >= 1000 ) return FALSE;  // just in case
  if ( strlen(value) == 0 ) return TRUE;  // empty string ATTR_VALUE is OK
  strcpy(tempStr, value);

  // prepare to extract the partitions/tokens from the default string
  const char *token, *sep = " ,:" ;
  token = strtok( tempStr, sep );
  
  // iterate thru list of volume names; return false iff any name is invalid
  // (Also an appropriate error/warning would be issued.)
  while ( token != NULL ) {
    NAString tokenObj(token);
    Int32 countPeriods = 0, inBetween = 0;
    NABoolean anyError = tokenObj.isNull() ;
    // check three part ANSI name
    for (Int32 i = 0; !anyError && i < (Int32)tokenObj.length() ; i++ ) {
      if ( ComSqlText.isDigit(token[i]) ||
	   ComSqlText.isSimpleLatinLetter(token[i]) ) inBetween++;
      else {
	if ( ComSqlText.getPeriod() == token[i] &&  // it is a period
	     countPeriods++ < 2 ) {
	  if ( inBetween == 0 ) anyError = TRUE; // no CATALOG or SCHEMA
	  else inBetween = 0 ; // start counting the next ( SCHEMA or NAME )
	}
	else anyError = TRUE;
      }
    }
    if ( countPeriods != 2 || inBetween == 0 ) anyError = TRUE;

    if ( anyError ) {
      if (errOrWarn)
	*CmpCommon::diags() << DgSqlCode(ERRWARN(2055)) << DgString0(token) 
			    << DgString1("INVALID QUALIFIED NAME");
      return FALSE;
    }
    token = strtok( NULL, sep );
  }

  return TRUE;
}
Esempio n. 27
0
ComDiagsArea *ExRaiseFunctionSqlError(CollHeap* heap, 
				      ComDiagsArea** diagsArea,
				      ExeErrorCode err, 
				      NABoolean derivedFunction,
				      OperatorTypeEnum origOperType,
				      ComCondition** cond)
{
  ExRaiseSqlError(heap, diagsArea, err);

  if (derivedFunction)
    {
      **diagsArea << DgSqlCode(-EXE_MAPPED_FUNCTION_ERROR);
      **diagsArea << DgString0(exClauseGetText(origOperType));
    }
  return *diagsArea;
}
Esempio n. 28
0
// process -g {moduleGlobal|moduleLocal[=OSSdirectory]}
Int32 Cmdline_Args::doModuleGlobalLocalDir(char *arg, Int32 argc, char **argv,
                                         Int32 &gCount, ComDiagsArea& diags)
{
  Int32 result = 0;
  // at most one -g moduleBlah option is allowed
  if (gCount > 0) {
    diags << DgSqlCode(mxcmpUmAtMostOneoptionGisAllowed); cout << diags;
    usage(argc, argv);
    result = -1;
  }
  gCount++;
  // process -g {moduleGlobal|moduleLocal}
  char *eq = strchr(arg, '=');
  if (!eq) { // -g {moduleGlobal|moduleLocal}
    return doModuleGlobalLocal(arg, argc, argv, diags);
  }
  // else -g moduleLocal=OSSdirectory
  if (strlen(eq+1) >= 1024) { // OSSdirectory is too long
    diags << DgSqlCode(mxcmpUmOssDirectoryPathTooLong) << DgString0(eq+1); cout << diags;
    usage(argc, argv);
    result = -1;
  }
  else { // OSSdirectory < 1024
    // verify we have -g moduleLocal=OSSdirectory
    Int32 kwdLen=(Int32)strlen("moduleLocal");
    if (eq-arg == kwdLen && strncmp(arg,"moduleLocal",kwdLen)==0) { 
      modulePlacement_ = MOD_LOCAL;
      // reject any Expand or Guardian path
      if (!strncmp(eq+1,"/E/",3) || !strncmp(eq+1,"/G/",3)) {
        diags << DgSqlCode(mxcmpUmModuleLocalSpecifyDir); cout << diags;
        usage(argc, argv);
        result = -1;
      }
      else {
        // copy OSSdirectory
        moduleDir_ = eq+1;
      }
    }
    else {
      diags << DgSqlCode(mxcmpUmUnsupportedArgumentInOptionG); cout << diags;
      usage(argc, argv);
      result = -1;
    }
  }
  return result;
}
// validate parameter for MV_AGE
Int32 ValidateMVAge::validate( const char *value,
                               const NADefaults *nad,
                               Int32 attrEnum,
                               Int32 errOrWarn,
                               float *alreadyHaveFloat ) const
{
  Int32 isOK = FALSE;
  float number=0;
  char textChars[20];

  if (strlen(value) < 15)
  {
    if (sscanf(value, "%f %s", &number, textChars) == 2)
    {
      const NAString text(textChars);
      if (!text.compareTo("Seconds", NAString::ignoreCase))
      {
	isOK = TRUE;
      }
      else if (!text.compareTo("Minutes", NAString::ignoreCase))
      {
	isOK = TRUE;
      }
      else if (!text.compareTo("Hours", NAString::ignoreCase))
      {
	isOK = TRUE;
      }
      else if (!text.compareTo("Days", NAString::ignoreCase))
      {
	isOK = TRUE;
      }
    }
  }

  if (!isOK)
  {
    if (errOrWarn)
      *CmpCommon::diags() << DgSqlCode(ERRWARN(2055))
          << DgString0(value)
          << DgString1(nad->lookupAttrName(attrEnum, errOrWarn));
  }
  
  return isOK;
}
Int32 ValidateRoleNameList::validate( const char *value,   
				const NADefaults *nad,
			 Int32 attrEnum,
			 Int32 errOrWarn,
				float *) const
{
  // Validate a list of role names.  Based on ValidateAnsiList
  // List format:  comma separated list of role names which use either . or _ 
  //  example:  "role.user1", "ROLE.user2", "role_user3"
  // SeaQuest example:  DB__Root, DB__Services, db_role12, db_user3

  // Validate using a copy of "*value"
  char tempStr[1000];  // max length of ATTR_VALUE 
  if ( strlen(value) >= 1000 ) return FALSE;  // just in case
  if ( strlen(value) == 0 ) return TRUE;  // empty string ATTR_VALUE is OK
  strcpy(tempStr, value);

  // prepare to extract the role names/tokens from the default string
  const char *token, *sep = " ," ;
  token = strtok( tempStr, sep );
  
  // iterate thru list of role names; return false iff any name is invalid
  // (Also an appropriate error/warning would be issued.)
  while ( token != NULL ) {
    NAString tokenObj(token);
    Lng32 sqlcode = ToInternalIdentifier(tokenObj, TRUE /*upCase*/,
                                         FALSE /*acceptCircumflex*/,
                                         0 /*toInternalIdentifierFlags*/);
    if (sqlcode && ABS(sqlcode) != 3128)
    {
      // 3004 A delimited identifier must contain at least one character.
      // 3118 Identifier too long.
      // 3127 Illegal character in identifier $0~string0.
      // 3128 $1~string1 is a reserved word.
      if (errOrWarn)
	*CmpCommon::diags() << DgSqlCode(ERRWARN(2055)) << DgString0(token) 
			    << DgString1("INVALID AUTHORIZATION IDENTIFIER");
    }
    token = strtok( NULL, sep );
  }

  return TRUE;
}