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