OHSQLTable::OHSQLTable( sdbcx::OCollection* _pTables, const Reference< XConnection >& _xConnection)
:OTableHelper(_pTables,_xConnection,true)
{ // we create a new table here, so we should have all the rights or ;-)
m_nPrivileges = Privilege::DROP |
Privilege::REFERENCE |
Privilege::ALTER |
Privilege::CREATE |
Privilege::READ |
Privilege::DELETE |
Privilege::UPDATE |
Privilege::INSERT |
Privilege::SELECT;
construct();
}
if ( !m_xColumns || !m_xColumns->hasByName(colName) ) throw NoSuchElementException(colName,*this);
if ( !isNew() )
{ // first we have to check what should be altered
Reference<XPropertySet> xProp;
m_xColumns->getByName(colName) >>= xProp; // first check the types
sal_Int32 nOldType = 0,nNewType = 0,nOldPrec = 0,nNewPrec = 0,nOldScale = 0,nNewScale = 0;
OUString sOldTypeName, sNewTypeName;
// and precision and scale
xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_PRECISION)) >>= nOldPrec;
descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_PRECISION))>>= nNewPrec;
xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_SCALE)) >>= nOldScale;
descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_SCALE)) >>= nNewScale;
// second: check the "is nullable" value
sal_Int32 nOldNullable = 0,nNewNullable = 0;
xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISNULLABLE)) >>= nOldNullable;
descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISNULLABLE)) >>= nNewNullable;
// check also the auto_increment bool bOldAutoIncrement = false,bAutoIncrement = false;
xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bOldAutoIncrement;
descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bAutoIncrement;
// now we should look if the name of the column changed
OUString sNewColumnName;
descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_NAME)) >>= sNewColumnName; if ( sNewColumnName != colName )
{ const OUString sQuote = getMetaData()->getIdentifierQuoteString( );
OUString sSql = getAlterTableColumnPart() + " ALTER COLUMN " +
::dbtools::quoteName(sQuote,colName) + " RENAME TO " +
::dbtools::quoteName(sQuote,sNewColumnName);
executeStatement(sSql);
}
if ( nOldType != nNewType
|| sOldTypeName != sNewTypeName
|| nOldPrec != nNewPrec
|| nOldScale != nNewScale
|| nNewNullable != nOldNullable
|| bOldAutoIncrement != bAutoIncrement )
{ // special handling because they change the type names to distinguish // if a column should be an auto_increment one if ( bOldAutoIncrement != bAutoIncrement )
{ /// TODO: insert special handling for auto increment "IDENTITY" and primary key
}
alterColumnType(nNewType,sNewColumnName,descriptor);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.