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 "mysql/YTable.hxx"
27cdf0e10cSrcweir #include "mysql/YTables.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 "mysql/YCatalog.hxx"
45cdf0e10cSrcweir #include "mysql/YColumns.hxx"
46cdf0e10cSrcweir #include "TConnection.hxx"
47cdf0e10cSrcweir
48cdf0e10cSrcweir
49cdf0e10cSrcweir using namespace ::comphelper;
50cdf0e10cSrcweir using namespace connectivity::mysql;
51cdf0e10cSrcweir using namespace connectivity::sdbcx;
52cdf0e10cSrcweir using namespace connectivity;
53cdf0e10cSrcweir using namespace ::com::sun::star::uno;
54cdf0e10cSrcweir using namespace ::com::sun::star::beans;
55cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
56cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
57cdf0e10cSrcweir using namespace ::com::sun::star::container;
58cdf0e10cSrcweir using namespace ::com::sun::star::lang;
59cdf0e10cSrcweir namespace connectivity
60cdf0e10cSrcweir {
61cdf0e10cSrcweir namespace mysql
62cdf0e10cSrcweir {
63cdf0e10cSrcweir class OMySQLKeysHelper : public OKeysHelper
64cdf0e10cSrcweir {
65cdf0e10cSrcweir protected:
66cdf0e10cSrcweir // -----------------------------------------------------------------------------
getDropForeignKey() const67cdf0e10cSrcweir virtual ::rtl::OUString getDropForeignKey() const
68cdf0e10cSrcweir {
69cdf0e10cSrcweir return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" DROP FOREIGN KEY "));
70cdf0e10cSrcweir }
71cdf0e10cSrcweir public:
OMySQLKeysHelper(OTableHelper * _pTable,::osl::Mutex & _rMutex,const TStringVector & _rVector)72cdf0e10cSrcweir OMySQLKeysHelper( OTableHelper* _pTable,
73cdf0e10cSrcweir ::osl::Mutex& _rMutex,
74cdf0e10cSrcweir const TStringVector& _rVector
75cdf0e10cSrcweir ) : OKeysHelper(_pTable,_rMutex,_rVector){}
76cdf0e10cSrcweir
77cdf0e10cSrcweir };
78cdf0e10cSrcweir }
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
OMySQLTable(sdbcx::OCollection * _pTables,const Reference<XConnection> & _xConnection)81cdf0e10cSrcweir OMySQLTable::OMySQLTable( sdbcx::OCollection* _pTables,
82cdf0e10cSrcweir const Reference< XConnection >& _xConnection)
83cdf0e10cSrcweir :OTableHelper(_pTables,_xConnection,sal_True)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir // we create a new table here, so we should have all the rights or ;-)
86cdf0e10cSrcweir m_nPrivileges = Privilege::DROP |
87cdf0e10cSrcweir Privilege::REFERENCE |
88cdf0e10cSrcweir Privilege::ALTER |
89cdf0e10cSrcweir Privilege::CREATE |
90cdf0e10cSrcweir Privilege::READ |
91cdf0e10cSrcweir Privilege::DELETE |
92cdf0e10cSrcweir Privilege::UPDATE |
93cdf0e10cSrcweir Privilege::INSERT |
94cdf0e10cSrcweir Privilege::SELECT;
95cdf0e10cSrcweir construct();
96cdf0e10cSrcweir }
97cdf0e10cSrcweir // -------------------------------------------------------------------------
OMySQLTable(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)98cdf0e10cSrcweir OMySQLTable::OMySQLTable( sdbcx::OCollection* _pTables,
99cdf0e10cSrcweir const Reference< XConnection >& _xConnection,
100cdf0e10cSrcweir const ::rtl::OUString& _Name,
101cdf0e10cSrcweir const ::rtl::OUString& _Type,
102cdf0e10cSrcweir const ::rtl::OUString& _Description ,
103cdf0e10cSrcweir const ::rtl::OUString& _SchemaName,
104cdf0e10cSrcweir const ::rtl::OUString& _CatalogName,
105cdf0e10cSrcweir sal_Int32 _nPrivileges
106cdf0e10cSrcweir ) : OTableHelper( _pTables,
107cdf0e10cSrcweir _xConnection,
108cdf0e10cSrcweir sal_True,
109cdf0e10cSrcweir _Name,
110cdf0e10cSrcweir _Type,
111cdf0e10cSrcweir _Description,
112cdf0e10cSrcweir _SchemaName,
113cdf0e10cSrcweir _CatalogName)
114cdf0e10cSrcweir , m_nPrivileges(_nPrivileges)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir construct();
117cdf0e10cSrcweir }
118cdf0e10cSrcweir // -------------------------------------------------------------------------
construct()119cdf0e10cSrcweir void OMySQLTable::construct()
120cdf0e10cSrcweir {
121cdf0e10cSrcweir OTableHelper::construct();
122cdf0e10cSrcweir if ( !isNew() )
123cdf0e10cSrcweir registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRIVILEGES), PROPERTY_ID_PRIVILEGES,PropertyAttribute::READONLY,&m_nPrivileges, ::getCppuType(&m_nPrivileges));
124cdf0e10cSrcweir }
125cdf0e10cSrcweir // -----------------------------------------------------------------------------
createArrayHelper(sal_Int32) const126cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* OMySQLTable::createArrayHelper( sal_Int32 /*_nId*/ ) const
127cdf0e10cSrcweir {
128cdf0e10cSrcweir return doCreateArrayHelper();
129cdf0e10cSrcweir }
130cdf0e10cSrcweir // -------------------------------------------------------------------------
getInfoHelper()131cdf0e10cSrcweir ::cppu::IPropertyArrayHelper & OMySQLTable::getInfoHelper()
132cdf0e10cSrcweir {
133cdf0e10cSrcweir return *static_cast<OMySQLTable_PROP*>(const_cast<OMySQLTable*>(this))->getArrayHelper(isNew() ? 1 : 0);
134cdf0e10cSrcweir }
135cdf0e10cSrcweir // -----------------------------------------------------------------------------
createColumns(const TStringVector & _rNames)136cdf0e10cSrcweir sdbcx::OCollection* OMySQLTable::createColumns(const TStringVector& _rNames)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir OMySQLColumns* pColumns = new OMySQLColumns(*this,sal_True,m_aMutex,_rNames);
139cdf0e10cSrcweir pColumns->setParent(this);
140cdf0e10cSrcweir return pColumns;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir // -----------------------------------------------------------------------------
createKeys(const TStringVector & _rNames)143cdf0e10cSrcweir sdbcx::OCollection* OMySQLTable::createKeys(const TStringVector& _rNames)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir return new OMySQLKeysHelper(this,m_aMutex,_rNames);
146cdf0e10cSrcweir }
147cdf0e10cSrcweir // -----------------------------------------------------------------------------
createIndexes(const TStringVector & _rNames)148cdf0e10cSrcweir sdbcx::OCollection* OMySQLTable::createIndexes(const TStringVector& _rNames)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir return new OIndexesHelper(this,m_aMutex,_rNames);
151cdf0e10cSrcweir }
152cdf0e10cSrcweir //--------------------------------------------------------------------------
getUnoTunnelImplementationId()153cdf0e10cSrcweir Sequence< sal_Int8 > OMySQLTable::getUnoTunnelImplementationId()
154cdf0e10cSrcweir {
155cdf0e10cSrcweir static ::cppu::OImplementationId * pId = 0;
156cdf0e10cSrcweir if (! pId)
157cdf0e10cSrcweir {
158cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
159cdf0e10cSrcweir if (! pId)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir static ::cppu::OImplementationId aId;
162cdf0e10cSrcweir pId = &aId;
163cdf0e10cSrcweir }
164cdf0e10cSrcweir }
165cdf0e10cSrcweir return pId->getImplementationId();
166cdf0e10cSrcweir }
167cdf0e10cSrcweir
168cdf0e10cSrcweir // com::sun::star::lang::XUnoTunnel
169cdf0e10cSrcweir //------------------------------------------------------------------
getSomething(const Sequence<sal_Int8> & rId)170cdf0e10cSrcweir sal_Int64 OMySQLTable::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
171cdf0e10cSrcweir {
172cdf0e10cSrcweir return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
173cdf0e10cSrcweir ? reinterpret_cast< sal_Int64 >( this )
174cdf0e10cSrcweir : OTable_TYPEDEF::getSomething(rId);
175cdf0e10cSrcweir }
176cdf0e10cSrcweir // -------------------------------------------------------------------------
177cdf0e10cSrcweir // XAlterTable
alterColumnByName(const::rtl::OUString & colName,const Reference<XPropertySet> & descriptor)178cdf0e10cSrcweir void SAL_CALL OMySQLTable::alterColumnByName( const ::rtl::OUString& colName, const Reference< XPropertySet >& descriptor ) throw(SQLException, NoSuchElementException, RuntimeException)
179cdf0e10cSrcweir {
180cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
181cdf0e10cSrcweir checkDisposed(
182cdf0e10cSrcweir #ifdef GCC
183cdf0e10cSrcweir ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed
184cdf0e10cSrcweir #else
185cdf0e10cSrcweir rBHelper.bDisposed
186cdf0e10cSrcweir #endif
187cdf0e10cSrcweir );
188cdf0e10cSrcweir
189cdf0e10cSrcweir if ( m_pColumns && !m_pColumns->hasByName(colName) )
190cdf0e10cSrcweir throw NoSuchElementException(colName,*this);
191cdf0e10cSrcweir
192cdf0e10cSrcweir
193cdf0e10cSrcweir if ( !isNew() )
194cdf0e10cSrcweir {
195cdf0e10cSrcweir // first we have to check what should be altered
196cdf0e10cSrcweir Reference<XPropertySet> xProp;
197cdf0e10cSrcweir m_pColumns->getByName(colName) >>= xProp;
198cdf0e10cSrcweir // first check the types
199cdf0e10cSrcweir sal_Int32 nOldType = 0,nNewType = 0,nOldPrec = 0,nNewPrec = 0,nOldScale = 0,nNewScale = 0;
200cdf0e10cSrcweir
201cdf0e10cSrcweir ::dbtools::OPropertyMap& rProp = OMetaConnection::getPropMap();
202cdf0e10cSrcweir xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_TYPE)) >>= nOldType;
203cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_TYPE)) >>= nNewType;
204cdf0e10cSrcweir // and precsions and scale
205cdf0e10cSrcweir xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_PRECISION)) >>= nOldPrec;
206cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_PRECISION))>>= nNewPrec;
207cdf0e10cSrcweir xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_SCALE)) >>= nOldScale;
208cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_SCALE)) >>= nNewScale;
209cdf0e10cSrcweir // second: check the "is nullable" value
210cdf0e10cSrcweir sal_Int32 nOldNullable = 0,nNewNullable = 0;
211cdf0e10cSrcweir xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISNULLABLE)) >>= nOldNullable;
212cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISNULLABLE)) >>= nNewNullable;
213cdf0e10cSrcweir
214cdf0e10cSrcweir // check also the auto_increment
215cdf0e10cSrcweir sal_Bool bOldAutoIncrement = sal_False,bAutoIncrement = sal_False;
216cdf0e10cSrcweir xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bOldAutoIncrement;
217cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bAutoIncrement;
218cdf0e10cSrcweir bool bColumnNameChanged = false;
219cdf0e10cSrcweir ::rtl::OUString sOldDesc,sNewDesc;
220cdf0e10cSrcweir xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_DESCRIPTION)) >>= sOldDesc;
221cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_DESCRIPTION)) >>= sNewDesc;
222cdf0e10cSrcweir
223cdf0e10cSrcweir if ( nOldType != nNewType
224cdf0e10cSrcweir || nOldPrec != nNewPrec
225cdf0e10cSrcweir || nOldScale != nNewScale
226cdf0e10cSrcweir || nNewNullable != nOldNullable
227cdf0e10cSrcweir || bOldAutoIncrement != bAutoIncrement
228cdf0e10cSrcweir || sOldDesc != sNewDesc )
229cdf0e10cSrcweir {
230cdf0e10cSrcweir // special handling because they change dthe type names to distinguish
231cdf0e10cSrcweir // if a column should be an auto_incmrement one
232cdf0e10cSrcweir if ( bOldAutoIncrement != bAutoIncrement )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir ::rtl::OUString sTypeName;
235cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_TYPENAME)) >>= sTypeName;
236cdf0e10cSrcweir
237cdf0e10cSrcweir static ::rtl::OUString s_sAutoIncrement(RTL_CONSTASCII_USTRINGPARAM("auto_increment"));
238cdf0e10cSrcweir if ( bAutoIncrement )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir if ( sTypeName.indexOf(s_sAutoIncrement) == -1 )
241cdf0e10cSrcweir {
242cdf0e10cSrcweir sTypeName += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" "));
243cdf0e10cSrcweir sTypeName += s_sAutoIncrement;
244cdf0e10cSrcweir }
245cdf0e10cSrcweir }
246cdf0e10cSrcweir else
247cdf0e10cSrcweir {
248cdf0e10cSrcweir sal_Int32 nIndex = 0;
249cdf0e10cSrcweir if ( sTypeName.getLength() && (nIndex = sTypeName.indexOf(s_sAutoIncrement)) != -1 )
250cdf0e10cSrcweir {
251cdf0e10cSrcweir sTypeName = sTypeName.copy(0,nIndex);
252cdf0e10cSrcweir descriptor->setPropertyValue(rProp.getNameByIndex(PROPERTY_ID_TYPENAME),makeAny(sTypeName));
253cdf0e10cSrcweir }
254cdf0e10cSrcweir }
255cdf0e10cSrcweir }
256cdf0e10cSrcweir alterColumnType(nNewType,colName,descriptor);
257cdf0e10cSrcweir bColumnNameChanged = true;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir // third: check the default values
261cdf0e10cSrcweir ::rtl::OUString sNewDefault,sOldDefault;
262cdf0e10cSrcweir xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_DEFAULTVALUE)) >>= sOldDefault;
263cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_DEFAULTVALUE)) >>= sNewDefault;
264cdf0e10cSrcweir
265cdf0e10cSrcweir if(sOldDefault.getLength())
266cdf0e10cSrcweir {
267cdf0e10cSrcweir dropDefaultValue(colName);
268cdf0e10cSrcweir if(sNewDefault.getLength() && sOldDefault != sNewDefault)
269cdf0e10cSrcweir alterDefaultValue(sNewDefault,colName);
270cdf0e10cSrcweir }
271cdf0e10cSrcweir else if(!sOldDefault.getLength() && sNewDefault.getLength())
272cdf0e10cSrcweir alterDefaultValue(sNewDefault,colName);
273cdf0e10cSrcweir
274cdf0e10cSrcweir // now we should look if the name of the column changed
275cdf0e10cSrcweir ::rtl::OUString sNewColumnName;
276cdf0e10cSrcweir descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_NAME)) >>= sNewColumnName;
277cdf0e10cSrcweir if ( !sNewColumnName.equalsIgnoreAsciiCase(colName) && !bColumnNameChanged )
278cdf0e10cSrcweir {
279cdf0e10cSrcweir ::rtl::OUString sSql = getAlterTableColumnPart();
280cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" CHANGE "));
281cdf0e10cSrcweir const ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( );
282cdf0e10cSrcweir sSql += ::dbtools::quoteName(sQuote,colName);
283cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" "));
284cdf0e10cSrcweir sSql += OTables::adjustSQL(::dbtools::createStandardColumnPart(descriptor,getConnection(),static_cast<OTables*>(m_pTables),getTypeCreatePattern()));
285cdf0e10cSrcweir executeStatement(sSql);
286cdf0e10cSrcweir }
287cdf0e10cSrcweir m_pColumns->refresh();
288cdf0e10cSrcweir }
289cdf0e10cSrcweir else
290cdf0e10cSrcweir {
291cdf0e10cSrcweir if(m_pColumns)
292cdf0e10cSrcweir {
293cdf0e10cSrcweir m_pColumns->dropByName(colName);
294cdf0e10cSrcweir m_pColumns->appendByDescriptor(descriptor);
295cdf0e10cSrcweir }
296cdf0e10cSrcweir }
297cdf0e10cSrcweir
298cdf0e10cSrcweir }
299cdf0e10cSrcweir // -----------------------------------------------------------------------------
alterColumnType(sal_Int32 nNewType,const::rtl::OUString & _rColName,const Reference<XPropertySet> & _xDescriptor)300cdf0e10cSrcweir void OMySQLTable::alterColumnType(sal_Int32 nNewType,const ::rtl::OUString& _rColName, const Reference<XPropertySet>& _xDescriptor)
301cdf0e10cSrcweir {
302cdf0e10cSrcweir ::rtl::OUString sSql = getAlterTableColumnPart();
303cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" CHANGE "));
304cdf0e10cSrcweir const ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( );
305cdf0e10cSrcweir sSql += ::dbtools::quoteName(sQuote,_rColName);
306cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" "));
307cdf0e10cSrcweir
308cdf0e10cSrcweir OColumn* pColumn = new OColumn(sal_True);
309cdf0e10cSrcweir Reference<XPropertySet> xProp = pColumn;
310cdf0e10cSrcweir ::comphelper::copyProperties(_xDescriptor,xProp);
311cdf0e10cSrcweir xProp->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),makeAny(nNewType));
312cdf0e10cSrcweir
313cdf0e10cSrcweir sSql += OTables::adjustSQL(::dbtools::createStandardColumnPart(xProp,getConnection(),static_cast<OTables*>(m_pTables),getTypeCreatePattern()));
314cdf0e10cSrcweir executeStatement(sSql);
315cdf0e10cSrcweir }
316cdf0e10cSrcweir // -----------------------------------------------------------------------------
getTypeCreatePattern() const317cdf0e10cSrcweir ::rtl::OUString OMySQLTable::getTypeCreatePattern() const
318cdf0e10cSrcweir {
319cdf0e10cSrcweir static const ::rtl::OUString s_sCreatePattern(RTL_CONSTASCII_USTRINGPARAM("(M,D)"));
320cdf0e10cSrcweir return s_sCreatePattern;
321cdf0e10cSrcweir }
322cdf0e10cSrcweir // -----------------------------------------------------------------------------
alterDefaultValue(const::rtl::OUString & _sNewDefault,const::rtl::OUString & _rColName)323cdf0e10cSrcweir void OMySQLTable::alterDefaultValue(const ::rtl::OUString& _sNewDefault,const ::rtl::OUString& _rColName)
324cdf0e10cSrcweir {
325cdf0e10cSrcweir ::rtl::OUString sSql = getAlterTableColumnPart();
326cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ALTER "));
327cdf0e10cSrcweir
328cdf0e10cSrcweir const ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( );
329cdf0e10cSrcweir sSql += ::dbtools::quoteName(sQuote,_rColName);
330cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" SET DEFAULT '")) + _sNewDefault;
331cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("'"));
332cdf0e10cSrcweir
333cdf0e10cSrcweir executeStatement(sSql);
334cdf0e10cSrcweir }
335cdf0e10cSrcweir // -----------------------------------------------------------------------------
dropDefaultValue(const::rtl::OUString & _rColName)336cdf0e10cSrcweir void OMySQLTable::dropDefaultValue(const ::rtl::OUString& _rColName)
337cdf0e10cSrcweir {
338cdf0e10cSrcweir ::rtl::OUString sSql = getAlterTableColumnPart();
339cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ALTER "));
340cdf0e10cSrcweir
341cdf0e10cSrcweir const ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( );
342cdf0e10cSrcweir sSql += ::dbtools::quoteName(sQuote,_rColName);
343cdf0e10cSrcweir sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" DROP DEFAULT"));
344cdf0e10cSrcweir
345cdf0e10cSrcweir executeStatement(sSql);
346cdf0e10cSrcweir }
347cdf0e10cSrcweir // -----------------------------------------------------------------------------
getAlterTableColumnPart()348cdf0e10cSrcweir ::rtl::OUString OMySQLTable::getAlterTableColumnPart()
349cdf0e10cSrcweir {
350cdf0e10cSrcweir ::rtl::OUString sSql = ::rtl::OUString::createFromAscii("ALTER TABLE ");
351cdf0e10cSrcweir const ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( );
352cdf0e10cSrcweir
353cdf0e10cSrcweir ::rtl::OUString sComposedName(
354cdf0e10cSrcweir ::dbtools::composeTableName( getMetaData(), m_CatalogName, m_SchemaName, m_Name, sal_True, ::dbtools::eInTableDefinitions ) );
355cdf0e10cSrcweir sSql += sComposedName;
356cdf0e10cSrcweir
357cdf0e10cSrcweir return sSql;
358cdf0e10cSrcweir }
359cdf0e10cSrcweir // -----------------------------------------------------------------------------
executeStatement(const::rtl::OUString & _rStatement)360cdf0e10cSrcweir void OMySQLTable::executeStatement(const ::rtl::OUString& _rStatement )
361cdf0e10cSrcweir {
362cdf0e10cSrcweir ::rtl::OUString sSQL = _rStatement;
363cdf0e10cSrcweir if(sSQL.lastIndexOf(',') == (sSQL.getLength()-1))
364cdf0e10cSrcweir sSQL = sSQL.replaceAt(sSQL.getLength()-1,1,::rtl::OUString::createFromAscii(")"));
365cdf0e10cSrcweir
366cdf0e10cSrcweir Reference< XStatement > xStmt = getConnection()->createStatement( );
367cdf0e10cSrcweir if ( xStmt.is() )
368cdf0e10cSrcweir {
369cdf0e10cSrcweir xStmt->execute(sSQL);
370cdf0e10cSrcweir ::comphelper::disposeComponent(xStmt);
371cdf0e10cSrcweir }
372cdf0e10cSrcweir }
373cdf0e10cSrcweir // -----------------------------------------------------------------------------
getRenameStart() const374cdf0e10cSrcweir ::rtl::OUString OMySQLTable::getRenameStart() const
375cdf0e10cSrcweir {
376cdf0e10cSrcweir return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RENAME TABLE "));
377cdf0e10cSrcweir }
378cdf0e10cSrcweir
379cdf0e10cSrcweir
380cdf0e10cSrcweir
381cdf0e10cSrcweir
382