/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
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.