1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 30*cdf0e10cSrcweir #include "hsqldb/HTable.hxx" 31*cdf0e10cSrcweir #include "hsqldb/HTables.hxx" 32*cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/sdbcx/KeyType.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/sdbc/KeyRule.hpp> 36*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 37*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/sdbcx/Privilege.hpp> 40*cdf0e10cSrcweir #include <comphelper/property.hxx> 41*cdf0e10cSrcweir #include <comphelper/extract.hxx> 42*cdf0e10cSrcweir #include <comphelper/types.hxx> 43*cdf0e10cSrcweir #include "connectivity/dbtools.hxx" 44*cdf0e10cSrcweir #include "connectivity/sdbcx/VColumn.hxx" 45*cdf0e10cSrcweir #include "connectivity/TKeys.hxx" 46*cdf0e10cSrcweir #include "connectivity/TIndexes.hxx" 47*cdf0e10cSrcweir #include "connectivity/TColumnsHelper.hxx" 48*cdf0e10cSrcweir #include "hsqldb/HCatalog.hxx" 49*cdf0e10cSrcweir #include "hsqldb/HColumns.hxx" 50*cdf0e10cSrcweir #include "TConnection.hxx" 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #include <tools/diagnose_ex.h> 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir using namespace ::comphelper; 56*cdf0e10cSrcweir using namespace connectivity::hsqldb; 57*cdf0e10cSrcweir using namespace connectivity::sdbcx; 58*cdf0e10cSrcweir using namespace connectivity; 59*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 60*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 61*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 62*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 63*cdf0e10cSrcweir using namespace ::com::sun::star::container; 64*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir OHSQLTable::OHSQLTable( sdbcx::OCollection* _pTables, 67*cdf0e10cSrcweir const Reference< XConnection >& _xConnection) 68*cdf0e10cSrcweir :OTableHelper(_pTables,_xConnection,sal_True) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir // we create a new table here, so we should have all the rights or ;-) 71*cdf0e10cSrcweir m_nPrivileges = Privilege::DROP | 72*cdf0e10cSrcweir Privilege::REFERENCE | 73*cdf0e10cSrcweir Privilege::ALTER | 74*cdf0e10cSrcweir Privilege::CREATE | 75*cdf0e10cSrcweir Privilege::READ | 76*cdf0e10cSrcweir Privilege::DELETE | 77*cdf0e10cSrcweir Privilege::UPDATE | 78*cdf0e10cSrcweir Privilege::INSERT | 79*cdf0e10cSrcweir Privilege::SELECT; 80*cdf0e10cSrcweir construct(); 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir // ------------------------------------------------------------------------- 83*cdf0e10cSrcweir OHSQLTable::OHSQLTable( sdbcx::OCollection* _pTables, 84*cdf0e10cSrcweir const Reference< XConnection >& _xConnection, 85*cdf0e10cSrcweir const ::rtl::OUString& _Name, 86*cdf0e10cSrcweir const ::rtl::OUString& _Type, 87*cdf0e10cSrcweir const ::rtl::OUString& _Description , 88*cdf0e10cSrcweir const ::rtl::OUString& _SchemaName, 89*cdf0e10cSrcweir const ::rtl::OUString& _CatalogName, 90*cdf0e10cSrcweir sal_Int32 _nPrivileges 91*cdf0e10cSrcweir ) : OTableHelper( _pTables, 92*cdf0e10cSrcweir _xConnection, 93*cdf0e10cSrcweir sal_True, 94*cdf0e10cSrcweir _Name, 95*cdf0e10cSrcweir _Type, 96*cdf0e10cSrcweir _Description, 97*cdf0e10cSrcweir _SchemaName, 98*cdf0e10cSrcweir _CatalogName) 99*cdf0e10cSrcweir , m_nPrivileges(_nPrivileges) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir construct(); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir // ------------------------------------------------------------------------- 104*cdf0e10cSrcweir void OHSQLTable::construct() 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir OTableHelper::construct(); 107*cdf0e10cSrcweir if ( !isNew() ) 108*cdf0e10cSrcweir registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRIVILEGES), PROPERTY_ID_PRIVILEGES,PropertyAttribute::READONLY,&m_nPrivileges, ::getCppuType(&m_nPrivileges)); 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 111*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* OHSQLTable::createArrayHelper( sal_Int32 /*_nId*/ ) const 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir return doCreateArrayHelper(); 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir // ------------------------------------------------------------------------- 116*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper & OHSQLTable::getInfoHelper() 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir return *static_cast<OHSQLTable_PROP*>(const_cast<OHSQLTable*>(this))->getArrayHelper(isNew() ? 1 : 0); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 121*cdf0e10cSrcweir sdbcx::OCollection* OHSQLTable::createColumns(const TStringVector& _rNames) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir OHSQLColumns* pColumns = new OHSQLColumns(*this,sal_True,m_aMutex,_rNames); 124*cdf0e10cSrcweir pColumns->setParent(this); 125*cdf0e10cSrcweir return pColumns; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 128*cdf0e10cSrcweir sdbcx::OCollection* OHSQLTable::createKeys(const TStringVector& _rNames) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir return new OKeysHelper(this,m_aMutex,_rNames); 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 133*cdf0e10cSrcweir sdbcx::OCollection* OHSQLTable::createIndexes(const TStringVector& _rNames) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir return new OIndexesHelper(this,m_aMutex,_rNames); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir //-------------------------------------------------------------------------- 138*cdf0e10cSrcweir Sequence< sal_Int8 > OHSQLTable::getUnoTunnelImplementationId() 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir static ::cppu::OImplementationId * pId = 0; 141*cdf0e10cSrcweir if (! pId) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 144*cdf0e10cSrcweir if (! pId) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir static ::cppu::OImplementationId aId; 147*cdf0e10cSrcweir pId = &aId; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir return pId->getImplementationId(); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir // com::sun::star::lang::XUnoTunnel 154*cdf0e10cSrcweir //------------------------------------------------------------------ 155*cdf0e10cSrcweir sal_Int64 OHSQLTable::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) 158*cdf0e10cSrcweir ? reinterpret_cast< sal_Int64 >( this ) 159*cdf0e10cSrcweir : OTable_TYPEDEF::getSomething(rId); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir // ------------------------------------------------------------------------- 162*cdf0e10cSrcweir // XAlterTable 163*cdf0e10cSrcweir void SAL_CALL OHSQLTable::alterColumnByName( const ::rtl::OUString& colName, const Reference< XPropertySet >& descriptor ) throw(SQLException, NoSuchElementException, RuntimeException) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 166*cdf0e10cSrcweir checkDisposed( 167*cdf0e10cSrcweir #ifdef GCC 168*cdf0e10cSrcweir ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed 169*cdf0e10cSrcweir #else 170*cdf0e10cSrcweir rBHelper.bDisposed 171*cdf0e10cSrcweir #endif 172*cdf0e10cSrcweir ); 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir if ( m_pColumns && !m_pColumns->hasByName(colName) ) 175*cdf0e10cSrcweir throw NoSuchElementException(colName,*this); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir if ( !isNew() ) 179*cdf0e10cSrcweir { 180*cdf0e10cSrcweir // first we have to check what should be altered 181*cdf0e10cSrcweir Reference<XPropertySet> xProp; 182*cdf0e10cSrcweir m_pColumns->getByName(colName) >>= xProp; 183*cdf0e10cSrcweir // first check the types 184*cdf0e10cSrcweir sal_Int32 nOldType = 0,nNewType = 0,nOldPrec = 0,nNewPrec = 0,nOldScale = 0,nNewScale = 0; 185*cdf0e10cSrcweir ::rtl::OUString sOldTypeName, sNewTypeName; 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir ::dbtools::OPropertyMap& rProp = OMetaConnection::getPropMap(); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir // type/typename 190*cdf0e10cSrcweir xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_TYPE)) >>= nOldType; 191*cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_TYPE)) >>= nNewType; 192*cdf0e10cSrcweir xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_TYPENAME)) >>= sOldTypeName; 193*cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_TYPENAME))>>= sNewTypeName; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir // and precsions and scale 196*cdf0e10cSrcweir xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_PRECISION)) >>= nOldPrec; 197*cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_PRECISION))>>= nNewPrec; 198*cdf0e10cSrcweir xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_SCALE)) >>= nOldScale; 199*cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_SCALE)) >>= nNewScale; 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir // second: check the "is nullable" value 202*cdf0e10cSrcweir sal_Int32 nOldNullable = 0,nNewNullable = 0; 203*cdf0e10cSrcweir xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISNULLABLE)) >>= nOldNullable; 204*cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISNULLABLE)) >>= nNewNullable; 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir // check also the auto_increment 207*cdf0e10cSrcweir sal_Bool bOldAutoIncrement = sal_False,bAutoIncrement = sal_False; 208*cdf0e10cSrcweir xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bOldAutoIncrement; 209*cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bAutoIncrement; 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir // now we should look if the name of the column changed 212*cdf0e10cSrcweir ::rtl::OUString sNewColumnName; 213*cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_NAME)) >>= sNewColumnName; 214*cdf0e10cSrcweir if ( !sNewColumnName.equals(colName) ) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir const ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( ); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir ::rtl::OUString sSql = getAlterTableColumnPart(); 219*cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ALTER COLUMN ")); 220*cdf0e10cSrcweir sSql += ::dbtools::quoteName(sQuote,colName); 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" RENAME TO ")); 223*cdf0e10cSrcweir sSql += ::dbtools::quoteName(sQuote,sNewColumnName); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir executeStatement(sSql); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir if ( nOldType != nNewType 229*cdf0e10cSrcweir || sOldTypeName != sNewTypeName 230*cdf0e10cSrcweir || nOldPrec != nNewPrec 231*cdf0e10cSrcweir || nOldScale != nNewScale 232*cdf0e10cSrcweir || nNewNullable != nOldNullable 233*cdf0e10cSrcweir || bOldAutoIncrement != bAutoIncrement ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir // special handling because they change the type names to distinguish 236*cdf0e10cSrcweir // if a column should be an auto_incmrement one 237*cdf0e10cSrcweir if ( bOldAutoIncrement != bAutoIncrement ) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir /// TODO: insert special handling for auto increment "IDENTITY" and primary key 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir alterColumnType(nNewType,sNewColumnName,descriptor); 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir // third: check the default values 245*cdf0e10cSrcweir ::rtl::OUString sNewDefault,sOldDefault; 246*cdf0e10cSrcweir xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_DEFAULTVALUE)) >>= sOldDefault; 247*cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_DEFAULTVALUE)) >>= sNewDefault; 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir if(sOldDefault.getLength()) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir dropDefaultValue(colName); 252*cdf0e10cSrcweir if(sNewDefault.getLength() && sOldDefault != sNewDefault) 253*cdf0e10cSrcweir alterDefaultValue(sNewDefault,sNewColumnName); 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir else if(!sOldDefault.getLength() && sNewDefault.getLength()) 256*cdf0e10cSrcweir alterDefaultValue(sNewDefault,sNewColumnName); 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir m_pColumns->refresh(); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir else 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir if(m_pColumns) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir m_pColumns->dropByName(colName); 265*cdf0e10cSrcweir m_pColumns->appendByDescriptor(descriptor); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 271*cdf0e10cSrcweir void OHSQLTable::alterColumnType(sal_Int32 nNewType,const ::rtl::OUString& _rColName, const Reference<XPropertySet>& _xDescriptor) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir ::rtl::OUString sSql = getAlterTableColumnPart(); 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ALTER COLUMN ")); 276*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 277*cdf0e10cSrcweir try 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir ::rtl::OUString sDescriptorName; 280*cdf0e10cSrcweir OSL_ENSURE( _xDescriptor.is() 281*cdf0e10cSrcweir && ( _xDescriptor->getPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_NAME ) ) >>= sDescriptorName ) 282*cdf0e10cSrcweir && ( sDescriptorName == _rColName ), 283*cdf0e10cSrcweir "OHSQLTable::alterColumnType: unexpected column name!" ); 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir catch( const Exception& ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir #else 290*cdf0e10cSrcweir (void)_rColName; 291*cdf0e10cSrcweir #endif 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir OHSQLColumn* pColumn = new OHSQLColumn(sal_True); 294*cdf0e10cSrcweir Reference<XPropertySet> xProp = pColumn; 295*cdf0e10cSrcweir ::comphelper::copyProperties(_xDescriptor,xProp); 296*cdf0e10cSrcweir xProp->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),makeAny(nNewType)); 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir sSql += ::dbtools::createStandardColumnPart(xProp,getConnection()); 299*cdf0e10cSrcweir executeStatement(sSql); 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 302*cdf0e10cSrcweir void OHSQLTable::alterDefaultValue(const ::rtl::OUString& _sNewDefault,const ::rtl::OUString& _rColName) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir ::rtl::OUString sSql = getAlterTableColumnPart(); 305*cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ALTER COLUMN ")); 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir const ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( ); 308*cdf0e10cSrcweir sSql += ::dbtools::quoteName(sQuote,_rColName); 309*cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" SET DEFAULT '")) + _sNewDefault; 310*cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("'")); 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir executeStatement(sSql); 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 315*cdf0e10cSrcweir void OHSQLTable::dropDefaultValue(const ::rtl::OUString& _rColName) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir ::rtl::OUString sSql = getAlterTableColumnPart(); 318*cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ALTER COLUMN ")); 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir const ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( ); 321*cdf0e10cSrcweir sSql += ::dbtools::quoteName(sQuote,_rColName); 322*cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" DROP DEFAULT")); 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir executeStatement(sSql); 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 327*cdf0e10cSrcweir ::rtl::OUString OHSQLTable::getAlterTableColumnPart() 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir ::rtl::OUString sSql = ::rtl::OUString::createFromAscii("ALTER TABLE "); 330*cdf0e10cSrcweir const ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( ); 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir ::rtl::OUString sComposedName( ::dbtools::composeTableName( getMetaData(), m_CatalogName, m_SchemaName, m_Name, sal_True, ::dbtools::eInTableDefinitions ) ); 333*cdf0e10cSrcweir sSql += sComposedName; 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir return sSql; 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 338*cdf0e10cSrcweir void OHSQLTable::executeStatement(const ::rtl::OUString& _rStatement ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir ::rtl::OUString sSQL = _rStatement; 341*cdf0e10cSrcweir if(sSQL.lastIndexOf(',') == (sSQL.getLength()-1)) 342*cdf0e10cSrcweir sSQL = sSQL.replaceAt(sSQL.getLength()-1,1,::rtl::OUString::createFromAscii(")")); 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir Reference< XStatement > xStmt = getConnection()->createStatement( ); 345*cdf0e10cSrcweir if ( xStmt.is() ) 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir try { xStmt->execute(sSQL); } 348*cdf0e10cSrcweir catch( const Exception& ) 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir ::comphelper::disposeComponent(xStmt); 351*cdf0e10cSrcweir throw; 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir ::comphelper::disposeComponent(xStmt); 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir } 356*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 357*cdf0e10cSrcweir Sequence< Type > SAL_CALL OHSQLTable::getTypes( ) throw(RuntimeException) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir if ( ! m_Type.compareToAscii("VIEW") ) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir Sequence< Type > aTypes = OTableHelper::getTypes(); 362*cdf0e10cSrcweir ::std::vector<Type> aOwnTypes; 363*cdf0e10cSrcweir aOwnTypes.reserve(aTypes.getLength()); 364*cdf0e10cSrcweir const Type* pIter = aTypes.getConstArray(); 365*cdf0e10cSrcweir const Type* pEnd = pIter + aTypes.getLength(); 366*cdf0e10cSrcweir for(;pIter != pEnd;++pIter) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir if( *pIter != ::getCppuType((const Reference<XRename>*)0) ) 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir aOwnTypes.push_back(*pIter); 371*cdf0e10cSrcweir } 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir Type *pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0]; 374*cdf0e10cSrcweir return Sequence< Type >(pTypes, aOwnTypes.size()); 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir return OTableHelper::getTypes(); 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir // ------------------------------------------------------------------------- 379*cdf0e10cSrcweir // XRename 380*cdf0e10cSrcweir void SAL_CALL OHSQLTable::rename( const ::rtl::OUString& newName ) throw(SQLException, ElementExistException, RuntimeException) 381*cdf0e10cSrcweir { 382*cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 383*cdf0e10cSrcweir checkDisposed( 384*cdf0e10cSrcweir #ifdef GCC 385*cdf0e10cSrcweir ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed 386*cdf0e10cSrcweir #else 387*cdf0e10cSrcweir rBHelper.bDisposed 388*cdf0e10cSrcweir #endif 389*cdf0e10cSrcweir ); 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir if(!isNew()) 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir ::rtl::OUString sSql = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ALTER ")); 394*cdf0e10cSrcweir if ( m_Type == ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VIEW")) ) 395*cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" VIEW ")); 396*cdf0e10cSrcweir else 397*cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" TABLE ")); 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( ); 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir ::rtl::OUString sCatalog,sSchema,sTable; 402*cdf0e10cSrcweir ::dbtools::qualifiedNameComponents(getMetaData(),newName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation); 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir ::rtl::OUString sComposedName( 405*cdf0e10cSrcweir ::dbtools::composeTableName( getMetaData(), m_CatalogName, m_SchemaName, m_Name, sal_True, ::dbtools::eInDataManipulation ) ); 406*cdf0e10cSrcweir sSql += sComposedName 407*cdf0e10cSrcweir + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" RENAME TO ")); 408*cdf0e10cSrcweir sSql += ::dbtools::composeTableName( getMetaData(), sCatalog, sSchema, sTable, sal_True, ::dbtools::eInDataManipulation ); 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir executeStatement(sSql); 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir ::connectivity::OTable_TYPEDEF::rename(newName); 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir else 415*cdf0e10cSrcweir ::dbtools::qualifiedNameComponents(getMetaData(),newName,m_CatalogName,m_SchemaName,m_Name,::dbtools::eInTableDefinitions); 416*cdf0e10cSrcweir } 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir // ------------------------------------------------------------------------- 419*cdf0e10cSrcweir Any SAL_CALL OHSQLTable::queryInterface( const Type & rType ) throw(RuntimeException) 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir if( !m_Type.compareToAscii("VIEW") && rType == ::getCppuType((const Reference<XRename>*)0) ) 422*cdf0e10cSrcweir return Any(); 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir return OTableHelper::queryInterface(rType); 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir // ------------------------------------------------------------------------- 427*cdf0e10cSrcweir 428