void ElemDDLColViewDef::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; default : ABORT("internal logic error"); break; } // switch }
boost::python::dict NtTable::createStructureDict(const boost::python::list& scalarTypePyList) { boost::python::list pyList; pyList.append(PvType::String); boost::python::dict pyDict; pyDict[LabelsFieldKey] = pyList; boost::python::dict pyDict2; for (int column = 0; column < boost::python::len(scalarTypePyList); column++) { boost::python::extract<int> scalarTypeExtract(scalarTypePyList[column]); if (scalarTypeExtract.check()) { PvType::ScalarType scalarType = static_cast<PvType::ScalarType>(scalarTypeExtract()); boost::python::list pyList2; pyList2.append(scalarType); std::string columnName = getColumnName(column); pyDict2[columnName] = pyList2; } else { throw InvalidArgument("Element list must be valid PV scalar type."); } } pyDict[ValueFieldKey] = pyDict2; pyDict[DescriptorFieldKey] = PvType::String; pyDict[TimeStampFieldKey] = PvTimeStamp::createStructureDict(); pyDict[AlarmFieldKey] = PvAlarm::createStructureDict(); return pyDict; }
vnl_vector<double> RtDesignMatrix::getArtifactTimepoints() { // initialize return vector vnl_vector<double> listOfTr(numArtifacts, 0); unsigned int foundArt = 0; // loop through all columns for (unsigned int col = 0; col < getNumColumns(); col++) { // look for column name "artifact" if (!strcmp(getColumnName(col).c_str(), "artifact")) { vnl_vector<double> curCol = getColumn(col); // go through rows to find artifact timepoint for (unsigned int row = 0; row < getNumRows(); row++) { if (curCol[row] == 1) { listOfTr.put(foundArt, row); foundArt++; break; // go to next col } } } } return listOfTr; }
NAString ElemDDLColDef::getColDefAsText() const { NAString text; text = getColumnName(); text += " "; if (getColumnDataType()) { getColumnDataType()->getMyTypeAsText(&text, FALSE); } text += " "; if (getDefaultClauseStatus() == NO_DEFAULT_CLAUSE_SPEC) { text += "NO DEFAULT "; } else if (getDefaultValueExpr() NEQ NULL) { if (getDefaultValueExpr()->getOperatorType() == ITM_IDENTITY) { text += "GENERATED BY DEFAULT AS IDENTITY "; } else { text += "DEFAULT "; text += getDefaultValueExpr()->getText(); } } text += " "; if (getIsConstraintNotNullSpecified()) { text += "NOT NULL NOT DROPPABLE"; } text += " "; if (getIsConstraintPKSpecified()) { text += "PRIMARY KEY "; } for (CollIndex i = 0; i < columnConstraintArray_.entries(); i++) { ElemDDLNode * pColAttr = columnConstraintArray_[i]; if ((pColAttr) && (pColAttr->castToElemDDLConstraintUnique()) && (pColAttr->castToElemDDLConstraintUnique()->getConstraintKind() EQU ElemDDLConstraint::COLUMN_CONSTRAINT_DEF)) { text += "UNIQUE "; } } return text; }
void NtTable::setColumn(int column, const boost::python::list& pyList) { if (column < 0 || column >= nColumns) { throw InvalidArgument("Column index must be in range [0,%d].", nColumns-1); } std::string columnName = getColumnName(column); epics::pvData::PVStructurePtr pvStructurePtr2 = PyPvDataUtility::getStructureField(ValueFieldKey, pvStructurePtr); PyPvDataUtility::pyListToScalarArrayField(pyList, columnName, pvStructurePtr2); }
int DBResult::getColumnIndex (const std::string& columnName) const { for (int i=0; i<getNbColumns (); ++i) { if (getColumnName (i) == columnName) return i; } return -1; }
Record::FieldNames DBResult::getFieldNames() const { FieldNames result; size_t nbcol(getNbColumns()); for(size_t icol(0); icol<nbcol; ++icol) { result.push_back(getColumnName(icol)); } return result; }
virtual QStringList getColumnNames() { QStringList ret; int count = getColumnCount(); for (int i = 0; i < count; ++i) { ret << getColumnName(i); } return ret; }
boost::python::list NtTable::getColumn(int column) const { if (column < 0 || column >= nColumns) { throw InvalidArgument("Column index must be in range [0,%d].", nColumns-1); } std::string columnName = getColumnName(column); boost::python::list pyList; epics::pvData::PVStructurePtr pvStructurePtr2 = PyPvDataUtility::getStructureField(ValueFieldKey, pvStructurePtr); PyPvDataUtility::scalarArrayFieldToPyList(columnName, pvStructurePtr2, pyList); return pyList; }
void drawTitle() { setFont(verdana18_bold); // draw title of current plot fill(0); textSize(20); textAlign(TX_LEFT, TX_BOTTOM); const char * title = getColumnName(currentColumn); text(title, plotX1, plotY1 - 20); }
attribs_map ResultSet::getTupleValues(void) { attribs_map tup_vals; if(current_tuple < 0 || current_tuple >= getTupleCount()) throw Exception(ERR_REF_TUPLE_INEXISTENT, __PRETTY_FUNCTION__, __FILE__, __LINE__); for(int col=0; col < getColumnCount(); col++) tup_vals[getColumnName(col)]=getColumnValue(col); return(tup_vals); }
std::vector<int> DBResult::computeMaxColWidths () const { std::vector<int> widths; for (int c=0; c<getNbColumns (); ++c) { size_t max = 0; std::string name (getColumnName (c)); if (name.length () > max) max = name.length (); while (next()) { std::string value (getText (c)); if (value.length () > max) max = value.length (); } reset(); widths.push_back (max); } return widths; }
boost::python::dict NtTable::createStructureDict(int nColumns, PvType::ScalarType scalarType) { if (nColumns < 0) { throw InvalidArgument("Number of columns cannot be negative."); } boost::python::list pyList; pyList.append(PvType::String); boost::python::dict pyDict; pyDict[LabelsFieldKey] = pyList; boost::python::dict pyDict2; for (int column = 0; column < nColumns; column++) { std::string columnName = getColumnName(column); boost::python::list pyList2; pyList2.append(scalarType); pyDict2[columnName] = pyList2; } pyDict[ValueFieldKey] = pyDict2; pyDict[DescriptorFieldKey] = PvType::String; pyDict[TimeStampFieldKey] = PvTimeStamp::createStructureDict(); pyDict[AlarmFieldKey] = PvAlarm::createStructureDict(); return pyDict; }
// constructor ElemDDLColNameArray::ElemDDLColNameArray(CollHeap *heap) : LIST(ElemDDLColName *)(heap) { } // virtual destructor ElemDDLColNameArray::~ElemDDLColNameArray() { } // ----------------------------------------------------------------------- // methods for class ElemDDLColRef // ----------------------------------------------------------------------- // virtual destructor ElemDDLColRef::~ElemDDLColRef() { } // cast virtual function ElemDDLColRef * ElemDDLColRef::castToElemDDLColRef() { return this; } // accessor NAString ElemDDLColRef::getColumnOrderingAsNAString() const { switch(getColumnOrdering()) { case COM_ASCENDING_ORDER : return NAString("Ascending"); case COM_DESCENDING_ORDER : return NAString("Descending"); default : ABORT("internal logic error"); return NAString(); } } // // methods for tracing // const NAString ElemDDLColRef::getText() const { return "ElemDDLColRef"; } const NAString ElemDDLColRef::displayLabel1() const { return NAString("Column name: ") + getColumnName(); } const NAString ElemDDLColRef::displayLabel2() const { return NAString("Order: ") + getColumnOrderingAsNAString(); } // ----------------------------------------------------------------------- // methods for class ElemDDLColRefArray // ----------------------------------------------------------------------- // constructor ElemDDLColRefArray::ElemDDLColRefArray(CollHeap *heap) : LIST(ElemDDLColRef *)(heap) { } // virtual destructor ElemDDLColRefArray::~ElemDDLColRefArray() { } // see if this ElemDDLColRefArray has other ElemDDLColRefArray // as a prefix. ComBoolean ElemDDLColRefArray::hasPrefix(ElemDDLColRefArray &other) { Int32 otherEntryCount = other.entries(); Int32 thisEntryCount = this->entries(); // See if this array has atleast as many entries as the // other. if (thisEntryCount < otherEntryCount) return FALSE; Int32 i = 0; for(; i < otherEntryCount; i++) { if ((*this)[i]->getColumnName() != other[i]->getColumnName()) break; if ((*this)[i]->getColumnOrdering() != other[i]->getColumnOrdering()) break; } if (i == otherEntryCount) return TRUE; else return FALSE; }
void ResultBuilder::build(const bool columnNames) { if (mError==true) return; // Set up the columns try { const int count = getColumnCount(); if (count < 1) { // I think a count of 0 isn't technically an error, because the result set might just be empty. if (count < 0) mError = true; return; } for (int k=0; k<count; ++k) { const int ct = getColumnType(k); if (ct == QUERY_NO_TYPE) mError = true; else mResult.mCol.push_back(ct); if (columnNames) { mResult.mColNames.push_back(getColumnName(k)); } } } catch (std::exception&) { mError = true; return; } // Empty results are considered valid. if (!hasNext()) return; if (mError == true || mResult.mCol.size() < 1) { mError = true; return; } // Read the rows while (hasNext()) { startRow(); for (int k=0; k<mResult.mCol.size(); k++) { const int col = mResult.mCol.data()[k]; if (col == QUERY_NUMERIC) { double v = 0.0f; if (!getDouble(k, v)) mError = true; addNumeric(v); } else if (col == QUERY_STRING) { string v; if (!getString(k, v)) mError = true; addString(v); } else if (col == QUERY_NULL) { // I can't determine at any point the actual type of the column, // because it looks like sqlite always bases that info on the first // row in the result set. So in this case, I've got to just get // every type. double v = 0.0f; if (!getDouble(k, v)) v = 0.0f; addNumeric(v); --mColIdx; string str; getString(k, str); addString(str); } } next(); } }
/** Gets name (if column does not exist then NULL) */ inline const char *getColName(int whichColumn) const { return getColumnName(whichColumn); }
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; } } }
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 }
// constructor ElemDDLColDef::ElemDDLColDef( const NAString *columnFamily, const NAString *columnName, NAType * pColumnDataType, ElemDDLNode * pColAttrList, CollHeap * heap) : ElemDDLNode(ELM_COL_DEF_ELEM), columnName_(*columnName, heap), columnDataType_(pColumnDataType), defaultClauseStatus_(DEFAULT_CLAUSE_NOT_SPEC), isNewAdjustedDefaultConstValueNode_(FALSE), pDefault_(NULL), isHeadingSpec_(FALSE), heading_(heap), columnClass_(COM_USER_COLUMN), isNotNullSpec_(FALSE), isNotNullNondroppable_(FALSE), isLoggableSpec_(FALSE), isLoggable_(TRUE), pConstraintNotNull_(NULL), isPrimaryKeySpec_(FALSE), pConstraintPK_(NULL), columnConstraintArray_(heap), primaryKeyColRefArray_(heap), direction_(COM_OUTPUT_COLUMN), pSGOptions_(NULL), pSGLocation_(NULL), isDivisionColumn_(FALSE), divisionColumnSeqNum_(-1), isLobAttrsSpec_(FALSE), lobStorage_(Lob_HDFS_File), isSeabaseSerializedSpec_(FALSE), seabaseSerialized_(FALSE), isColDefaultSpec_(FALSE) { // ComASSERT(pColumnDataType NEQ NULL); if (columnFamily) columnFamily_ = *columnFamily; if (pColumnDataType NEQ NULL) { const NAString dataTypeName = pColumnDataType->getTypeName(); // Create table with data type DATETIME not supported. Must check for DATE, // TIME, and TIMESTAMP as well since DATETIME might be converted into these, if( dataTypeName == "DATETIME" || dataTypeName == "DATE" || dataTypeName == "TIME" || dataTypeName == "TIMESTAMP" ) { // Check flag to see if DATETIME originally specified if( ((DatetimeIntervalCommonType *)pColumnDataType)-> getDTIFlag(DatetimeIntervalCommonType::UNSUPPORTED_DDL_DATA_TYPE)) { // Only put error into diags if it doesn't already contain it if(!SqlParser_Diags->contains(-3195)) { *SqlParser_Diags << DgSqlCode(-3195) << DgString0("DATETIME"); } return; } } // Create table with data type INTERVAL with FRACTION field(s) not supported else if (dataTypeName == "INTERVAL") { // Check flag to see if FRACTION was originally specified if( ((DatetimeIntervalCommonType *)pColumnDataType)-> getDTIFlag(DatetimeIntervalCommonType::UNSUPPORTED_DDL_DATA_TYPE)) { // Only put error into diags if it doesn't already contain it if(!SqlParser_Diags->contains(-3195)) { *SqlParser_Diags << DgSqlCode(-3195) << DgString0("INTERVAL with FRACTION field(s)"); } return; } // Check to see if interval second is specified with leading // precision of 0 if(!((SQLInterval *)pColumnDataType)->isSupportedType()) { // Only put error into diags if it doesn't already contain it if(!SqlParser_Diags->contains(-3195)) { *SqlParser_Diags << DgSqlCode(-3195) << DgString0("INTERVAL SECOND with leading precision 0"); } return; } } } setChild(INDEX_ELEM_DDL_COL_ATTR_LIST, pColAttrList); // initialize data member pDefault_ ComBoolean isIdentityColumn = FALSE; // // Traverse the list of column attributes to check for duplicate // HEADING clause and duplicate NOT NULL column constraint definition // if (pColAttrList NEQ NULL) { for (CollIndex index = 0; index < pColAttrList->entries(); index++) { setColumnAttribute((*pColAttrList)[index]); } } // At this point we will know if the user // has specified NOT NULL NOT DROPPABLE for IDENTITY // column. If not specified, then automatically add // it. if (pSGOptions_) //isIdentityColumn { // if NOT NULL not specified, then specify it here. if(NOT getIsConstraintNotNullSpecified()) isNotNullSpec_ = TRUE; // [NOT] DROPPABLE is the only attribute for NOT NULL. if (pConstraintNotNull_) { // if DROPPABLE was specified explicity then raise an error. if (pConstraintNotNull_->isDroppableSpecifiedExplicitly()) { *SqlParser_Diags << DgSqlCode(-3413) << DgColumnName(ToAnsiIdentifier(getColumnName())); return; } else { // add the NOT DROPPABLE attribute to the NOT NULL . pConstraintNotNull_->setConstraintAttributes (new (PARSERHEAP()) ElemDDLConstraintAttrDroppable(FALSE)); } } else { // by default NOT NULLs are NOT DROPPABLEs as well in SQL/MX pConstraintNotNull_ = new (PARSERHEAP()) ElemDDLConstraintNotNull(PARSERHEAP()); pConstraintNotNull_->setConstraintAttributes (new (PARSERHEAP()) ElemDDLConstraintAttrDroppable(FALSE)); } } //if isIdentityColumn // // All column attributes has been checked and saved. // If there exists a NOT NULL NONDROPPABLE constraint // associating with the currently defined column, makes // sure that the associating NAType (data type) parse // node does not allow null values. // if (getIsConstraintNotNullSpecified() AND NOT getConstraintNotNull()->isDroppable()) { isNotNullNondroppable_ = TRUE; if (columnDataType_) columnDataType_->setNullable(FALSE); } } // ElemDDLColDef()
const NAString ElemDDLColDef::displayLabel1() const { return NAString("Column name: ") + getColumnName(); }