// paramName must be passed in WITHOUT leading '$' (ERRORPARAM_BEGINMARK).
// paramName returns stripped of any internal '~' (ERRORPARAM_TYPESEP) and the
//   chars either preceding it or following it, if paramName is at all valid.
//   E.g., "0~string0" returns as "0" if positional but "string0" if named;
//   "int0~1" returns as "1" if pos but "int0" if named;
//   "2" returns as "2" either way;
//   "b" returns as "b" either way (if pos, function result is -1, invalid);
//   "intx~y" returns as "y" if pos (and function result is -1, invalid) 
//   but "intx~y" if named (with a successful result, and the ComDiagsMsg.C
//   caller will reject it as not matching a string table lookup and then
//   display the entire bogus name).
// Function returns -1 for invalid paramName,
//   0 for valid NAMED_PARAM,
//   n>=0 for valid POSITIONAL_PARAM (n = the position, 0th, 1st, 2nd, ...)
//
// Why do we need to do this?  Well, we have two kinds of messages --
// ComDiagsMsg.C ComCondition ones with named params, and
// ErrorMessage.C ErrorMessage ones with positional.
// The positional params need to have position numbers so that messages can
// be translated (I18N of text often requires reordering params).
// Tagging each param with both name and position info means that the same
// msg code can be used from anywhere (either ComDiags or E'Msg),
// i.e. we can share messages and not have a confusing welter of nearly
// identical ones.
//
Lng32 FixupMessageParam(NAWchar *paramName, MsgParamType paramType)
{
  ComASSERT(paramName);
  if (!*paramName) return -1;			// invalid (empty) paramName

  NAWchar *p;
  NAWchar* sep = NAWstrchr(paramName, ERRORPARAM_TYPESEP);

  NABoolean begend = sep ? (sep == paramName || sep[1] == NAWchar('\0')) : FALSE;

  switch (paramType)
    {
    case NAMED_PARAM:
      if (begend) return 0;			// "~x" and "9~" `legal' names
      if (sep)
	if (isdigit(*paramName))
	  NAWstrcpy(paramName, ++sep);		// "9~x" -> "x"
	else if (isdigit(sep[1]))
	  *sep = NAWchar('\0');			// "x~9" -> "x"
        //else {}				// "x~y" `legal'
      return 0;					// (Dubious legal names will be
      						// flagged by our caller.)

    case POSITIONAL_PARAM:
      if (begend) return -1;			// "~x" and "9~" invalid nums
      if (!isdigit(*paramName))
        if (!sep)
	  return -1;				// "x" invalid num
	else
	  NAWstrcpy(paramName, ++sep);		// "x~9" -> "9"
      else
        if (sep)
	  *sep = NAWchar('\0');			// "9~x" -> "9"
        //else {}				// "9" valid
      for (p=paramName; *p; p++)
        if (!isdigit(*p))
	  return -1;				// "9x" invalid num
      Lng32 pos;
      NAWsscanf(paramName, WIDE_("%d"), &pos);
      return pos;

    default:
      return -1;				// invalid (unknown paramType)
    }
} // FixupMessageParam
// -----------------------------------------------------------------------
// Translate ANSI SQL names from Default ANSI SQL Name character set
// to UCS-2 encoding values.  The contents of the outWcs parameter is
// clear and set to the newly computed UCS2 string
// -----------------------------------------------------------------------
void CmAnsiNameToUCS2(const NAString &inMbs, NAWString &outWcs)
{
  outWcs.remove(0); // set to an empty string
  if (inMbs.length() <= 0)
  {
    return;
  }
  NAWString * pTargetNAWString =
    charToUnicode ( (Lng32)ComGetNameInterfaceCharSet() // in - Lng32        strCharSet
                  , inMbs.data()                        // in - const char * str
                  , (Int32)inMbs.length()               // in - Int32        len
                  , (NAMemory *)STMTHEAP                // in - NAMemory *   h
                  );
  ComASSERT(pTargetNAWString != NULL AND pTargetNAWString->length() > 0 AND
             pTargetNAWString->length() <= ComMAX_ANSI_IDENTIFIER_INTERNAL_LEN/*in NAWchars*/);
  outWcs.append(pTargetNAWString->data(), pTargetNAWString->length());
  delete pTargetNAWString;
}
void
ElemDDLConstraintUnique::setColumnRefList(ElemDDLNode * pColumnRefList)
{
  setChild(INDEX_COLUMN_NAME_LIST, pColumnRefList);

  if (getColumnRefList())
  {
    //
    // Copies information about the key column list to keyColumnArray_
    // so the user can access the information easier.  (Assumes that
    // keyColumnArray_ is still empty.)
    //
    for (CollIndex i = 0; i < getColumnRefList()->entries(); i++)
    {
      ComASSERT((*getColumnRefList())[i] AND
                (*getColumnRefList())[i]->castToElemDDLColRef());
      keyColumnArray_.insert((*getColumnRefList())[i]->castToElemDDLColRef());
    }
  }

} // ElemDDLConstraintUnique::setColumnRefList()
// method for building text
//virtual 
NAString ElemDDLFileAttrMaxSize::getSyntax() const
{
  NAString syntax = "MAXSIZE ";

  if (TRUE == isUnbounded_)
  {
    syntax += "UNBOUNDED";
  }
  else
  {
#pragma nowarn(1506)   // warning elimination 
    syntax += LongToNAString(maxSize_);
#pragma warn(1506)  // warning elimination 
    syntax += " ";
    
    switch(maxSizeUnit_)
    {

    case COM_BYTES:
      syntax += "";
      break;
    case COM_KBYTES:
      syntax += "K";
      break;
    case COM_MBYTES:
      syntax += "M";
      break;
    case COM_GBYTES:
      syntax += "G";
      break;
    default:
      ComASSERT(FALSE);
      break;

    }
  }

  return syntax;

} // getSyntax
ElemDDLPartitionByColumnList::ElemDDLPartitionByColumnList(
     ElemDDLNode * partitionKeyColumnList,
     CollHeap    * heap)
: ElemDDLPartitionByOpt(ELM_PARTITION_BY_COLUMN_LIST_ELEM),
  partitionKeyColumnArray_(heap)
{
  setChild(INDEX_PARTITION_KEY_COLUMN_LIST, partitionKeyColumnList);

  //
  // copies pointers to parse nodes representing
  // column names (appearing in a partition by option)
  // to partitionKeyColumnArray_ so the user can access
  // this information easier.
  //

  ComASSERT(partitionKeyColumnList NEQ NULL);
  for (CollIndex i = 0; i < partitionKeyColumnList->entries(); i++)
  {
    partitionKeyColumnArray_.insert((*partitionKeyColumnList)[i]->
						castToElemDDLColRef());
  }
}
// ComResWords::wordCompare() ===========================================
// comparison function for reserved word Table binary search
// returns: negative if val1 < val2 (table entry)
//          zero if val1 == val2
//          positive if val1 > val2
// =====================================================================
//
Int32 ComResWords::wordCompare(const void *val1, const void *val2)
{
  // Cast the (void *) pointers to the (ComResWord *) which they must
  // be.
  //
  ComResWord *val = (ComResWord *)val1;
  ComResWord *entry = (ComResWord *)val2;

  // If either entry is NULL or has a NULL word, return 0 (equal).
  //
  ComASSERT(val && val->getResWord() && entry && entry->getResWord());

  // case-sensitive comparison
  // (all words are uppercase)
  //
  Int32 len1 = str_len(val->getResWord());
  Int32 len2 = str_len(entry->getResWord());

  Int32 maxlen = (len1 > len2) ? len1 : len2;
 
  return str_cmp(val->getResWord(), entry->getResWord(), maxlen);
}
Esempio n. 7
0
NABoolean NAType::createSQLLiteral(const char * buf,
                                   NAString *&stringLiteral,
                                   NABoolean &isNull,
                                   CollHeap *h) const
{
  // the base class can handle the case of a NULL value and
  // generate a NULL value, otherwise let the derived class
  // generate a literal
  if (supportsSQLnull())
    {
      Int32 nullValue = 0;

      switch (getSQLnullHdrSize())
        {
        case 2:
          {
            Int16 tmp = *((Int16*) buf);
            nullValue = tmp;
          }
          break;

        default:
          ComASSERT(FALSE);
        }

      if (nullValue)
        {
          stringLiteral = new(h) NAString("NULL", h);
          isNull = TRUE;
          return TRUE;
        }
    }

  isNull = FALSE;
  return FALSE;
}
ExprNode *
ElemDDLConstraint::getChild(Lng32 index)
{
  ComASSERT(index EQU INDEX_CONSTRAINT_ATTRIBUTES);
  return pConstraintAttributes_;
}
//
// Scans (parses) input external-format schema name.
//
// This method assumes that the parameter  externalSchemaName  only
// contains the external-format schema name.  The syntax of an
// schema name is
//
//   [ <catalog-name-part> ] . <schema-name-part>
//
// A schema name part must be specified; the catalog name part is optional.
//
// The method returns the number of bytes scanned via the parameter
// bytesScanned.  If the scanned schema name is illegal, bytesScanned
// contains the number of bytes examined when the name is determined
// to be invalid.
//
// If the specified external-format schema name is valid, this method
// returns TRUE and saves the parsed ANSI SQL name part into data
// members catalogNamePart_ and schemaNamePart_; otherwise, it returns
// FALSE and does not changes the contents of the data members.
//
NABoolean
ComSchemaName::scan(const NAString &externalSchemaName,
                    size_t &bytesScanned)
{
  size_t count;
  size_t externalSchemaNameLen = externalSchemaName.length();
  bytesScanned = 0;

  #define COPY_VALIDATED_STRING(x)	\
		      ComAnsiNamePart(x, ComAnsiNamePart::INTERNAL_FORMAT)

  if (( SqlParser_Initialized() && SqlParser_NAMETYPE == DF_NSK)       ||
      (!SqlParser_Initialized() && *externalSchemaName.data() == '\\')) {
    ComMPLoc loc(externalSchemaName);
    switch (loc.getFormat()) {
      case ComMPLoc::SUBVOL:
		catalogNamePart_ = COPY_VALIDATED_STRING(loc.getSysDotVol());
		schemaNamePart_  = COPY_VALIDATED_STRING(loc.getSubvolName());
		bytesScanned = externalSchemaNameLen;
		return TRUE;

      case ComMPLoc::FILE:
		if (!loc.hasSubvolName()) {
		  catalogNamePart_ = "";
		  schemaNamePart_  = COPY_VALIDATED_STRING(loc.getFileName());
		  bytesScanned = externalSchemaNameLen;
		  return TRUE;
		}
    }
  }

  // Each ComAnsiNamePart ctor below must be preceded by "count = 0;"
  // -- see ComAnsiNamePart.cpp, and for a better scan implementation,
  //    see ComObjectName::scan() + ComObjectName(bytesScanned) ctor.

  // ---------------------------------------------------------------------
  // Scan the leftmost ANSI SQL name part.
  // ---------------------------------------------------------------------

  count = 0;
  ComAnsiNamePart part1(externalSchemaName, count);
  bytesScanned += count;
  if (NOT part1.isValid())
    return FALSE;

  if (bytesScanned >= externalSchemaNameLen)
  {
    ComASSERT(bytesScanned == externalSchemaNameLen);
    schemaNamePart_  = part1;
    return TRUE;					// "sch"
  }

  // Get past the period separator
  if (NOT ComSqlText.isPeriod(externalSchemaName[bytesScanned++]))
    return FALSE;

  // ---------------------------------------------------------------------
  // Scan the last ANSI SQL name part
  // ---------------------------------------------------------------------

#pragma nowarn(1506)   // warning elimination 
  Int32 remainingLen = externalSchemaNameLen - bytesScanned;
#pragma warn(1506)  // warning elimination 
  NAString remainingName = externalSchemaName(bytesScanned, remainingLen);
  count = 0;
  ComAnsiNamePart part2(remainingName, count);
  bytesScanned += count;
  if (NOT part2.isValid())
    return FALSE;

  if (bytesScanned == externalSchemaNameLen)
  {
    catalogNamePart_ = part1;
    schemaNamePart_  = part2;
    return TRUE;					// "cat.sch"
  }

  // The specified external-format object name contains some extra
  // trailing characters -- illegal.
  //
  return FALSE;

} // ComSchemaName::scan()
ExprNode *
ElemDDLColDefault::getChild(Lng32 index)
{
  ComASSERT(index EQU INDEX_DEFAULT_VALUE_EXPR);
  return defaultValueExpr_;
}
ExprNode *
ElemDDLPartitionSystem::getChild(Lng32 index)
{ 
  ComASSERT(index >= 0 AND index < getArity());
  return children_[index];
}
ExprNode *
StmtDDLRoleGrant::getChild(Lng32 index)
{
  ComASSERT(index >= 0 AND index < getArity());
  return children_[index];
}
void
ElemDDLColDef::setDefaultAttribute(ElemDDLNode * pColDefaultNode)
{
  ElemDDLColDefault * pColDefault = NULL;
  ComBoolean isIdentityColumn = FALSE;

  NAType * pColumnDataType = columnDataType_;

  if (pColDefaultNode NEQ NULL)
    {
      ComASSERT(pColDefaultNode->castToElemDDLColDefault() NEQ NULL);
      pColDefault = pColDefaultNode->castToElemDDLColDefault();
    }

  if (pColDefault NEQ NULL)
    {
      switch (pColDefault->getColumnDefaultType())
        {
        case ElemDDLColDefault::COL_NO_DEFAULT:
          defaultClauseStatus_ = NO_DEFAULT_CLAUSE_SPEC;
          break;
        case ElemDDLColDefault::COL_DEFAULT:
          {
            defaultClauseStatus_ = DEFAULT_CLAUSE_SPEC;
            
            if (pColDefault->getSGOptions())
              {
                isIdentityColumn = TRUE;
                pSGOptions_ = pColDefault->getSGOptions();
                pSGLocation_ = pColDefault->getSGLocation();
              }
            else
              {
                ComASSERT(pColDefault->getDefaultValueExpr() NEQ NULL);
                pDefault_ = pColDefault->getDefaultValueExpr();
              }
            
            // The cast ItemExpr to ConstValue for (ConstValue *)pDefault_; 
            // statement below sets arbitary value for the isNULL_. 
            // Bypass these checks for ID column (basically ITM_IDENTITY).
            ConstValue *cvDef = (ConstValue *)pDefault_;
            if ((cvDef && !cvDef->isNull()) && (!isIdentityColumn))
              {
                const NAType *cvTyp = cvDef->getType();
                NABoolean isAnErrorAlreadyIssued = FALSE;
                
                if ( cvTyp->getTypeQualifier() == NA_CHARACTER_TYPE )
                  {
                    CharInfo::CharSet defaultValueCS = ((const CharType *)cvTyp)->getCharSet();
                    // Always check for INFER_CHARSET setting before the ICAT setting.
                    NAString inferCharSetFlag;
                    if (getCharSetInferenceSetting(inferCharSetFlag) == TRUE &&
                        NOT cvDef->isStrLitWithCharSetPrefixSpecified())
                      {
                        if (pColumnDataType->getTypeQualifier() == NA_CHARACTER_TYPE
                            && ((const CharType *)pColumnDataType)->getCharSet() == CharInfo::UCS2
                            && SqlParser_DEFAULT_CHARSET == CharInfo::UCS2
                            && defaultValueCS == CharInfo::ISO88591
                            )
                          {
                            *SqlParser_Diags << DgSqlCode(-1186)
                                             << DgColumnName(ToAnsiIdentifier(getColumnName()))
                                             << DgString0(pColumnDataType->getTypeSQLname(TRUE/*terse*/))
                                             << DgString1(cvTyp->getTypeSQLname(TRUE/*terse*/));
                            isAnErrorAlreadyIssued = TRUE;
                          }
                        else
                          {
                            cvTyp = cvDef -> pushDownType(*columnDataType_, NA_CHARACTER_TYPE);
                          }
                      }
                    else if (CmpCommon::getDefault(ALLOW_IMPLICIT_CHAR_CASTING) == DF_ON &&
                             NOT cvDef->isStrLitWithCharSetPrefixSpecified() &&
                             cvTyp->getTypeQualifier() == NA_CHARACTER_TYPE &&
                             SqlParser_DEFAULT_CHARSET == CharInfo::ISO88591 &&
                             defaultValueCS == CharInfo::UnknownCharSet)
                      {
                        cvTyp = cvDef -> pushDownType(*columnDataType_, NA_CHARACTER_TYPE);
                      }
                    
                  } // column default value has character data type
                
                if (NOT isAnErrorAlreadyIssued &&
                    pColumnDataType->getTypeQualifier() == NA_CHARACTER_TYPE &&
                    cvTyp->getTypeQualifier() == NA_CHARACTER_TYPE &&
                    (
                         CmpCommon::getDefault(ALLOW_IMPLICIT_CHAR_CASTING) == DF_ON ||
                         NOT cvDef->isStrLitWithCharSetPrefixSpecified()))
                  {
                    const CharType *cdCharType = (const CharType *)pColumnDataType;
                    const CharType *cvCharType = (const CharType *)cvTyp;
                    CharInfo::CharSet cdCharSet = cdCharType->getCharSet(); // cd = column definition
                    CharInfo::CharSet cvCharSet = cvCharType->getCharSet(); // cv = constant value
                    if (cvCharSet == CharInfo::ISO88591)  // default value is a _ISO88591 str lit
                      {
                        
                      }
                    else if ( (cvCharSet == CharInfo::UNICODE ||  // default value is a _UCS2 string literal
                               cvCharSet == CharInfo::UTF8)   &&  // or a _UTF8 string literal
                              cdCharSet != cvCharSet )
                      {
                        //
                        // Check to see if all characters in the specified column default
                        // string literal value can be successfully converted/translated
                        // to the actual character set of the column.
                        //
                        char buf[2032];  // the output buffer - should be big enough
                        buf[0] = '\0';
                        enum cnv_charset eCnvCS = convertCharsetEnum( cdCharSet );
                        const char * pInStr = cvDef->getRawText()->data();
                        Int32 inStrLen = cvDef->getRawText()->length();
                        char * p1stUnstranslatedChar = NULL;
                        UInt32 outStrLenInBytes = 0;
                        unsigned charCount = 0;  // number of characters translated/converted
                        Int32 cnvErrStatus = 0;
                        char *pSubstitutionChar = NULL;
                        Int32 convFlags = 0;
                        
                        if ( cvCharSet == CharInfo::UNICODE )
                          {
                            cnvErrStatus =
                              UTF16ToLocale
                              ( cnv_version1            // in  - const enum cnv_version version
                                , pInStr                  // in  - const char *in_bufr
                                , inStrLen                // in  - const int in_len
                                , buf                     // out - const char *out_bufr
                                , 2016                    // in  - const int out_len
                                , eCnvCS                  // in  - enum cnv_charset charset
                                , p1stUnstranslatedChar   // out - char * & first_untranslated_char
                                , &outStrLenInBytes       // out - unsigned int *output_data_len_p
                                , convFlags               // in  - const int cnv_flags
                                , (Int32)TRUE               // in  - const int addNullAtEnd_flag
                                , (Int32)FALSE              // in  - const int allow_invalids
                                , &charCount              // out - unsigned int * translated_char_cnt_p
                                , pSubstitutionChar       // in  - const char *substitution_char
                                );
                          }
                        else // cvCharSet must be CharInfo::UTF8
                          {
                            cnvErrStatus =
                              UTF8ToLocale
                              ( cnv_version1            // in  - const enum cnv_version version
                                , pInStr                  // in  - const char *in_bufr
                                , inStrLen                // in  - const int in_len
                                , buf                     // out - const char *out_bufr
                                , 2016                    // in  - const int out_len
                                , eCnvCS                  // in  - enum cnv_charset charset
                                , p1stUnstranslatedChar   // out - char * & first_untranslated_char
                                , &outStrLenInBytes       // out - unsigned int *output_data_len_p
                                , (Int32)TRUE               // in  - const int addNullAtEnd_flag
                                , (Int32)FALSE              // in  - const int allow_invalids
                                , &charCount              // out - unsigned int * translated_char_cnt_p
                                , pSubstitutionChar       // in  - const char *substitution_char
                                );
                          }
                        switch (cnvErrStatus)
                          {
                          case 0: // success
                          case CNV_ERR_NOINPUT: // an empty input string will get this error code
                            {
                              ConstValue *pMBStrLitConstValue ;
                              // convert the string literal saved in cvDef (column default value)
                              // from UNICODE (e.g. UTF16) to the column character data type
                              if ( cdCharSet != CharInfo::UNICODE)
                                {
                                  NAString mbs2(buf, PARSERHEAP());  // note that buf is NULL terminated
                                  pMBStrLitConstValue =
                                    new(PARSERHEAP()) ConstValue ( mbs2
                                                                   , cdCharSet // use this for str lit prefix
                                                                   , CharInfo::DefaultCollation
                                                                   , CharInfo::COERCIBLE
                                                                   , PARSERHEAP()
                                                                   );
                                }
                              else
                                {
                                  NAWString mbs2((NAWchar*)buf, PARSERHEAP());  // note that buf is NULL terminated
                                  pMBStrLitConstValue = 
                                    new(PARSERHEAP()) ConstValue ( mbs2
                                                                   , cdCharSet // use this for str lit prefix
                                                                   , CharInfo::DefaultCollation
                                                                   , CharInfo::COERCIBLE
                                                                   , PARSERHEAP()
                                                                   );
                                }
                              delete pDefault_; // deallocate the old ConstValue object
                              cvDef = NULL;     // do not use cvDef anymore
                              pDefault_ = pMBStrLitConstValue;
                              pColDefault->setDefaultValueExpr(pDefault_);
                            }
                            break;
                          case CNV_ERR_INVALID_CHAR:
                            {
                              // 1401 ==  CAT_UNABLE_TO_CONVERT_COLUMN_DEFAULT_VALUE_TO_CHARSET
                              *SqlParser_Diags << DgSqlCode(-1401)
                                               << DgColumnName(ToAnsiIdentifier(getColumnName()))
                                               << DgString0(CharInfo::getCharSetName(cdCharSet));
                            }
                            break;
                          case CNV_ERR_BUFFER_OVERRUN: // output buffer not big enough
                          case CNV_ERR_INVALID_CS:
                          default:
                            CMPABORT_MSG("Parser internal logic error");
                            break;
                          } // switch
                      }
                    else if(!pColumnDataType->isCompatible(*cvTyp))
                      {
                        if (NOT isAnErrorAlreadyIssued)
                          {
                            *SqlParser_Diags << DgSqlCode(-1186)
                                             << DgColumnName(ToAnsiIdentifier(getColumnName()))
                                             << DgString0(pColumnDataType->getTypeSQLname(TRUE/*terse*/))
                                             << DgString1(cvTyp->getTypeSQLname(TRUE/*terse*/));
                            isAnErrorAlreadyIssued = TRUE;
                          }
                      }
                  } // column has character data type
                else
                  // if interval data type, the default value must have the same
                  // interval qualifier as the column.
                  if (NOT isAnErrorAlreadyIssued &&
                      (!pColumnDataType->isCompatible(*cvTyp) ||
                       (pColumnDataType->getTypeQualifier() == NA_INTERVAL_TYPE &&
                        pColumnDataType->getFSDatatype() != cvTyp->getFSDatatype())))
                    {
                      *SqlParser_Diags << DgSqlCode(-1186)
                                       << DgColumnName(ToAnsiIdentifier(getColumnName()))
                                       << DgString0(pColumnDataType->getTypeSQLname(TRUE/*terse*/))
                                       << DgString1(cvTyp->getTypeSQLname(TRUE/*terse*/));
                      isAnErrorAlreadyIssued = TRUE;
                    }
              }
          }
          break;
        case ElemDDLColDefault::COL_COMPUTED_DEFAULT:
          {
            defaultClauseStatus_ = DEFAULT_CLAUSE_SPEC;
            computedDefaultExpr_ = pColDefault->getComputedDefaultExpr();
          }
          break;
        default:
          CMPABORT_MSG("Parser internal logic error");
          break;
        }
    }

}
// -----------------------------------------------------------------------
// member functions for class StmtDDLSchGrant
// -----------------------------------------------------------------------
StmtDDLSchGrant::StmtDDLSchGrant(ElemDDLNode * pPrivileges,
                                 const ElemDDLSchemaName & aSchemaNameParseNode,
                                 ElemDDLNode * pGranteeList,
                                 ElemDDLNode * pWithGrantOption,
                                 ElemDDLNode * pByGrantorOption,
                                 CollHeap    * heap)
    : StmtDDLNode(DDL_GRANT_SCHEMA),
      schemaName_(heap),
      schemaQualName_(aSchemaNameParseNode.getSchemaName(), heap),
      isAllDMLPrivileges_(FALSE),
      isAllDDLPrivileges_(FALSE),
      isAllOtherPrivileges_(FALSE),
      isWithGrantOptionSpec_(FALSE),
      privActArray_(heap),
      granteeArray_(heap),
      isByGrantorOptionSpec_(FALSE),
      byGrantor_(NULL)
{
    if (schemaQualName_.getSchemaName().isNull())
    {
        schemaQualName_ = ActiveSchemaDB()->getDefaultSchema();
    }
    setChild(INDEX_PRIVILEGES, pPrivileges);
    setChild(INDEX_GRANTEE_LIST, pGranteeList);
    setChild(INDEX_WITH_GRANT_OPTION, pWithGrantOption);
    setChild(INDEX_BY_GRANTOR_OPTION, pByGrantorOption);
    //objectName_ = objectQualName_.getQualifiedNameAsAnsiString();
    //
    // inserts pointers to parse nodes representing privilege
    // actions to privActArray_ so the user can access the
    // information about privilege actions easier.
    //

    ComASSERT(pPrivileges NEQ NULL);
    ElemDDLPrivileges * pPrivsNode = pPrivileges->castToElemDDLPrivileges();
    ComASSERT(pPrivsNode NEQ NULL);
    if (pPrivsNode->isAllPrivileges())
    {
        isAllDMLPrivileges_ = TRUE;
        isAllDDLPrivileges_ = TRUE;
        isAllOtherPrivileges_ = TRUE;
    }
    if (pPrivsNode->isAllDMLPrivileges())
    {
        isAllDMLPrivileges_ = TRUE;
    }
    if (pPrivsNode->isAllDDLPrivileges())
    {
        isAllDDLPrivileges_ = TRUE;
    }
    if (pPrivsNode->isAllOtherPrivileges())
    {
        isAllOtherPrivileges_ = TRUE;
    }

    ElemDDLNode * pPrivActs = pPrivsNode->getPrivilegeActionList();
    if (pPrivActs)
    {
        for (CollIndex i = 0; i < pPrivActs->entries(); i++)
        {
            privActArray_.insert((*pPrivActs)[i]->castToElemDDLPrivAct());
        }
    }

    //
    // copies pointers to parse nodes representing grantee
    // to granteeArray_ so the user can access the information
    // easier.
    //

    ComASSERT(pGranteeList NEQ NULL);
    for (CollIndex i = 0; i < pGranteeList->entries(); i++)
    {
        granteeArray_.insert((*pGranteeList)[i]->castToElemDDLGrantee());
    }

    //
    // looks for With Grant option phrase
    //

    if (pWithGrantOption NEQ NULL)
    {
        isWithGrantOptionSpec_ = TRUE;
    }

    if ( pByGrantorOption NEQ NULL )
    {
        isByGrantorOptionSpec_ = TRUE;
        byGrantor_ = pByGrantorOption->castToElemDDLGrantee();
    }

} // StmtDDLSchGrant::StmtDDLSchGrant()
ExprNode *
StmtDDLInitializeSQL::getChild(Lng32 index)
{
    ComASSERT ((index >= 0) && index < getArity());
    return children_[index];
}
StmtDDLPublish::StmtDDLPublish(ElemDDLNode * pPrivileges,
                               const QualifiedName & objectName,
                               const NAString & synonymName,
                               ComBoolean isRole,
                               ElemDDLNode * pGranteeList,
                               ComBoolean isPublish,
                               CollHeap    * heap)
    : StmtDDLNode(DDL_PUBLISH),
      objectName_(heap),
      objectQualName_(objectName, heap),
      synonymName_(synonymName, heap),
      isSynonymNameSpec_(FALSE),
      isRoleList_(isRole),
      isPublish_(isPublish),
      isAllPrivileges_(FALSE),
      privActArray_(heap),
      granteeArray_(heap)
{
    setChild(PUBLISH_PRIVILEGES, pPrivileges);
    setChild(PUBLISH_GRANTEE_LIST, pGranteeList);
    objectName_ = objectQualName_.getQualifiedNameAsAnsiString();

    if (!synonymName.isNull())
        isSynonymNameSpec_ = TRUE;

    //
    // inserts pointers to parse nodes representing privilege
    // actions to privActArray_ so the user can access the
    // information about privilege actions easier.
    //

    ComASSERT(pPrivileges NEQ NULL);
    ElemDDLPrivileges * pPrivsNode = pPrivileges->castToElemDDLPrivileges();
    ComASSERT(pPrivsNode NEQ NULL);
    if (pPrivsNode->isAllPrivileges())
    {
        isAllPrivileges_ = TRUE;
    }
    else
    {
        ElemDDLNode * pPrivActs = pPrivsNode->getPrivilegeActionList();
        for (CollIndex i = 0; i < pPrivActs->entries(); i++)
        {
            ElemDDLPrivAct *pPrivAct = (*pPrivActs)[i]->castToElemDDLPrivAct();
            privActArray_.insert(pPrivAct);
        }
    }

    //
    // copies pointers to parse nodes representing grantee
    // to granteeArray_ so the user can access the information
    // easier.
    //

    ComASSERT(pGranteeList NEQ NULL);
    for (CollIndex i = 0; i < pGranteeList->entries(); i++)
    {
        granteeArray_.insert((*pGranteeList)[i]->castToElemDDLGrantee());
    }

} // StmtDDLPublish::StmtDDLPublish()
StmtDDLGrant::StmtDDLGrant(ElemDDLNode * pPrivileges,
                           const QualifiedName & objectName,
                           ElemDDLNode * pGranteeList,
                           ElemDDLNode * pWithGrantOption,
                           ElemDDLNode * pByGrantorOption,
                           QualifiedName * actionName,
                           CollHeap    * heap)
    : StmtDDLNode(DDL_GRANT),
      objectName_(heap),
      objectQualName_(objectName, heap),
      isAllPrivileges_(FALSE),
      isWithGrantOptionSpec_(FALSE),
      privActArray_(heap),
      actionQualName_(actionName),
      granteeArray_(heap),
      isByGrantorOptionSpec_(FALSE),
      byGrantor_(NULL)
{
    setChild(INDEX_PRIVILEGES, pPrivileges);
    setChild(INDEX_GRANTEE_LIST, pGranteeList);
    setChild(INDEX_WITH_GRANT_OPTION, pWithGrantOption);
    setChild(INDEX_BY_GRANTOR_OPTION, pByGrantorOption);
    objectName_ = objectQualName_.getQualifiedNameAsAnsiString();
    //
    // inserts pointers to parse nodes representing privilege
    // actions to privActArray_ so the user can access the
    // information about privilege actions easier.
    //

    ComASSERT(pPrivileges NEQ NULL);
    ElemDDLPrivileges * pPrivsNode = pPrivileges->castToElemDDLPrivileges();
    ComASSERT(pPrivsNode NEQ NULL);
    if (pPrivsNode->isAllPrivileges())
    {
        isAllPrivileges_ = TRUE;
    }
    else
    {
        ElemDDLNode * pPrivActs = pPrivsNode->getPrivilegeActionList();
        for (CollIndex i = 0; i < pPrivActs->entries(); i++)
        {
            ElemDDLPrivAct *pPrivAct = (*pPrivActs)[i]->castToElemDDLPrivAct();
            privActArray_.insert(pPrivAct);
            if (pPrivAct->isDDLPriv())
                privActArray_.setHasDDLPriv(TRUE);
        }
    }

    //
    // copies pointers to parse nodes representing grantee
    // to granteeArray_ so the user can access the information
    // easier.
    //

    ComASSERT(pGranteeList NEQ NULL);
    for (CollIndex i = 0; i < pGranteeList->entries(); i++)
    {
        granteeArray_.insert((*pGranteeList)[i]->castToElemDDLGrantee());
    }

    //
    // looks for With Grant option phrase
    //

    if (pWithGrantOption NEQ NULL)
    {
        isWithGrantOptionSpec_ = TRUE;
    }

    if ( pByGrantorOption NEQ NULL )
    {
        isByGrantorOptionSpec_ = TRUE;
        byGrantor_ = pByGrantorOption->castToElemDDLGrantee();
    }


} // StmtDDLGrant::StmtDDLGrant()
NATraceList
StmtDDLSchRevoke::getDetailInfo() const
{
    NAString        detailText;
    NATraceList detailTextList;

    //
    // object name
    //

    detailTextList.append(displayLabel1());   // object name

    //
    // privileges
    //

    StmtDDLSchRevoke * localThis = (StmtDDLSchRevoke *)this;

    detailTextList.append(localThis->getChild(INDEX_PRIVILEGES)
                          ->castToElemDDLNode()
                          ->castToElemDDLPrivileges()
                          ->getDetailInfo());

    //
    // grantee list
    //

    const ElemDDLGranteeArray & granteeArray = getGranteeArray();

    detailText = "Grantee list [";
    detailText += LongToNAString((Lng32)granteeArray.entries());
    detailText += " element(s)]";
    detailTextList.append(detailText);

    for (CollIndex i = 0; i < granteeArray.entries(); i++)
    {
        detailText = "[grantee ";
        detailText += LongToNAString((Lng32)i);
        detailText += "]";
        detailTextList.append(detailText);

        ComASSERT(granteeArray[i] NEQ NULL AND
                  granteeArray[i]->castToElemDDLGrantee() NEQ NULL);
        detailTextList.append("    ", granteeArray[i]->castToElemDDLGrantee()
                              ->getDetailInfo());
    }

    //
    // grant option for
    //

    detailText = "is grant option for? ";
    detailText += YesNo(isGrantOptionForSpecified());
    detailTextList.append(detailText);

    //
    // drop behavior
    //

    detailTextList.append(displayLabel2());   // drop behavior


    return detailTextList;

} // StmtDDLSchRevoke::getDetailInfo
ExprNode *
StmtDDLSchRevoke::getChild(Lng32 index)
{
    ComASSERT(index >= 0 AND index < getArity());
    return children_[index];
}
StmtDDLSchRevoke::StmtDDLSchRevoke(NABoolean isGrantOptionFor,
                                   ElemDDLNode * pPrivileges,
                                   const ElemDDLSchemaName & aSchemaNameParseNode,
                                   ElemDDLNode * pGranteeList,
                                   ComDropBehavior dropBehavior,
                                   ElemDDLNode * pByGrantorOption,
                                   CollHeap    * heap)
    : StmtDDLNode(DDL_REVOKE_SCHEMA),
      schemaName_(heap),
      schemaQualName_(aSchemaNameParseNode.getSchemaName(), heap),
      isAllDDLPrivileges_(FALSE),
      isAllDMLPrivileges_(FALSE),
      isAllOtherPrivileges_(FALSE),
      isGrantOptionForSpec_(isGrantOptionFor),
      dropBehavior_(dropBehavior),
      privActArray_(heap),
      granteeArray_(heap),
      isByGrantorOptionSpec_(FALSE),
      byGrantor_(NULL)
{

    setChild(INDEX_PRIVILEGES, pPrivileges);
    setChild(INDEX_GRANTEE_LIST, pGranteeList);
    setChild(INDEX_BY_GRANTOR_OPTION, pByGrantorOption);

    //
    // inserts pointers to parse nodes representing privilege
    // actions to privActArray_ so the user can access the
    // information about privilege actions easier.
    //

    ComASSERT(pPrivileges NEQ NULL);
    ElemDDLPrivileges * pPrivsNode = pPrivileges->castToElemDDLPrivileges();
    ComASSERT(pPrivsNode NEQ NULL);
    if (pPrivsNode->isAllPrivileges())
    {
        isAllDDLPrivileges_ = TRUE;
        isAllDMLPrivileges_ = TRUE;
        isAllOtherPrivileges_ = TRUE;
    }
    if (pPrivsNode->isAllDDLPrivileges())
    {
        isAllDDLPrivileges_ = TRUE;
    }
    if (pPrivsNode->isAllDMLPrivileges())
    {
        isAllDMLPrivileges_ = TRUE;
    }
    if (pPrivsNode->isAllOtherPrivileges())
    {
        isAllOtherPrivileges_ = TRUE;
    }

    ElemDDLNode * pPrivActs = pPrivsNode->getPrivilegeActionList();
    if (pPrivActs)
    {
        for (CollIndex i = 0; i < pPrivActs->entries(); i++)
        {
            privActArray_.insert((*pPrivActs)[i]->castToElemDDLPrivAct());
        }
    }

    //
    // copies pointers to parse nodes representing grantee
    // to granteeArray_ so the user can access the information
    // easier.
    //

    ComASSERT(pGranteeList NEQ NULL);
    for (CollIndex i = 0; i < pGranteeList->entries(); i++)
    {
        granteeArray_.insert((*pGranteeList)[i]->castToElemDDLGrantee());
    }

    if ( pByGrantorOption NEQ NULL )
    {
        isByGrantorOptionSpec_ = TRUE;
        byGrantor_ = pByGrantorOption->castToElemDDLGrantee();
    }

} // StmtDDLSchRevoke::StmtDDLSchRevoke()
Esempio n. 21
0
// Gets the length that a given data type would use in the display tool
Lng32 NAType::getDisplayLength(Lng32 datatype,
		    Lng32 length,
		    Lng32 precision,
		    Lng32 scale,
                    Lng32 heading_len) const
{
  Lng32 d_len = 0;

  Int32 scale_len = 0;
  if (scale > 0)
    scale_len = 1;

  switch (datatype)
    {
    case REC_BPINT_UNSIGNED:
      // Can set the display size based on precision. For now treat it as
      // unsigned smallint
      d_len = SQL_USMALL_DISPLAY_SIZE;
      break;

    case REC_BIN16_SIGNED:
      d_len = SQL_SMALL_DISPLAY_SIZE + scale_len;
      break;

    case REC_BIN16_UNSIGNED:
      d_len = SQL_USMALL_DISPLAY_SIZE + scale_len;
      break;

    case REC_BIN32_SIGNED:
      d_len = SQL_INT_DISPLAY_SIZE + scale_len;
      break;

    case REC_BIN32_UNSIGNED:
      d_len = SQL_UINT_DISPLAY_SIZE + scale_len;
      break;

    case REC_BIN64_SIGNED:
      d_len = SQL_LARGE_DISPLAY_SIZE + scale_len;
      break;

    case REC_BYTE_F_ASCII:
      d_len = length;
      break;

   case REC_BYTE_V_ASCII:
   case REC_BYTE_V_ASCII_LONG:
      d_len = length;
      break;

    case REC_DECIMAL_UNSIGNED:
      d_len = length + scale_len;
      break;

    case REC_DECIMAL_LSE:
      d_len = length + 1 + scale_len;
      break;

    case REC_NUM_BIG_SIGNED:
      {
	SQLBigNum tmp(precision,scale,FALSE,TRUE,FALSE,NULL);
	d_len = tmp.getDisplayLength();
      }
      break;

    case REC_NUM_BIG_UNSIGNED:
      {
	SQLBigNum tmp(precision,scale,FALSE,FALSE,FALSE,NULL);
	d_len = tmp.getDisplayLength();
      }
      break;

    case REC_FLOAT32:
    case REC_TDM_FLOAT32:
      d_len = SQL_REAL_DISPLAY_SIZE;
      break;

    case REC_FLOAT64:
    case REC_TDM_FLOAT64:
      d_len = SQL_DOUBLE_PRECISION_DISPLAY_SIZE;
      break;

    case REC_DATETIME:
     /*
      switch (precision) {
      case SQLDTCODE_DATE:
	{
	  SQLDate tmp(FALSE);
	  d_len = tmp.getDisplayLength();
	}
        break;
      case SQLDTCODE_TIME:
	{
	  SQLTime tmp(FALSE, (unsigned) scale);
	  d_len = tmp.getDisplayLength();
	}
        break;
      case SQLDTCODE_TIMESTAMP:
	{
	  SQLTimestamp tmp(FALSE, (unsigned) scale);
	  d_len = tmp.getDisplayLength();
	}
        break;
      default:
        d_len = length;
        break;
      }
      */
      ComASSERT(FALSE);
      break;

    case REC_INT_YEAR:
    case REC_INT_MONTH:
    case REC_INT_YEAR_MONTH:
    case REC_INT_DAY:
    case REC_INT_HOUR:
    case REC_INT_DAY_HOUR:
    case REC_INT_MINUTE:
    case REC_INT_HOUR_MINUTE:
    case REC_INT_DAY_MINUTE:
    case REC_INT_SECOND:
    case REC_INT_MINUTE_SECOND:
    case REC_INT_HOUR_SECOND:
    case REC_INT_DAY_SECOND:
    case REC_INT_FRACTION: {
        rec_datetime_field startField;
        rec_datetime_field endField;
        getIntervalFields(datatype, startField, endField);
        SQLInterval interval(FALSE,
                             startField,
                             (UInt32) precision,
                             endField,
                             (UInt32) scale);
#pragma nowarn(1506)   // warning elimination 
        d_len = interval.getDisplayLength();
#pragma warn(1506)  // warning elimination 
      }
      break;

    case REC_BLOB:
    case REC_CLOB:
      d_len = length;
      break;

    default:
      d_len = length;
      break;
    }

  if (d_len >= heading_len)
    return d_len;
  else
    return heading_len;
}
Esempio n. 22
0
SqlciEnv::SqlciEnv(short serv_type, NABoolean macl_rw_flag)
{
  ole_server = serv_type;
  logfile = new Logfile;
  sqlci_stmts = new SqlciStmts(50);
  prepared_stmts = new SqlciList<PrepStmt>;
  param_list = new SqlciList<Param>;
  pattern_list = new SqlciList<Param>;
  define_list = new SqlciList<Define>;
  envvar_list = new SqlciList<Envvar>;
  cursorList_ = new SqlciList<CursorStmt>;
  sqlci_stats = new SqlciStats();
  terminal_charset_ = CharInfo::ISO88591;
  iso_mapping_charset_ = CharInfo::ISO88591;
  default_charset_ = CharInfo::ISO88591;
  infer_charset_ = FALSE;
  lastDmlStmtStatsType_ = SQLCLIDEV_NO_STATS;
  lastExecutedStmt_ = NULL;
  statsStmt_ = NULL;
  lastAllocatedStmt_ = NULL;

  defaultCatalog_ = NULL;
  defaultSchema_ = NULL;

  doneWithPrologue_ = FALSE;
  noBanner_ = FALSE;

  setListCount(MAX_LISTCOUNT);
  resetSpecialError();
  defaultCatAndSch_ = NULL;

  userNameFromCommandLine_ = "";

  report_env = new SqlciRWEnv(); // initialize the report writer environment variable
  cs_env = new SqlciCSEnv(); // initialize the macl environment variable.

  // A break flag macl_rw_flag was added to the constructor in order for the SqlciEnv
  // constructor not to call the MACL & Report Writer Constructors
  // when the SqlciEnv constructor is called after a break key is hit.

// 64-bit: no more report writer and macl
/*
//  if (macl_rw_flag) {
//    jzLng32 retcode = RW_MXCI_Constructor(report_env->rwEnv(), this);
//    if (retcode == ERR)
//      SqlciError (SQLCI_RW_UNABLE_TO_GET_CONSTRUCTOR,(ErrorParam *) 0 );
//
//    jzLng32 maclretcode = CS_MXCI_Constructor(cs_env->csEnv());
//    if (maclretcode == CSERROR)
//      SqlciError (SQLCI_CS_UNABLE_TO_GET_CONSTRUCTOR,(ErrorParam *) 0 );
//    constructorFlag_ = TRUE;
//  }
//  else 
*/
    constructorFlag_ = FALSE;

  setMode(SqlciEnv::SQL_);		  // Set the mode initially to be SQL
  showShape_ = FALSE;
  eol_seen_on_input = -1;
  obey_file = 0;
  prev_err_flush_input = 0;

  logCommands_ = FALSE;
  deallocateStmt_ = FALSE ; // Always set to FALSE.Set to TRUE only in global_sqlci_env if needed.

// Note that interactive_session is overwritten in SqlciEnv::run(infile) ...
   // Executing on NT
  if ((Int32)cin.tellg() == EOF)
    interactive_session = -1;	// Std. input is terminal keyboard
  else
    interactive_session = 0;
  cin.clear();			// Always clear() bad results from any tellg()

  // Special case for QA testing
  // ---------------------------
  // If sqlci has been started via an exec, ALWAYS deem it to be interactive.
  // Since there is no easy way to determine if we have been exec'ed, we will
  // use an environment variable to decide this. Just the existence of this
  // variable is enough and the value is immaterial.

  if (getenv("QA_TEST_WITH_EXEC")) interactive_session = -1;

#ifndef NDEBUG
  // Ensure that SQLCI sqlcode is same as in ExpError.h
  ComASSERT(SQL_Canceled == -ABS(EXE_CANCELED));
#endif

  prepareOnly_ = NULL;
  executeOnly_ = NULL;
}
void
ParDDLLikeOptsCreateTable::setLikeOption(ElemDDLLikeOpt * pLikeOption)
{
  ComASSERT(pLikeOption != NULL);
  
  switch (pLikeOption->getOperatorType())
  {
  case ELM_LIKE_OPT_WITHOUT_CONSTRAINTS_ELEM :
    if (isLikeOptWithoutConstraintsSpec_)
    {
      *SqlParser_Diags << DgSqlCode(-3149);

      //  "*** Error *** Duplicate WITHOUT CONSTRAINTS phrases "
      //  << "in LIKE clause" << endl;
    }
    ComASSERT(pLikeOption->castToElemDDLLikeOptWithoutConstraints() != NULL);
    isLikeOptWithoutConstraints_ = TRUE;
    isLikeOptWithoutConstraintsSpec_ = TRUE;
    break;

  case ELM_LIKE_OPT_WITH_HEADINGS_ELEM :
    if (isLikeOptWithHeadingsSpec_)
    {
      *SqlParser_Diags << DgSqlCode(-3150);
      //      cout << "*** Error *** Duplicate WITH HEADING phrases "
      //  << "in LIKE clause" << endl;
    }
    ComASSERT(pLikeOption->castToElemDDLLikeOptWithHeadings() != NULL);
    isLikeOptWithHeadings_ = TRUE;
    isLikeOptWithHeadingsSpec_ = TRUE;
    break;

  case ELM_LIKE_OPT_WITH_HORIZONTAL_PARTITIONS_ELEM :
    if (isLikeOptWithHorizontalPartitionsSpec_)
    {
      *SqlParser_Diags << DgSqlCode(-3151);
      //cout << "*** Error *** Duplicate WITH HORIZONTAL PARTITIONS phrases "
      //  << "in LIKE clause" << endl;
    }
    ComASSERT(pLikeOption->castToElemDDLLikeOptWithHorizontalPartitions() != NULL);
    isLikeOptWithHorizontalPartitions_ = TRUE;
    isLikeOptWithHorizontalPartitionsSpec_ = TRUE;
    break;

  case ELM_LIKE_OPT_WITHOUT_SALT_ELEM :
    if (isLikeOptWithoutSaltSpec_)
    {
      // ERROR[3152] Duplicate WITHOUT SALT phrases were specified
      //             in LIKE clause in CREATE TABLE statement.
      *SqlParser_Diags << DgSqlCode(-3152) << DgString0("SALT");
    }
    if (isLikeOptSaltClauseSpec_)
    {
      // ERROR[3154] The WITHOUT SALT clause is not allowed with the SALT clause.
      *SqlParser_Diags << DgSqlCode(-3154) << DgString0("WITHOUT SALT") << DgString1("SALT");
    }
    ComASSERT(pLikeOption->castToElemDDLLikeOptWithoutSalt() != NULL);
    isLikeOptWithoutSalt_ = TRUE;
    isLikeOptWithoutSaltSpec_ = TRUE;
    break;

  case ELM_LIKE_OPT_SALT_CLAUSE_ELEM:
    {  // braces needed since we declare some variables in this case
      if (isLikeOptSaltClauseSpec_)
      {
        // ERROR[3183] Duplicate SALT clauses were specified.
        *SqlParser_Diags << DgSqlCode(-3183) << DgString0("SALT");
      }
      if (isLikeOptWithoutSaltSpec_)
      {
        // ERROR[3154] The WITHOUT SALT clause is not allowed with the SALT clause.
        *SqlParser_Diags << DgSqlCode(-3154) << DgString0("WITHOUT SALT") << DgString1("SALT");
      }
      ComASSERT(pLikeOption->castToElemDDLLikeSaltClause() != NULL);
      isLikeOptSaltClauseSpec_ = TRUE;
      isLikeOptSaltClause_ = new (PARSERHEAP()) NAString();
      ElemDDLLikeSaltClause * saltClauseWrapper = pLikeOption->castToElemDDLLikeSaltClause();
      const ElemDDLSaltOptionsClause * saltOptions = saltClauseWrapper->getSaltClause();
      saltOptions->unparseIt(*isLikeOptSaltClause_ /* side-effected */);
      isLikeOptWithoutSalt_ = TRUE;  // suppresses any SALT clause from the source table
    }
    break;

  case ELM_LIKE_OPT_WITHOUT_DIVISION_ELEM :
    if (isLikeOptWithoutDivisionSpec_)
    {
      // ERROR[3152] Duplicate WITHOUT DIVISION phrases were specified
      //             in LIKE clause in CREATE TABLE statement.
      *SqlParser_Diags << DgSqlCode(-3152) << DgString0("DIVISION");
    }
    ComASSERT(pLikeOption->castToElemDDLLikeOptWithoutDivision() != NULL);
    isLikeOptWithoutDivision_ = TRUE;
    isLikeOptWithoutDivisionSpec_ = TRUE;
    break;

  case ELM_LIKE_OPT_LIMIT_COLUMN_LENGTH:
    {
      if (isLikeOptLimitColumnLengthSpec_)
      {
        // ERROR[3152] Duplicate LIMIT COLUMN LENGTH phrases were specified
        //             in LIKE clause in CREATE TABLE statement.
        *SqlParser_Diags << DgSqlCode(-3152) << DgString0("LIMIT COLUMN LENGTH");
      }
      ComASSERT(pLikeOption->castToElemDDLLikeLimitColumnLength() != NULL);
      ElemDDLLikeLimitColumnLength * limitColumnLength = 
        pLikeOption->castToElemDDLLikeLimitColumnLength();
      isLikeOptColumnLengthLimit_ = limitColumnLength->getColumnLengthLimit();
      isLikeOptLimitColumnLengthSpec_ = TRUE;
    }
    break;

  case ELM_LIKE_OPT_WITHOUT_ROW_FORMAT_ELEM :
    if (isLikeOptWithoutRowFormatSpec_)
    {
      // ERROR[3152] Duplicate WITHOUT ROW FORMAT phrases were specified
      //             in LIKE clause in CREATE TABLE statement.
      *SqlParser_Diags << DgSqlCode(-3152) << DgString0("ROW FORMAT");
    }
    ComASSERT(pLikeOption->castToElemDDLLikeOptWithoutRowFormat() != NULL);
    isLikeOptWithoutRowFormat_ = TRUE;
    isLikeOptWithoutRowFormatSpec_ = TRUE;
    break;

  default :
    NAAbort("ParDDLLikeOpts.C", __LINE__, "internal logic error");
    break;
  }
} // ParDDLLikeOptsCreateTable::setLikeOption()
ExprNode *
ElemDDLList::getChild(Lng32 index)
{ 
  ComASSERT(index >= 0 AND index < getArity());
  return children_[index];
}
void
ParDDLLikeOptsCreateTable::setLikeOption(ElemDDLLikeOpt * pLikeOption)
{
  ComASSERT(pLikeOption != NULL);
  
  switch (pLikeOption->getOperatorType())
  {
  case ELM_LIKE_OPT_WITHOUT_CONSTRAINTS_ELEM :
    if (isLikeOptWithoutConstraintsSpec_)
    {
      *SqlParser_Diags << DgSqlCode(-3149);

      //  "*** Error *** Duplicate WITHOUT CONSTRAINTS phrases "
      //  << "in LIKE clause" << endl;
    }
    ComASSERT(pLikeOption->castToElemDDLLikeOptWithoutConstraints() != NULL);
    isLikeOptWithoutConstraints_ = TRUE;
    isLikeOptWithoutConstraintsSpec_ = TRUE;
    break;

  case ELM_LIKE_OPT_WITH_HEADINGS_ELEM :
    if (isLikeOptWithHeadingsSpec_)
    {
      *SqlParser_Diags << DgSqlCode(-3150);
      //      cout << "*** Error *** Duplicate WITH HEADING phrases "
      //  << "in LIKE clause" << endl;
    }
    ComASSERT(pLikeOption->castToElemDDLLikeOptWithHeadings() != NULL);
    isLikeOptWithHeadings_ = TRUE;
    isLikeOptWithHeadingsSpec_ = TRUE;
    break;

  case ELM_LIKE_OPT_WITH_HORIZONTAL_PARTITIONS_ELEM :
    if (isLikeOptWithHorizontalPartitionsSpec_)
    {
      *SqlParser_Diags << DgSqlCode(-3151);
      //cout << "*** Error *** Duplicate WITH HORIZONTAL PARTITIONS phrases "
      //  << "in LIKE clause" << endl;
    }
    ComASSERT(pLikeOption->castToElemDDLLikeOptWithHorizontalPartitions() != NULL);
    isLikeOptWithHorizontalPartitions_ = TRUE;
    isLikeOptWithHorizontalPartitionsSpec_ = TRUE;
    break;

  case ELM_LIKE_OPT_WITHOUT_SALT_ELEM :
    if (isLikeOptWithoutSaltSpec_)
    {
      // ERROR[3152] Duplicate WITHOUT SALT phrases were specified
      //             in LIKE clause in CREATE TABLE statement.
      *SqlParser_Diags << DgSqlCode(-3152) << DgString0("SALT");
    }
    ComASSERT(pLikeOption->castToElemDDLLikeOptWithoutSalt() != NULL);
    isLikeOptWithoutSalt_ = TRUE;
    isLikeOptWithoutSaltSpec_ = TRUE;
    break;

  case ELM_LIKE_OPT_WITHOUT_DIVISION_ELEM :
    if (isLikeOptWithoutDivisionSpec_)
    {
      // ERROR[3152] Duplicate WITHOUT DIVISION phrases were specified
      //             in LIKE clause in CREATE TABLE statement.
      *SqlParser_Diags << DgSqlCode(-3152) << DgString0("DIVISION");
    }
    ComASSERT(pLikeOption->castToElemDDLLikeOptWithoutDivision() != NULL);
    isLikeOptWithoutDivision_ = TRUE;
    isLikeOptWithoutDivisionSpec_ = TRUE;
    break;

  default :
    NAAbort("ParDDLLikeOpts.C", __LINE__, "internal logic error");
    break;
  }
} // ParDDLLikeOptsCreateTable::setLikeOption()
void
ElemDDLColDef::setColumnAttribute(ElemDDLNode * pColAttr)
{
  switch(pColAttr->getOperatorType())
  {
  case ELM_COL_HEADING_ELEM :
    if (isHeadingSpec_)
    {
       // Duplicate HEADING clauses in column definition.
      *SqlParser_Diags << DgSqlCode(-3051)
                       << DgColumnName(ToAnsiIdentifier(getColumnName()));
    }
    ComASSERT(pColAttr->castToElemDDLColHeading() NEQ NULL);
    heading_ = pColAttr->castToElemDDLColHeading()->getColumnHeading();
    isHeadingSpec_ = TRUE;

    // Report an error if heading_ is too long.
    if (heading_.length() > ElemDDLColHeading::maxHeadingLength)
    {
      *SqlParser_Diags << DgSqlCode(-3132)
                       << DgColumnName(ToAnsiIdentifier(getColumnName())); 
    }
    break;

  case ELM_CONSTRAINT_CHECK_ELEM :
    ComASSERT(pColAttr->castToElemDDLConstraintCheck() NEQ NULL);
    columnConstraintArray_.insert(pColAttr->castToElemDDLConstraint());
    break;

  case ELM_CONSTRAINT_NOT_NULL_ELEM :
    ComASSERT(pColAttr->castToElemDDLConstraintNotNull() NEQ NULL);
    if (isNotNullSpec_)
    {
      // Duplicate NOT NULL clauses in column definition.
      *SqlParser_Diags << DgSqlCode(-3052)
                       << DgString0("NOT NULL")
                       << DgColumnName(ToAnsiIdentifier(getColumnName()));
    }
    isNotNullSpec_ = TRUE;
    pConstraintNotNull_ = pColAttr->castToElemDDLConstraintNotNull();

    if (NOT pConstraintNotNull_->isDroppable())
      {
	isNotNullNondroppable_ = TRUE;    
	if (columnDataType_)
	  columnDataType_->setNullable(FALSE);
      }

    // Note that we do not insert pConstraintNotNull_ into
    // columnConstraintArray_ even though Not Null constraint is
    // also a column constraint.  The user can use the accessors
    // getIsConstraintNotNullSpecified and getConstraintNotNull
    // instead.

    break;


  case ELM_LOGGABLE:
	  ComASSERT( NULL NEQ pColAttr->castToElemDDLLoggable())
		if(TRUE == isLoggableSpec_)
		{
			// Duplicate LOGGABLE in column definition.
			*SqlParser_Diags << DgSqlCode(-12064)
						   << DgColumnName(ToAnsiIdentifier(getColumnName()));
		}

		isLoggableSpec_ = TRUE;
		isLoggable_ = pColAttr->castToElemDDLLoggable()->getIsLoggable();
		break;


  case ELM_CONSTRAINT_PRIMARY_KEY_COLUMN_ELEM :
    {
      ComASSERT(pColAttr->castToElemDDLConstraintPKColumn() NEQ NULL);
      ComASSERT(pColAttr->castToElemDDLConstraintPKColumn()
                        ->getConstraintKind()
             EQU ElemDDLConstraint::COLUMN_CONSTRAINT_DEF);
      if (isPrimaryKeySpec_)
      {
	// Duplicate PRIMARY KEY clauses in column definition.
	*SqlParser_Diags << DgSqlCode(-3053)
                         << DgColumnName(ToAnsiIdentifier(getColumnName()));
      }
      isPrimaryKeySpec_ = TRUE;
      ElemDDLConstraintPKColumn * pColPKConstraint =
                                  pColAttr->castToElemDDLConstraintPKColumn();
      //
      // Copies the pointer to the parse node representing the column
      // primary key constraint to pConstraintPK_ so the user (caller)
      // can access the information easier.  Note that this pointer is
      // not inserted into columnConstraintArray_ because primary key
      // constraint is special.  (There can only be one primary key
      // constraint associating with a table.)  The user (caller) can
      // use method getIsConstraintPKSpecified() and getConstraintPK()
      // to get the primary key constraint information.
      //
      pConstraintPK_ = pColPKConstraint;

      // The column name is not specified in the column primary key
      // constraint definition.  To make the user (caller) to access
      // to this information easier, creates a parse node containing
      // the column name.
      
      ComASSERT(pColPKConstraint->getColumnRefList() EQU NULL);
      ElemDDLColRef * pColRef = new(PARSERHEAP())
	ElemDDLColRef(getColumnName(),
		      pColPKConstraint->
		      getColumnOrdering(),
                      PARSERHEAP());
      pColPKConstraint->setColumnRefList(pColRef);
      primaryKeyColRefArray_.insert(pColRef);
    }
    break;

  case ELM_CONSTRAINT_REFERENTIAL_INTEGRITY_ELEM :
    {
      ComASSERT(pColAttr->castToElemDDLConstraintRI() NEQ NULL);
      ComASSERT(pColAttr->castToElemDDLConstraintRI()->getConstraintKind()
                EQU ElemDDLConstraint::COLUMN_CONSTRAINT_DEF);
      columnConstraintArray_.insert(pColAttr->castToElemDDLConstraint());
      //
      // The column name is not specified in the column referential
      // integrity constraint definition.  To make the user (caller)
      // to access to this information easier, creates a parse node
      // containing the column name.
      //
      ElemDDLConstraintRI * pColRIConstraint =
                            pColAttr->castToElemDDLConstraintRI();
      ComASSERT(pColRIConstraint->getReferencingColumnNameList() EQU NULL);
      ElemDDLColName * pColName = new(PARSERHEAP())
	ElemDDLColName(getColumnName());
      pColRIConstraint->setReferencingColumnNameList(pColName);
    }
    break;

  case ELM_CONSTRAINT_UNIQUE_ELEM :
    {
      ComASSERT(pColAttr->castToElemDDLConstraintUnique() NEQ NULL);
      ComASSERT(pColAttr->castToElemDDLConstraintUnique()->getConstraintKind()
                EQU ElemDDLConstraint::COLUMN_CONSTRAINT_DEF);
      columnConstraintArray_.insert(pColAttr->castToElemDDLConstraint());
      //
      // The column name is not specified in the column unique
      // constraint definition.  To make the user (caller) to access
      // to this information easier, creates a parse node containing
      // the column name.
      //
      ElemDDLConstraintUnique * pColUniqueConstraint =
                                pColAttr->castToElemDDLConstraintUnique();
      ComASSERT(pColUniqueConstraint->getColumnRefList() EQU NULL);
      ElemDDLColRef * pColRef = new(PARSERHEAP())
	ElemDDLColRef(getColumnName(),
		      COM_ASCENDING_ORDER,
		      PARSERHEAP());
      pColUniqueConstraint->setColumnRefList(pColRef);
    }
    break;

  case ELM_LOBATTRS:
    {
      ComASSERT( NULL NEQ pColAttr->castToElemDDLLobAttrs())
	if(TRUE == isLobAttrsSpec_)
	  {
	    // Duplicate LOB attrs in column definition.
            *SqlParser_Diags << DgSqlCode(-3052)
                             << DgString0("LOB")
                             << DgColumnName(ToAnsiIdentifier(getColumnName()));
	  }
      
      isLobAttrsSpec_ = TRUE;
      lobStorage_ = pColAttr->castToElemDDLLobAttrs()->getLobStorage();
    }
    break;

  case ELM_SEABASE_SERIALIZED:
    {
      ComASSERT( NULL NEQ pColAttr->castToElemDDLSeabaseSerialized())
	if(TRUE == isSeabaseSerializedSpec_)
	  {
	    // Duplicate SERIALIZED attrs in column definition.
            *SqlParser_Diags << DgSqlCode(-3052)
                             << DgString0("SERIALIZED")
                             << DgColumnName(ToAnsiIdentifier(getColumnName()));
	  }
      
      isSeabaseSerializedSpec_ = TRUE;
      seabaseSerialized_ =  pColAttr->castToElemDDLSeabaseSerialized()->serialized();
    }
    break;

  case ELM_COL_DEFAULT_ELEM:
    {
      ComASSERT( NULL NEQ pColAttr->castToElemDDLColDefault());
	if(TRUE == isColDefaultSpec_)
	  {
	    // Duplicate DEFAULT attrs in column definition.
            *SqlParser_Diags << DgSqlCode(-3052)
                             << DgString0("DEFAULT")
                             << DgColumnName(ToAnsiIdentifier(getColumnName()));
	  }
      
      isColDefaultSpec_ = TRUE;
      setDefaultAttribute(pColAttr->castToElemDDLColDefault());
    }
    break;

  default :
    ABORT("internal logic error");
    break;
    
  }  // switch
}
ExprNode *
ElemDDLMVFileAttrClause::getChild(Lng32 index)
{ 
  ComASSERT(index >= 0 AND index < getArity());
  return children_[index];
}
// constructor
ElemDDLConstraintRI::ElemDDLConstraintRI(
     ElemDDLNode * pReferencedTableAndColumns,
     ComRCMatchOption matchType,
     ElemDDLNode * pReferentialTriggeredActions,
     CollHeap    * heap)

: ElemDDLConstraint(heap, ELM_CONSTRAINT_REFERENTIAL_INTEGRITY_ELEM),
  matchType_(matchType),
  isDeleteRuleSpec_(FALSE),
  deleteRule_(COM_NO_ACTION_DELETE_RULE),
  isUpdateRuleSpec_(FALSE),
  updateRule_(COM_NO_ACTION_UPDATE_RULE),
  referencingColumnNameArray_(heap),
  referencedColumnNameArray_(heap)
{
  setChild(INDEX_REFERENCING_COLUMN_NAME_LIST, NULL);
  setChild(INDEX_REFERENCED_TABLE_AND_COLUMNS, pReferencedTableAndColumns);
  setChild(INDEX_REFERENTIAL_TRIGGERED_ACTIONS, pReferentialTriggeredActions);

  //
  // Note that at the point this parse node is contructed, the information
  // regarding the referencing column name list (in the FOREIGN KEY phrase)
  // has not been collected yet.
  //

  //
  // referenced table name
  //

  ComASSERT(pReferencedTableAndColumns);
  ElemDDLReferences * pReferences = pReferencedTableAndColumns
        ->castToElemDDLReferences();
  ComASSERT(pReferences);

  //
  // referenced column name list (if any)
  //

  ElemDDLNode * pReferencedColumns = pReferences->getReferencedColumns();
  if (pReferencedColumns)
  {
    for (CollIndex index = 0; index < pReferencedColumns->entries(); index++)
    {
      referencedColumnNameArray_.insert((*pReferencedColumns)[index]
                                        ->castToElemDDLColName());
    }
  }

  //
  // referential triggered actions
  //

  if (pReferentialTriggeredActions)
  {
    for (CollIndex i = 0; i < pReferentialTriggeredActions->entries(); i++)
    {
      ComASSERT((*pReferentialTriggeredActions)[i]);
      setReferentialTriggeredAction((*pReferentialTriggeredActions)[i]
                                    ->castToElemDDLRefTrigAct());
    }
  }

} // ElemDDLConstraintRI::ElemDDLConstraintRI()
ExprNode *
ElemDDLLike::getChild(Lng32 index)
{ 
  ComASSERT(index >= 0 AND index < MAX_ELEM_DDL_LIKE_ARITY);
  return pLikeOptions_;
}
// method for building text
//virtual 
NAString ElemDDLPartitionClause::getSyntax() const
{
  NAString syntax = "";
  
  switch(partitionType_)
  {
  case COM_SYSTEM_PARTITIONING:
    // this is the default - no syntax
    break;
  case COM_RANGE_PARTITIONING:
    syntax += "RANGE ";
    break;
  case COM_HASH_V1_PARTITIONING:
    syntax += "HASH ";
    break;
  case COM_HASH_V2_PARTITIONING:
    syntax += "HASH2 ";
    break;
  default:
    ComASSERT(FALSE);
  }

  syntax += "PARTITION ";


  ElemDDLNode * pElemDDL = getPartitionByOption();

  if(NULL != pElemDDL)
  {
    ElemDDLPartitionByColumnList * pPartitionByColList = 
			      pElemDDL->castToElemDDLPartitionByColumnList();

    ComASSERT(NULL != pPartitionByColList);

    syntax += "BY ";
    syntax += "(";
    syntax += pPartitionByColList->getSyntax();
    syntax += ") ";

  }

  pElemDDL = getPartitionDefBody();
  if(NULL != pElemDDL)
  {
    // pElemDDL dynamic type returned from the parser can be either an 
    // ElemDDLPartitionList or an ElemDDLPartitionRange
    ElemDDLPartitionList * pPartitionList = 
				      pElemDDL->castToElemDDLPartitionList();

    ElemDDLPartitionRange *pRange = pElemDDL->castToElemDDLPartitionRange();

    //++ MV
    syntax += "(";
    if(NULL != pPartitionList) 
    {
      syntax += pPartitionList->getSyntax();
    } 
    else 
    {
      ComASSERT(NULL != pRange);
      syntax += pRange->getSyntax();
    }
    syntax += ") ";
    //-- MV
  }


  return syntax;
} // getSyntax()