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