summaryrefslogtreecommitdiff
path: root/connectivity/source/drivers/mysql
diff options
context:
space:
mode:
Diffstat (limited to 'connectivity/source/drivers/mysql')
-rw-r--r--connectivity/source/drivers/mysql/YCatalog.cxx174
-rw-r--r--connectivity/source/drivers/mysql/YColumns.cxx89
-rw-r--r--connectivity/source/drivers/mysql/YDriver.cxx481
-rw-r--r--connectivity/source/drivers/mysql/YTable.cxx385
-rw-r--r--connectivity/source/drivers/mysql/YTables.cxx243
-rw-r--r--connectivity/source/drivers/mysql/YUser.cxx350
-rw-r--r--connectivity/source/drivers/mysql/YUsers.cxx118
-rw-r--r--connectivity/source/drivers/mysql/YViews.cxx162
-rw-r--r--connectivity/source/drivers/mysql/Yservices.cxx124
-rw-r--r--connectivity/source/drivers/mysql/exports.dxp2
-rw-r--r--connectivity/source/drivers/mysql/makefile.mk92
-rw-r--r--connectivity/source/drivers/mysql/mysql.component35
-rwxr-xr-xconnectivity/source/drivers/mysql/mysql.xcu258
-rw-r--r--connectivity/source/drivers/mysql/mysql.xml29
14 files changed, 2542 insertions, 0 deletions
diff --git a/connectivity/source/drivers/mysql/YCatalog.cxx b/connectivity/source/drivers/mysql/YCatalog.cxx
new file mode 100644
index 000000000000..eab600fc33dc
--- /dev/null
+++ b/connectivity/source/drivers/mysql/YCatalog.cxx
@@ -0,0 +1,174 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_connectivity.hxx"
+#include "mysql/YCatalog.hxx"
+#include "mysql/YUsers.hxx"
+#include "mysql/YTables.hxx"
+#include "mysql/YViews.hxx"
+#include <com/sun/star/sdbc/XRow.hpp>
+#include <com/sun/star/sdbc/XResultSet.hpp>
+#include <comphelper/types.hxx>
+
+
+// -------------------------------------------------------------------------
+using namespace connectivity;
+using namespace connectivity::mysql;
+using namespace connectivity::sdbcx;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::sdbcx;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::lang;
+// -------------------------------------------------------------------------
+OMySQLCatalog::OMySQLCatalog(const Reference< XConnection >& _xConnection) : OCatalog(_xConnection)
+ ,m_xConnection(_xConnection)
+{
+}
+// -----------------------------------------------------------------------------
+void OMySQLCatalog::refreshObjects(const Sequence< ::rtl::OUString >& _sKindOfObject,TStringVector& _rNames)
+{
+ Reference< XResultSet > xResult = m_xMetaData->getTables(Any(),
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")),
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")),
+ _sKindOfObject);
+ fillNames(xResult,_rNames);
+}
+// -------------------------------------------------------------------------
+void OMySQLCatalog::refreshTables()
+{
+ TStringVector aVector;
+ static const ::rtl::OUString s_sTableTypeView(RTL_CONSTASCII_USTRINGPARAM("VIEW"));
+ static const ::rtl::OUString s_sTableTypeTable(RTL_CONSTASCII_USTRINGPARAM("TABLE"));
+ static const ::rtl::OUString s_sAll(RTL_CONSTASCII_USTRINGPARAM("%"));
+
+ Sequence< ::rtl::OUString > sTableTypes(3);
+ sTableTypes[0] = s_sTableTypeView;
+ sTableTypes[1] = s_sTableTypeTable;
+ sTableTypes[2] = s_sAll; // just to be sure to include anything else ....
+
+ refreshObjects(sTableTypes,aVector);
+
+ if ( m_pTables )
+ m_pTables->reFill(aVector);
+ else
+ m_pTables = new OTables(m_xMetaData,*this,m_aMutex,aVector);
+}
+// -------------------------------------------------------------------------
+void OMySQLCatalog::refreshViews()
+{
+ Sequence< ::rtl::OUString > aTypes(1);
+ aTypes[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VIEW"));
+
+/*
+ sal_Bool bSupportsViews = sal_False;
+ try
+ {
+ Reference<XResultSet> xRes = m_xMetaData->getTableTypes();
+ Reference<XRow> xRow(xRes,UNO_QUERY);
+ while ( !bSupportsViews && xRow.is() && xRes->next() )
+ {
+ ::rtl::OUString sTableType( xRow->getString( 1 ) );
+ bSupportsViews = sTableType.equalsIgnoreAsciiCase( aTypes[0] );
+ }
+ }
+ catch(const SQLException&)
+ {
+ }
+*/
+ // let's simply assume the server is new enough to support views. Current drivers
+ // as of this writing might not return the proper information in getTableTypes, so
+ // don't rely on it.
+ // during #73245# / 2007-10-26 / frank.schoenheit@sun.com
+ bool bSupportsViews = sal_True;
+
+ TStringVector aVector;
+ if ( bSupportsViews )
+ refreshObjects(aTypes,aVector);
+
+ if ( m_pViews )
+ m_pViews->reFill(aVector);
+ else
+ m_pViews = new OViews(m_xMetaData,*this,m_aMutex,aVector);
+}
+// -------------------------------------------------------------------------
+void OMySQLCatalog::refreshGroups()
+{
+}
+// -------------------------------------------------------------------------
+void OMySQLCatalog::refreshUsers()
+{
+ TStringVector aVector;
+ Reference< XStatement > xStmt = m_xConnection->createStatement( );
+ Reference< XResultSet > xResult = xStmt->executeQuery(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("select User from mysql.user group by User")));
+ if ( xResult.is() )
+ {
+ Reference< XRow > xRow(xResult,UNO_QUERY);
+ TString2IntMap aMap;
+ while( xResult->next() )
+ aVector.push_back(xRow->getString(1));
+ ::comphelper::disposeComponent(xResult);
+ }
+ ::comphelper::disposeComponent(xStmt);
+
+ if(m_pUsers)
+ m_pUsers->reFill(aVector);
+ else
+ m_pUsers = new OUsers(*this,m_aMutex,aVector,m_xConnection,this);
+}
+// -----------------------------------------------------------------------------
+Any SAL_CALL OMySQLCatalog::queryInterface( const Type & rType ) throw(RuntimeException)
+{
+ if ( rType == ::getCppuType((const Reference<XGroupsSupplier>*)0) )
+ return Any();
+
+
+ return OCatalog::queryInterface(rType);
+}
+// -----------------------------------------------------------------------------
+Sequence< Type > SAL_CALL OMySQLCatalog::getTypes( ) throw(RuntimeException)
+{
+ Sequence< Type > aTypes = OCatalog::getTypes();
+ ::std::vector<Type> aOwnTypes;
+ aOwnTypes.reserve(aTypes.getLength());
+ const Type* pBegin = aTypes.getConstArray();
+ const Type* pEnd = pBegin + aTypes.getLength();
+ for(;pBegin != pEnd;++pBegin)
+ {
+ if ( !(*pBegin == ::getCppuType((const Reference<XGroupsSupplier>*)0)))
+ {
+ aOwnTypes.push_back(*pBegin);
+ }
+ }
+ const Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
+ return Sequence< Type >(pTypes, aOwnTypes.size());
+}
+// -----------------------------------------------------------------------------
+
+
diff --git a/connectivity/source/drivers/mysql/YColumns.cxx b/connectivity/source/drivers/mysql/YColumns.cxx
new file mode 100644
index 000000000000..abfcfacc7cf2
--- /dev/null
+++ b/connectivity/source/drivers/mysql/YColumns.cxx
@@ -0,0 +1,89 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_connectivity.hxx"
+#include "mysql/YColumns.hxx"
+#include "TConnection.hxx"
+
+
+using namespace ::comphelper;
+using namespace connectivity::mysql;
+using namespace connectivity::sdbcx;
+using namespace connectivity;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::sdbcx;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::lang;
+
+OMySQLColumns::OMySQLColumns( ::cppu::OWeakObject& _rParent
+ ,sal_Bool _bCase
+ ,::osl::Mutex& _rMutex
+ ,const TStringVector &_rVector
+ ,sal_Bool _bUseHardRef
+ ) : OColumnsHelper(_rParent,_bCase,_rMutex,_rVector,_bUseHardRef)
+{
+}
+// -----------------------------------------------------------------------------
+Reference< XPropertySet > OMySQLColumns::createDescriptor()
+{
+ return new OMySQLColumn(sal_True);
+}
+// -----------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
+OMySQLColumn::OMySQLColumn( sal_Bool _bCase)
+ : connectivity::sdbcx::OColumn( _bCase )
+{
+ construct();
+}
+// -------------------------------------------------------------------------
+void OMySQLColumn::construct()
+{
+ m_sAutoIncrement = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("auto_increment"));
+ registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_AUTOINCREMENTCREATION),PROPERTY_ID_AUTOINCREMENTCREATION,0,&m_sAutoIncrement, ::getCppuType(&m_sAutoIncrement));
+}
+// -----------------------------------------------------------------------------
+::cppu::IPropertyArrayHelper* OMySQLColumn::createArrayHelper( sal_Int32 /*_nId*/ ) const
+{
+ return doCreateArrayHelper();
+}
+// -----------------------------------------------------------------------------
+::cppu::IPropertyArrayHelper & SAL_CALL OMySQLColumn::getInfoHelper()
+{
+ return *OMySQLColumn_PROP::getArrayHelper(isNew() ? 1 : 0);
+}
+// -----------------------------------------------------------------------------
+Sequence< ::rtl::OUString > SAL_CALL OMySQLColumn::getSupportedServiceNames( ) throw(RuntimeException)
+{
+ Sequence< ::rtl::OUString > aSupported(1);
+ aSupported[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Column");
+
+ return aSupported;
+}
+// -----------------------------------------------------------------------------
diff --git a/connectivity/source/drivers/mysql/YDriver.cxx b/connectivity/source/drivers/mysql/YDriver.cxx
new file mode 100644
index 000000000000..024066207622
--- /dev/null
+++ b/connectivity/source/drivers/mysql/YDriver.cxx
@@ -0,0 +1,481 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_connectivity.hxx"
+#include "mysql/YDriver.hxx"
+#include "mysql/YCatalog.hxx"
+#include <osl/diagnose.h>
+#include <comphelper/namedvaluecollection.hxx>
+#include "connectivity/dbexception.hxx"
+#include <connectivity/dbcharset.hxx>
+#include <com/sun/star/sdbc/XDriverAccess.hpp>
+#include "TConnection.hxx"
+#include "resource/common_res.hrc"
+#include "resource/sharedresources.hxx"
+
+//........................................................................
+namespace connectivity
+{
+//........................................................................
+ using namespace mysql;
+ using namespace ::com::sun::star::uno;
+ using namespace ::com::sun::star::sdbc;
+ using namespace ::com::sun::star::sdbcx;
+ using namespace ::com::sun::star::beans;
+ using namespace ::com::sun::star::lang;
+
+ namespace mysql
+ {
+ Reference< XInterface > SAL_CALL ODriverDelegator_CreateInstance(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFac) throw( Exception )
+ {
+ return *(new ODriverDelegator(_rxFac));
+ }
+ }
+
+
+ //====================================================================
+ //= ODriverDelegator
+ //====================================================================
+ //--------------------------------------------------------------------
+ ODriverDelegator::ODriverDelegator(const Reference< XMultiServiceFactory >& _rxFactory)
+ : ODriverDelegator_BASE(m_aMutex)
+ ,m_xFactory(_rxFactory)
+ ,m_eDriverType(D_ODBC)
+ {
+ }
+
+ //--------------------------------------------------------------------
+ ODriverDelegator::~ODriverDelegator()
+ {
+ try
+ {
+ ::comphelper::disposeComponent(m_xODBCDriver);
+ ::comphelper::disposeComponent(m_xNativeDriver);
+ TJDBCDrivers::iterator aIter = m_aJdbcDrivers.begin();
+ TJDBCDrivers::iterator aEnd = m_aJdbcDrivers.end();
+ for ( ;aIter != aEnd;++aIter )
+ ::comphelper::disposeComponent(aIter->second);
+ }
+ catch(const Exception&)
+ {
+ }
+ }
+
+ // --------------------------------------------------------------------------------
+ void ODriverDelegator::disposing()
+ {
+ ::osl::MutexGuard aGuard(m_aMutex);
+
+
+ for (TWeakPairVector::iterator i = m_aConnections.begin(); m_aConnections.end() != i; ++i)
+ {
+ Reference<XInterface > xTemp = i->first.get();
+ ::comphelper::disposeComponent(xTemp);
+ }
+ m_aConnections.clear();
+ TWeakPairVector().swap(m_aConnections);
+
+ ODriverDelegator_BASE::disposing();
+ }
+
+ namespace
+ {
+ sal_Bool isOdbcUrl(const ::rtl::OUString& _sUrl)
+ {
+ return _sUrl.copy(0,16).equalsAscii("sdbc:mysql:odbc:");
+ }
+ //--------------------------------------------------------------------
+ sal_Bool isNativeUrl(const ::rtl::OUString& _sUrl)
+ {
+ return (!_sUrl.compareTo(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:mysql:mysqlc:")), sizeof("sdbc:mysql:mysqlc:")-1));
+ }
+ //--------------------------------------------------------------------
+ T_DRIVERTYPE lcl_getDriverType(const ::rtl::OUString& _sUrl)
+ {
+ T_DRIVERTYPE eRet = D_JDBC;
+ if ( isOdbcUrl(_sUrl ) )
+ eRet = D_ODBC;
+ else if ( isNativeUrl(_sUrl ) )
+ eRet = D_NATIVE;
+ return eRet;
+ }
+ //--------------------------------------------------------------------
+ ::rtl::OUString transformUrl(const ::rtl::OUString& _sUrl)
+ {
+ ::rtl::OUString sNewUrl = _sUrl.copy(11);
+ if ( isOdbcUrl( _sUrl ) )
+ sNewUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:")) + sNewUrl;
+ else if ( isNativeUrl( _sUrl ) )
+ sNewUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("sdbc:")) + sNewUrl;
+ else
+ {
+ sNewUrl = sNewUrl.copy(5);
+
+ ::rtl::OUString sTempUrl = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("jdbc:mysql://"));
+
+ sTempUrl += sNewUrl;
+ sNewUrl = sTempUrl;
+ }
+ return sNewUrl;
+ }
+ //--------------------------------------------------------------------
+ Reference< XDriver > lcl_loadDriver(const Reference< XMultiServiceFactory >& _rxFactory,const ::rtl::OUString& _sUrl)
+ {
+ Reference<XDriverAccess> xDriverAccess(_rxFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdbc.DriverManager")) ),UNO_QUERY);
+ OSL_ENSURE(xDriverAccess.is(),"Could not load driver manager!");
+ Reference< XDriver > xDriver;
+ if ( xDriverAccess.is() )
+ xDriver = xDriverAccess->getDriverByURL(_sUrl);
+ return xDriver;
+ }
+ //--------------------------------------------------------------------
+ Sequence< PropertyValue > lcl_convertProperties(T_DRIVERTYPE _eType,const Sequence< PropertyValue >& info,const ::rtl::OUString& _sUrl)
+ {
+ ::std::vector<PropertyValue> aProps;
+ const PropertyValue* pSupported = info.getConstArray();
+ const PropertyValue* pEnd = pSupported + info.getLength();
+
+ aProps.reserve(info.getLength() + 5);
+ for (;pSupported != pEnd; ++pSupported)
+ {
+ aProps.push_back( *pSupported );
+ }
+
+ if ( _eType == D_ODBC )
+ {
+ aProps.push_back( PropertyValue(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Silent"))
+ ,0
+ ,makeAny(sal_True)
+ ,PropertyState_DIRECT_VALUE) );
+ aProps.push_back( PropertyValue(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PreventGetVersionColumns"))
+ ,0
+ ,makeAny(sal_True)
+ ,PropertyState_DIRECT_VALUE) );
+ }
+ else if ( _eType == D_JDBC )
+ {
+ aProps.push_back( PropertyValue(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClass"))
+ ,0
+ ,makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.mysql.jdbc.Driver")))
+ ,PropertyState_DIRECT_VALUE) );
+ }
+ else
+ {
+ aProps.push_back( PropertyValue(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PublicConnectionURL"))
+ ,0
+ ,makeAny(_sUrl)
+ ,PropertyState_DIRECT_VALUE) );
+ }
+ aProps.push_back( PropertyValue(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled"))
+ ,0
+ ,makeAny(sal_True)
+ ,PropertyState_DIRECT_VALUE) );
+ aProps.push_back( PropertyValue(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoRetrievingStatement"))
+ ,0
+ ,makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT LAST_INSERT_ID()")))
+ ,PropertyState_DIRECT_VALUE) );
+ aProps.push_back( PropertyValue(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParameterNameSubstitution"))
+ ,0
+ ,makeAny(sal_True)
+ ,PropertyState_DIRECT_VALUE) );
+ PropertyValue* pProps = aProps.empty() ? 0 : &aProps[0];
+ return Sequence< PropertyValue >(pProps, aProps.size());
+ }
+ }
+ //--------------------------------------------------------------------
+ Reference< XDriver > ODriverDelegator::loadDriver( const ::rtl::OUString& url, const Sequence< PropertyValue >& info )
+ {
+ Reference< XDriver > xDriver;
+ const ::rtl::OUString sCuttedUrl = transformUrl(url);
+ const T_DRIVERTYPE eType = lcl_getDriverType( url );
+ if ( eType == D_ODBC )
+ {
+ if ( !m_xODBCDriver.is() )
+ m_xODBCDriver = lcl_loadDriver(m_xFactory,sCuttedUrl);
+ xDriver = m_xODBCDriver;
+ } // if ( bIsODBC )
+ else if ( eType == D_NATIVE )
+ {
+ if ( !m_xNativeDriver.is() )
+ m_xNativeDriver = lcl_loadDriver(m_xFactory,sCuttedUrl);
+ xDriver = m_xNativeDriver;
+ }
+ else
+ {
+ ::comphelper::NamedValueCollection aSettings( info );
+ ::rtl::OUString sDriverClass(RTL_CONSTASCII_USTRINGPARAM("com.mysql.jdbc.Driver"));
+ sDriverClass = aSettings.getOrDefault( "JavaDriverClass", sDriverClass );
+
+ TJDBCDrivers::iterator aFind = m_aJdbcDrivers.find(sDriverClass);
+ if ( aFind == m_aJdbcDrivers.end() )
+ aFind = m_aJdbcDrivers.insert(TJDBCDrivers::value_type(sDriverClass,lcl_loadDriver(m_xFactory,sCuttedUrl))).first;
+ xDriver = aFind->second;
+ }
+
+ return xDriver;
+ }
+
+ //--------------------------------------------------------------------
+ Reference< XConnection > SAL_CALL ODriverDelegator::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw (SQLException, RuntimeException)
+ {
+ Reference< XConnection > xConnection;
+ if ( acceptsURL(url) )
+ {
+ Reference< XDriver > xDriver;
+ xDriver = loadDriver(url,info);
+ if ( xDriver.is() )
+ {
+ ::rtl::OUString sCuttedUrl = transformUrl(url);
+ const T_DRIVERTYPE eType = lcl_getDriverType( url );
+ Sequence< PropertyValue > aConvertedProperties = lcl_convertProperties(eType,info,url);
+ if ( eType == D_JDBC )
+ {
+ ::comphelper::NamedValueCollection aSettings( info );
+ ::rtl::OUString sIanaName = aSettings.getOrDefault( "CharSet", ::rtl::OUString() );
+ if ( sIanaName.getLength() )
+ {
+ ::dbtools::OCharsetMap aLookupIanaName;
+ ::dbtools::OCharsetMap::const_iterator aLookup = aLookupIanaName.find(sIanaName, ::dbtools::OCharsetMap::IANA());
+ if (aLookup != aLookupIanaName.end() )
+ {
+ ::rtl::OUString sAdd;
+ if ( RTL_TEXTENCODING_UTF8 == (*aLookup).getEncoding() )
+ {
+ static const ::rtl::OUString s_sCharSetOp(RTL_CONSTASCII_USTRINGPARAM("useUnicode=true&"));
+ if ( !sCuttedUrl.matchIgnoreAsciiCase(s_sCharSetOp) )
+ {
+ sAdd = s_sCharSetOp;
+ } // if ( !sCuttedUrl.matchIgnoreAsciiCase(s_sCharSetOp) )
+ } // if ( RTL_TEXTENCODING_UTF8 == (*aLookup).getEncoding() )
+ if ( sCuttedUrl.indexOf('?') == -1 )
+ sCuttedUrl += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("?"));
+ else
+ sCuttedUrl += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("&"));
+ sCuttedUrl += sAdd;
+ sCuttedUrl += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("characterEncoding="));
+ sCuttedUrl += sIanaName;
+ }
+ }
+ } // if ( !bIsODBC )
+
+ xConnection = xDriver->connect( sCuttedUrl, aConvertedProperties );
+ if ( xConnection.is() )
+ {
+ OMetaConnection* pMetaConnection = NULL;
+ // now we have to set the URL to get the correct answer for metadata()->getURL()
+ Reference< XUnoTunnel> xTunnel(xConnection,UNO_QUERY);
+ if ( xTunnel.is() )
+ {
+ pMetaConnection = reinterpret_cast<OMetaConnection*>(xTunnel->getSomething( OMetaConnection::getUnoTunnelImplementationId() ));
+ if ( pMetaConnection )
+ pMetaConnection->setURL(url);
+ }
+ m_aConnections.push_back(TWeakPair(WeakReferenceHelper(xConnection),TWeakConnectionPair(WeakReferenceHelper(),pMetaConnection)));
+ }
+ }
+ }
+ return xConnection;
+ }
+
+ //--------------------------------------------------------------------
+ sal_Bool SAL_CALL ODriverDelegator::acceptsURL( const ::rtl::OUString& url ) throw (SQLException, RuntimeException)
+ {
+ Sequence< PropertyValue > info;
+
+ sal_Bool bOK = url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "sdbc:mysql:odbc:" ) )
+ || url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "sdbc:mysql:jdbc:" ) )
+ || ( url.matchAsciiL( RTL_CONSTASCII_STRINGPARAM( "sdbc:mysql:mysqlc:" ) )
+ && loadDriver( url, info ).is()
+ );
+ return bOK;
+ }
+
+ //--------------------------------------------------------------------
+ Sequence< DriverPropertyInfo > SAL_CALL ODriverDelegator::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& /*info*/ ) throw (SQLException, RuntimeException)
+ {
+ ::std::vector< DriverPropertyInfo > aDriverInfo;
+ if ( !acceptsURL(url) )
+ return Sequence< DriverPropertyInfo >();
+
+ Sequence< ::rtl::OUString > aBoolean(2);
+ aBoolean[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"));
+ aBoolean[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("1"));
+
+
+ aDriverInfo.push_back(DriverPropertyInfo(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet"))
+ ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharSet of the database."))
+ ,sal_False
+ ,::rtl::OUString()
+ ,Sequence< ::rtl::OUString >())
+ );
+ aDriverInfo.push_back(DriverPropertyInfo(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SuppressVersionColumns"))
+ ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Display version columns (when available)."))
+ ,sal_False
+ ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0"))
+ ,aBoolean)
+ );
+ const T_DRIVERTYPE eType = lcl_getDriverType( url );
+ if ( eType == D_JDBC )
+ {
+ aDriverInfo.push_back(DriverPropertyInfo(
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("JavaDriverClass"))
+ ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("The JDBC driver class name."))
+ ,sal_True
+ ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.mysql.jdbc.Driver"))
+ ,Sequence< ::rtl::OUString >())
+ );
+ }
+
+ return Sequence< DriverPropertyInfo >(&aDriverInfo[0],aDriverInfo.size());
+ }
+
+ //--------------------------------------------------------------------
+ sal_Int32 SAL_CALL ODriverDelegator::getMajorVersion( ) throw (RuntimeException)
+ {
+ return 1;
+ }
+
+ //--------------------------------------------------------------------
+ sal_Int32 SAL_CALL ODriverDelegator::getMinorVersion( ) throw (RuntimeException)
+ {
+ return 0;
+ }
+
+ //--------------------------------------------------------------------
+ Reference< XTablesSupplier > SAL_CALL ODriverDelegator::getDataDefinitionByConnection( const Reference< XConnection >& connection ) throw (SQLException, RuntimeException)
+ {
+ ::osl::MutexGuard aGuard( m_aMutex );
+ checkDisposed(ODriverDelegator_BASE::rBHelper.bDisposed);
+
+ Reference< XTablesSupplier > xTab;
+ Reference< XUnoTunnel> xTunnel(connection,UNO_QUERY);
+ if ( xTunnel.is() )
+ {
+ OMetaConnection* pConnection = reinterpret_cast<OMetaConnection*>(xTunnel->getSomething( OMetaConnection::getUnoTunnelImplementationId() ));
+ if ( pConnection )
+ {
+ TWeakPairVector::iterator aEnd = m_aConnections.end();
+ for (TWeakPairVector::iterator i = m_aConnections.begin(); aEnd != i; ++i)
+ {
+ if ( i->second.second == pConnection )
+ {
+ xTab = Reference< XTablesSupplier >(i->second.first.get().get(),UNO_QUERY);
+ if ( !xTab.is() )
+ {
+ xTab = new OMySQLCatalog(connection);
+ i->second.first = WeakReferenceHelper(xTab);
+ }
+ break;
+ }
+ }
+ }
+ } // if ( xTunnel.is() )
+ if ( !xTab.is() )
+ {
+ TWeakPairVector::iterator aEnd = m_aConnections.end();
+ for (TWeakPairVector::iterator i = m_aConnections.begin(); aEnd != i; ++i)
+ {
+ Reference< XConnection > xTemp(i->first.get(),UNO_QUERY);
+ if ( xTemp == connection )
+ {
+ xTab = Reference< XTablesSupplier >(i->second.first.get().get(),UNO_QUERY);
+ if ( !xTab.is() )
+ {
+ xTab = new OMySQLCatalog(connection);
+ i->second.first = WeakReferenceHelper(xTab);
+ }
+ break;
+ }
+ }
+ }
+ return xTab;
+ }
+
+ //--------------------------------------------------------------------
+ Reference< XTablesSupplier > SAL_CALL ODriverDelegator::getDataDefinitionByURL( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw (SQLException, RuntimeException)
+ {
+ if ( ! acceptsURL(url) )
+ {
+ ::connectivity::SharedResources aResources;
+ const ::rtl::OUString sMessage = aResources.getResourceString(STR_URI_SYNTAX_ERROR);
+ ::dbtools::throwGenericSQLException(sMessage ,*this);
+ } // if ( ! acceptsURL(url) )
+
+ return getDataDefinitionByConnection(connect(url,info));
+ }
+
+ // XServiceInfo
+ // --------------------------------------------------------------------------------
+ //------------------------------------------------------------------------------
+ rtl::OUString ODriverDelegator::getImplementationName_Static( ) throw(RuntimeException)
+ {
+ return rtl::OUString::createFromAscii("org.openoffice.comp.drivers.MySQL.Driver");
+ }
+ //------------------------------------------------------------------------------
+ Sequence< ::rtl::OUString > ODriverDelegator::getSupportedServiceNames_Static( ) throw (RuntimeException)
+ {
+ Sequence< ::rtl::OUString > aSNS( 2 );
+ aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
+ aSNS[1] = ::rtl::OUString::createFromAscii("com.sun.star.sdbcx.Driver");
+ return aSNS;
+ }
+ //------------------------------------------------------------------
+ ::rtl::OUString SAL_CALL ODriverDelegator::getImplementationName( ) throw(RuntimeException)
+ {
+ return getImplementationName_Static();
+ }
+
+ //------------------------------------------------------------------
+ sal_Bool SAL_CALL ODriverDelegator::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
+ {
+ Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
+ const ::rtl::OUString* pSupported = aSupported.getConstArray();
+ const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
+ for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
+ ;
+
+ return pSupported != pEnd;
+ }
+ //------------------------------------------------------------------
+ Sequence< ::rtl::OUString > SAL_CALL ODriverDelegator::getSupportedServiceNames( ) throw(RuntimeException)
+ {
+ return getSupportedServiceNames_Static();
+ }
+ //------------------------------------------------------------------
+//........................................................................
+} // namespace connectivity
+//........................................................................
diff --git a/connectivity/source/drivers/mysql/YTable.cxx b/connectivity/source/drivers/mysql/YTable.cxx
new file mode 100644
index 000000000000..06be64f83313
--- /dev/null
+++ b/connectivity/source/drivers/mysql/YTable.cxx
@@ -0,0 +1,385 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_connectivity.hxx"
+#include "mysql/YTable.hxx"
+#include "mysql/YTables.hxx"
+#include <com/sun/star/sdbc/XRow.hpp>
+#include <com/sun/star/sdbc/XResultSet.hpp>
+#include <com/sun/star/sdbcx/KeyType.hpp>
+#include <com/sun/star/sdbc/KeyRule.hpp>
+#include <cppuhelper/typeprovider.hxx>
+#include <com/sun/star/lang/DisposedException.hpp>
+#include <com/sun/star/sdbc/ColumnValue.hpp>
+#include <com/sun/star/sdbcx/Privilege.hpp>
+#include <comphelper/property.hxx>
+#include <comphelper/extract.hxx>
+#include <comphelper/types.hxx>
+#include "connectivity/dbtools.hxx"
+#include "connectivity/sdbcx/VColumn.hxx"
+#include "connectivity/TKeys.hxx"
+#include "connectivity/TIndexes.hxx"
+#include "connectivity/TColumnsHelper.hxx"
+#include "mysql/YCatalog.hxx"
+#include "mysql/YColumns.hxx"
+#include "TConnection.hxx"
+
+
+using namespace ::comphelper;
+using namespace connectivity::mysql;
+using namespace connectivity::sdbcx;
+using namespace connectivity;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::sdbcx;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::lang;
+namespace connectivity
+{
+ namespace mysql
+ {
+ class OMySQLKeysHelper : public OKeysHelper
+ {
+ protected:
+ // -----------------------------------------------------------------------------
+ virtual ::rtl::OUString getDropForeignKey() const
+ {
+ return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" DROP FOREIGN KEY "));
+ }
+ public:
+ OMySQLKeysHelper( OTableHelper* _pTable,
+ ::osl::Mutex& _rMutex,
+ const TStringVector& _rVector
+ ) : OKeysHelper(_pTable,_rMutex,_rVector){}
+
+ };
+ }
+}
+
+OMySQLTable::OMySQLTable( sdbcx::OCollection* _pTables,
+ const Reference< XConnection >& _xConnection)
+ :OTableHelper(_pTables,_xConnection,sal_True)
+{
+ // we create a new table here, so we should have all the rights or ;-)
+ m_nPrivileges = Privilege::DROP |
+ Privilege::REFERENCE |
+ Privilege::ALTER |
+ Privilege::CREATE |
+ Privilege::READ |
+ Privilege::DELETE |
+ Privilege::UPDATE |
+ Privilege::INSERT |
+ Privilege::SELECT;
+ construct();
+}
+// -------------------------------------------------------------------------
+OMySQLTable::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
+ ) : OTableHelper( _pTables,
+ _xConnection,
+ sal_True,
+ _Name,
+ _Type,
+ _Description,
+ _SchemaName,
+ _CatalogName)
+ , m_nPrivileges(_nPrivileges)
+{
+ construct();
+}
+// -------------------------------------------------------------------------
+void OMySQLTable::construct()
+{
+ OTableHelper::construct();
+ if ( !isNew() )
+ registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRIVILEGES), PROPERTY_ID_PRIVILEGES,PropertyAttribute::READONLY,&m_nPrivileges, ::getCppuType(&m_nPrivileges));
+}
+// -----------------------------------------------------------------------------
+::cppu::IPropertyArrayHelper* OMySQLTable::createArrayHelper( sal_Int32 /*_nId*/ ) const
+{
+ return doCreateArrayHelper();
+}
+// -------------------------------------------------------------------------
+::cppu::IPropertyArrayHelper & OMySQLTable::getInfoHelper()
+{
+ return *static_cast<OMySQLTable_PROP*>(const_cast<OMySQLTable*>(this))->getArrayHelper(isNew() ? 1 : 0);
+}
+// -----------------------------------------------------------------------------
+sdbcx::OCollection* OMySQLTable::createColumns(const TStringVector& _rNames)
+{
+ OMySQLColumns* pColumns = new OMySQLColumns(*this,sal_True,m_aMutex,_rNames);
+ pColumns->setParent(this);
+ return pColumns;
+}
+// -----------------------------------------------------------------------------
+sdbcx::OCollection* OMySQLTable::createKeys(const TStringVector& _rNames)
+{
+ return new OMySQLKeysHelper(this,m_aMutex,_rNames);
+}
+// -----------------------------------------------------------------------------
+sdbcx::OCollection* OMySQLTable::createIndexes(const TStringVector& _rNames)
+{
+ return new OIndexesHelper(this,m_aMutex,_rNames);
+}
+//--------------------------------------------------------------------------
+Sequence< sal_Int8 > OMySQLTable::getUnoTunnelImplementationId()
+{
+ static ::cppu::OImplementationId * pId = 0;
+ if (! pId)
+ {
+ ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
+ if (! pId)
+ {
+ static ::cppu::OImplementationId aId;
+ pId = &aId;
+ }
+ }
+ return pId->getImplementationId();
+}
+
+// com::sun::star::lang::XUnoTunnel
+//------------------------------------------------------------------
+sal_Int64 OMySQLTable::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
+{
+ return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
+ ? reinterpret_cast< sal_Int64 >( this )
+ : OTable_TYPEDEF::getSomething(rId);
+}
+// -------------------------------------------------------------------------
+// XAlterTable
+void SAL_CALL OMySQLTable::alterColumnByName( const ::rtl::OUString& colName, const Reference< XPropertySet >& descriptor ) throw(SQLException, NoSuchElementException, RuntimeException)
+{
+ ::osl::MutexGuard aGuard(m_aMutex);
+ checkDisposed(
+#ifdef GCC
+ ::connectivity::sdbcx::OTableDescriptor_BASE::rBHelper.bDisposed
+#else
+ rBHelper.bDisposed
+#endif
+ );
+
+ if ( m_pColumns && !m_pColumns->hasByName(colName) )
+ throw NoSuchElementException(colName,*this);
+
+
+ if ( !isNew() )
+ {
+ // first we have to check what should be altered
+ Reference<XPropertySet> xProp;
+ m_pColumns->getByName(colName) >>= xProp;
+ // first check the types
+ sal_Int32 nOldType = 0,nNewType = 0,nOldPrec = 0,nNewPrec = 0,nOldScale = 0,nNewScale = 0;
+
+ ::dbtools::OPropertyMap& rProp = OMetaConnection::getPropMap();
+ xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_TYPE)) >>= nOldType;
+ descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_TYPE)) >>= nNewType;
+ // and precsions and scale
+ xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_PRECISION)) >>= nOldPrec;
+ descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_PRECISION))>>= nNewPrec;
+ xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_SCALE)) >>= nOldScale;
+ descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_SCALE)) >>= nNewScale;
+ // second: check the "is nullable" value
+ sal_Int32 nOldNullable = 0,nNewNullable = 0;
+ xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISNULLABLE)) >>= nOldNullable;
+ descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISNULLABLE)) >>= nNewNullable;
+
+ // check also the auto_increment
+ sal_Bool bOldAutoIncrement = sal_False,bAutoIncrement = sal_False;
+ xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bOldAutoIncrement;
+ descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)) >>= bAutoIncrement;
+ bool bColumnNameChanged = false;
+ ::rtl::OUString sOldDesc,sNewDesc;
+ xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_DESCRIPTION)) >>= sOldDesc;
+ descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_DESCRIPTION)) >>= sNewDesc;
+
+ if ( nOldType != nNewType
+ || nOldPrec != nNewPrec
+ || nOldScale != nNewScale
+ || nNewNullable != nOldNullable
+ || bOldAutoIncrement != bAutoIncrement
+ || sOldDesc != sNewDesc )
+ {
+ // special handling because they change dthe type names to distinguish
+ // if a column should be an auto_incmrement one
+ if ( bOldAutoIncrement != bAutoIncrement )
+ {
+ ::rtl::OUString sTypeName;
+ descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_TYPENAME)) >>= sTypeName;
+
+ static ::rtl::OUString s_sAutoIncrement(RTL_CONSTASCII_USTRINGPARAM("auto_increment"));
+ if ( bAutoIncrement )
+ {
+ if ( sTypeName.indexOf(s_sAutoIncrement) == -1 )
+ {
+ sTypeName += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" "));
+ sTypeName += s_sAutoIncrement;
+ }
+ }
+ else
+ {
+ sal_Int32 nIndex = 0;
+ if ( sTypeName.getLength() && (nIndex = sTypeName.indexOf(s_sAutoIncrement)) != -1 )
+ {
+ sTypeName = sTypeName.copy(0,nIndex);
+ descriptor->setPropertyValue(rProp.getNameByIndex(PROPERTY_ID_TYPENAME),makeAny(sTypeName));
+ }
+ }
+ }
+ alterColumnType(nNewType,colName,descriptor);
+ bColumnNameChanged = true;
+ }
+
+ // third: check the default values
+ ::rtl::OUString sNewDefault,sOldDefault;
+ xProp->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_DEFAULTVALUE)) >>= sOldDefault;
+ descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_DEFAULTVALUE)) >>= sNewDefault;
+
+ if(sOldDefault.getLength())
+ {
+ dropDefaultValue(colName);
+ if(sNewDefault.getLength() && sOldDefault != sNewDefault)
+ alterDefaultValue(sNewDefault,colName);
+ }
+ else if(!sOldDefault.getLength() && sNewDefault.getLength())
+ alterDefaultValue(sNewDefault,colName);
+
+ // now we should look if the name of the column changed
+ ::rtl::OUString sNewColumnName;
+ descriptor->getPropertyValue(rProp.getNameByIndex(PROPERTY_ID_NAME)) >>= sNewColumnName;
+ if ( !sNewColumnName.equalsIgnoreAsciiCase(colName) && !bColumnNameChanged )
+ {
+ ::rtl::OUString sSql = getAlterTableColumnPart();
+ sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" CHANGE "));
+ const ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( );
+ sSql += ::dbtools::quoteName(sQuote,colName);
+ sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" "));
+ sSql += OTables::adjustSQL(::dbtools::createStandardColumnPart(descriptor,getConnection(),static_cast<OTables*>(m_pTables),getTypeCreatePattern()));
+ executeStatement(sSql);
+ }
+ m_pColumns->refresh();
+ }
+ else
+ {
+ if(m_pColumns)
+ {
+ m_pColumns->dropByName(colName);
+ m_pColumns->appendByDescriptor(descriptor);
+ }
+ }
+
+}
+// -----------------------------------------------------------------------------
+void OMySQLTable::alterColumnType(sal_Int32 nNewType,const ::rtl::OUString& _rColName, const Reference<XPropertySet>& _xDescriptor)
+{
+ ::rtl::OUString sSql = getAlterTableColumnPart();
+ sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" CHANGE "));
+ const ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( );
+ sSql += ::dbtools::quoteName(sQuote,_rColName);
+ sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" "));
+
+ OColumn* pColumn = new OColumn(sal_True);
+ Reference<XPropertySet> xProp = pColumn;
+ ::comphelper::copyProperties(_xDescriptor,xProp);
+ xProp->setPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE),makeAny(nNewType));
+
+ sSql += OTables::adjustSQL(::dbtools::createStandardColumnPart(xProp,getConnection(),static_cast<OTables*>(m_pTables),getTypeCreatePattern()));
+ executeStatement(sSql);
+}
+// -----------------------------------------------------------------------------
+::rtl::OUString OMySQLTable::getTypeCreatePattern() const
+{
+ static const ::rtl::OUString s_sCreatePattern(RTL_CONSTASCII_USTRINGPARAM("(M,D)"));
+ return s_sCreatePattern;
+}
+// -----------------------------------------------------------------------------
+void OMySQLTable::alterDefaultValue(const ::rtl::OUString& _sNewDefault,const ::rtl::OUString& _rColName)
+{
+ ::rtl::OUString sSql = getAlterTableColumnPart();
+ sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ALTER "));
+
+ const ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( );
+ sSql += ::dbtools::quoteName(sQuote,_rColName);
+ sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" SET DEFAULT '")) + _sNewDefault;
+ sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("'"));
+
+ executeStatement(sSql);
+}
+// -----------------------------------------------------------------------------
+void OMySQLTable::dropDefaultValue(const ::rtl::OUString& _rColName)
+{
+ ::rtl::OUString sSql = getAlterTableColumnPart();
+ sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ALTER "));
+
+ const ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( );
+ sSql += ::dbtools::quoteName(sQuote,_rColName);
+ sSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" DROP DEFAULT"));
+
+ executeStatement(sSql);
+}
+// -----------------------------------------------------------------------------
+::rtl::OUString OMySQLTable::getAlterTableColumnPart()
+{
+ ::rtl::OUString sSql = ::rtl::OUString::createFromAscii("ALTER TABLE ");
+ const ::rtl::OUString sQuote = getMetaData()->getIdentifierQuoteString( );
+
+ ::rtl::OUString sComposedName(
+ ::dbtools::composeTableName( getMetaData(), m_CatalogName, m_SchemaName, m_Name, sal_True, ::dbtools::eInTableDefinitions ) );
+ sSql += sComposedName;
+
+ return sSql;
+}
+// -----------------------------------------------------------------------------
+void OMySQLTable::executeStatement(const ::rtl::OUString& _rStatement )
+{
+ ::rtl::OUString sSQL = _rStatement;
+ if(sSQL.lastIndexOf(',') == (sSQL.getLength()-1))
+ sSQL = sSQL.replaceAt(sSQL.getLength()-1,1,::rtl::OUString::createFromAscii(")"));
+
+ Reference< XStatement > xStmt = getConnection()->createStatement( );
+ if ( xStmt.is() )
+ {
+ xStmt->execute(sSQL);
+ ::comphelper::disposeComponent(xStmt);
+ }
+}
+// -----------------------------------------------------------------------------
+::rtl::OUString OMySQLTable::getRenameStart() const
+{
+ return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RENAME TABLE "));
+}
+
+
+
+
diff --git a/connectivity/source/drivers/mysql/YTables.cxx b/connectivity/source/drivers/mysql/YTables.cxx
new file mode 100644
index 000000000000..80bb2baf58c0
--- /dev/null
+++ b/connectivity/source/drivers/mysql/YTables.cxx
@@ -0,0 +1,243 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_connectivity.hxx"
+#include "mysql/YTables.hxx"
+#include "mysql/YViews.hxx"
+#include "mysql/YTable.hxx"
+#include <com/sun/star/sdbc/XRow.hpp>
+#include <com/sun/star/sdbc/XResultSet.hpp>
+#include <com/sun/star/sdbc/ColumnValue.hpp>
+#include <com/sun/star/sdbcx/Privilege.hpp>
+#include <com/sun/star/sdbc/KeyRule.hpp>
+#include <com/sun/star/sdbcx/KeyType.hpp>
+#include "mysql/YCatalog.hxx"
+#include <comphelper/extract.hxx>
+#include "connectivity/dbtools.hxx"
+#include "connectivity/dbexception.hxx"
+#include <cppuhelper/interfacecontainer.h>
+#include <comphelper/types.hxx>
+#include "TConnection.hxx"
+
+using namespace ::comphelper;
+using namespace connectivity;
+using namespace ::cppu;
+using namespace connectivity::mysql;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::sdbcx;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::lang;
+using namespace dbtools;
+typedef connectivity::sdbcx::OCollection OCollection_TYPE;
+
+sdbcx::ObjectType OTables::createObject(const ::rtl::OUString& _rName)
+{
+ ::rtl::OUString sCatalog,sSchema,sTable;
+ ::dbtools::qualifiedNameComponents(m_xMetaData,_rName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation);
+
+ static const ::rtl::OUString s_sTableTypeView(RTL_CONSTASCII_USTRINGPARAM("VIEW"));
+ static const ::rtl::OUString s_sTableTypeTable(RTL_CONSTASCII_USTRINGPARAM("TABLE"));
+ static const ::rtl::OUString s_sAll(RTL_CONSTASCII_USTRINGPARAM("%"));
+
+ Sequence< ::rtl::OUString > sTableTypes(3);
+ sTableTypes[0] = s_sTableTypeView;
+ sTableTypes[1] = s_sTableTypeTable;
+ sTableTypes[2] = s_sAll; // just to be sure to include anything else ....
+
+ Any aCatalog;
+ if ( sCatalog.getLength() )
+ aCatalog <<= sCatalog;
+ Reference< XResultSet > xResult = m_xMetaData->getTables(aCatalog,sSchema,sTable,sTableTypes);
+
+ sdbcx::ObjectType xRet = NULL;
+ if ( xResult.is() )
+ {
+ Reference< XRow > xRow(xResult,UNO_QUERY);
+ if ( xResult->next() ) // there can be only one table with this name
+ {
+// Reference<XStatement> xStmt = m_xConnection->createStatement();
+// if ( xStmt.is() )
+// {
+// Reference< XResultSet > xPrivRes = xStmt->executeQuery();
+// Reference< XRow > xPrivRow(xPrivRes,UNO_QUERY);
+// while ( xPrivRes.is() && xPrivRes->next() )
+// {
+// if ( xPrivRow->getString(1) )
+// {
+// }
+// }
+// }
+ sal_Int32 nPrivileges = Privilege::DROP |
+ Privilege::REFERENCE |
+ Privilege::ALTER |
+ Privilege::CREATE |
+ Privilege::READ |
+ Privilege::DELETE |
+ Privilege::UPDATE |
+ Privilege::INSERT |
+ Privilege::SELECT;
+
+ OMySQLTable* pRet = new OMySQLTable( this
+ ,static_cast<OMySQLCatalog&>(m_rParent).getConnection()
+ ,sTable
+ ,xRow->getString(4)
+ ,xRow->getString(5)
+ ,sSchema
+ ,sCatalog
+ ,nPrivileges);
+ xRet = pRet;
+ }
+ ::comphelper::disposeComponent(xResult);
+ }
+
+ return xRet;
+}
+// -------------------------------------------------------------------------
+void OTables::impl_refresh( ) throw(RuntimeException)
+{
+ static_cast<OMySQLCatalog&>(m_rParent).refreshTables();
+}
+// -------------------------------------------------------------------------
+void OTables::disposing(void)
+{
+m_xMetaData.clear();
+ OCollection::disposing();
+}
+// -------------------------------------------------------------------------
+Reference< XPropertySet > OTables::createDescriptor()
+{
+ return new OMySQLTable(this,static_cast<OMySQLCatalog&>(m_rParent).getConnection());
+}
+// -------------------------------------------------------------------------
+// XAppend
+sdbcx::ObjectType OTables::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor )
+{
+ createTable(descriptor);
+ return createObject( _rForName );
+}
+// -------------------------------------------------------------------------
+// XDrop
+void OTables::dropObject(sal_Int32 _nPos,const ::rtl::OUString _sElementName)
+{
+ Reference< XInterface > xObject( getObject( _nPos ) );
+ sal_Bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject );
+ if (!bIsNew)
+ {
+ Reference< XConnection > xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
+
+
+ ::rtl::OUString sCatalog,sSchema,sTable;
+ ::dbtools::qualifiedNameComponents(m_xMetaData,_sElementName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation);
+
+ ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("DROP ");
+
+ Reference<XPropertySet> xProp(xObject,UNO_QUERY);
+ sal_Bool bIsView = xProp.is() && ::comphelper::getString(xProp->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))) == ::rtl::OUString::createFromAscii("VIEW");
+ if(bIsView) // here we have a view
+ aSql += ::rtl::OUString::createFromAscii("VIEW ");
+ else
+ aSql += ::rtl::OUString::createFromAscii("TABLE ");
+
+ ::rtl::OUString sComposedName(
+ ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, sal_True, ::dbtools::eInDataManipulation ) );
+ aSql += sComposedName;
+ Reference< XStatement > xStmt = xConnection->createStatement( );
+ if ( xStmt.is() )
+ {
+ xStmt->execute(aSql);
+ ::comphelper::disposeComponent(xStmt);
+ }
+ // if no exception was thrown we must delete it from the views
+ if ( bIsView )
+ {
+ OViews* pViews = static_cast<OViews*>(static_cast<OMySQLCatalog&>(m_rParent).getPrivateViews());
+ if ( pViews && pViews->hasByName(_sElementName) )
+ pViews->dropByNameImpl(_sElementName);
+ }
+ }
+}
+// -------------------------------------------------------------------------
+::rtl::OUString OTables::adjustSQL(const ::rtl::OUString& _sSql)
+{
+ ::rtl::OUString sSQL = _sSql;
+ static const ::rtl::OUString s_sUNSIGNED(RTL_CONSTASCII_USTRINGPARAM("UNSIGNED"));
+ sal_Int32 nIndex = sSQL.indexOf(s_sUNSIGNED);
+ while(nIndex != -1 )
+ {
+ sal_Int32 nParen = sSQL.indexOf(')',nIndex);
+ sal_Int32 nPos = nIndex + s_sUNSIGNED.getLength();
+ ::rtl::OUString sNewUnsigned( sSQL.copy(nPos,nParen - nPos + 1));
+ sSQL = sSQL.replaceAt(nIndex,s_sUNSIGNED.getLength()+sNewUnsigned.getLength(),sNewUnsigned + s_sUNSIGNED);
+ nIndex = sSQL.indexOf(s_sUNSIGNED,nIndex + s_sUNSIGNED.getLength()+sNewUnsigned.getLength());
+ }
+ return sSQL;
+}
+// -------------------------------------------------------------------------
+void OTables::createTable( const Reference< XPropertySet >& descriptor )
+{
+ const Reference< XConnection > xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
+ static const ::rtl::OUString s_sCreatePattern(RTL_CONSTASCII_USTRINGPARAM("(M,D)"));
+ const ::rtl::OUString aSql = adjustSQL(::dbtools::createSqlCreateTableStatement(descriptor,xConnection,this,s_sCreatePattern));
+ Reference< XStatement > xStmt = xConnection->createStatement( );
+ if ( xStmt.is() )
+ {
+ xStmt->execute(aSql);
+ ::comphelper::disposeComponent(xStmt);
+ }
+}
+// -----------------------------------------------------------------------------
+void OTables::appendNew(const ::rtl::OUString& _rsNewTable)
+{
+ insertElement(_rsNewTable,NULL);
+
+ // notify our container listeners
+ ContainerEvent aEvent(static_cast<XContainer*>(this), makeAny(_rsNewTable), Any(), Any());
+ OInterfaceIteratorHelper aListenerLoop(m_aContainerListeners);
+ while (aListenerLoop.hasMoreElements())
+ static_cast<XContainerListener*>(aListenerLoop.next())->elementInserted(aEvent);
+}
+// -----------------------------------------------------------------------------
+::rtl::OUString OTables::getNameForObject(const sdbcx::ObjectType& _xObject)
+{
+ OSL_ENSURE(_xObject.is(),"OTables::getNameForObject: Object is NULL!");
+ return ::dbtools::composeTableName( m_xMetaData, _xObject, ::dbtools::eInDataManipulation, false, false, false );
+}
+// -----------------------------------------------------------------------------
+void OTables::addComment(const Reference< XPropertySet >& descriptor,::rtl::OUStringBuffer& _rOut)
+{
+ ::rtl::OUString sDesc;
+ descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION)) >>= sDesc;
+ if ( sDesc.getLength() )
+ {
+ _rOut.appendAscii(" COMMENT '");
+ _rOut.append(sDesc);
+ _rOut.appendAscii("'");
+ }
+}
diff --git a/connectivity/source/drivers/mysql/YUser.cxx b/connectivity/source/drivers/mysql/YUser.cxx
new file mode 100644
index 000000000000..9913fbe963fd
--- /dev/null
+++ b/connectivity/source/drivers/mysql/YUser.cxx
@@ -0,0 +1,350 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_connectivity.hxx"
+#include "mysql/YUser.hxx"
+#include <com/sun/star/sdbc/XRow.hpp>
+#include <com/sun/star/sdbc/XResultSet.hpp>
+#include "connectivity/dbtools.hxx"
+#include "connectivity/dbexception.hxx"
+#include <com/sun/star/sdbcx/Privilege.hpp>
+#include <com/sun/star/sdbcx/PrivilegeObject.hpp>
+#include "TConnection.hxx"
+#include "resource/common_res.hrc"
+
+using namespace connectivity;
+using namespace connectivity::mysql;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::sdbcx;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::lang;
+// -------------------------------------------------------------------------
+OMySQLUser::OMySQLUser( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection) : connectivity::sdbcx::OUser(sal_True)
+ ,m_xConnection(_xConnection)
+{
+ construct();
+}
+// -------------------------------------------------------------------------
+OMySQLUser::OMySQLUser( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,
+ const ::rtl::OUString& _Name
+ ) : connectivity::sdbcx::OUser(_Name,sal_True)
+ ,m_xConnection(_xConnection)
+{
+ construct();
+}
+// -------------------------------------------------------------------------
+void OMySQLUser::refreshGroups()
+{
+}
+// -------------------------------------------------------------------------
+OUserExtend::OUserExtend( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection) : OMySQLUser(_xConnection)
+{
+ construct();
+}
+// -------------------------------------------------------------------------
+typedef connectivity::sdbcx::OUser OUser_TYPEDEF;
+void OUserExtend::construct()
+{
+ registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD), PROPERTY_ID_PASSWORD,0,&m_Password,::getCppuType(reinterpret_cast< ::rtl::OUString*>(NULL)));
+}
+// -----------------------------------------------------------------------------
+cppu::IPropertyArrayHelper* OUserExtend::createArrayHelper() const
+{
+ Sequence< Property > aProps;
+ describeProperties(aProps);
+ return new cppu::OPropertyArrayHelper(aProps);
+}
+// -------------------------------------------------------------------------
+cppu::IPropertyArrayHelper & OUserExtend::getInfoHelper()
+{
+ return *OUserExtend_PROP::getArrayHelper();
+}
+typedef connectivity::sdbcx::OUser_BASE OUser_BASE_RBHELPER;
+// -----------------------------------------------------------------------------
+sal_Int32 SAL_CALL OMySQLUser::getPrivileges( const ::rtl::OUString& objName, sal_Int32 objType ) throw(SQLException, RuntimeException)
+{
+ ::osl::MutexGuard aGuard(m_aMutex);
+ checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed);
+
+ sal_Int32 nRights,nRightsWithGrant;
+ findPrivilegesAndGrantPrivileges(objName,objType,nRights,nRightsWithGrant);
+ return nRights;
+}
+// -----------------------------------------------------------------------------
+void OMySQLUser::findPrivilegesAndGrantPrivileges(const ::rtl::OUString& objName, sal_Int32 objType,sal_Int32& nRights,sal_Int32& nRightsWithGrant) throw(SQLException, RuntimeException)
+{
+ nRightsWithGrant = nRights = 0;
+ // first we need to create the sql stmt to select the privs
+ Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData();
+ ::rtl::OUString sCatalog,sSchema,sTable;
+ ::dbtools::qualifiedNameComponents(xMeta,objName,sCatalog,sSchema,sTable,::dbtools::eInDataManipulation);
+ Reference<XResultSet> xRes;
+ switch(objType)
+ {
+ case PrivilegeObject::TABLE:
+ case PrivilegeObject::VIEW:
+ {
+ Any aCatalog;
+ if ( sCatalog.getLength() )
+ aCatalog <<= sCatalog;
+ xRes = xMeta->getTablePrivileges(aCatalog,sSchema,sTable);
+ }
+ break;
+
+ case PrivilegeObject::COLUMN:
+ {
+ Any aCatalog;
+ if ( sCatalog.getLength() )
+ aCatalog <<= sCatalog;
+ xRes = xMeta->getColumnPrivileges(aCatalog,sSchema,sTable,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")));
+ }
+ break;
+ }
+
+ if ( xRes.is() )
+ {
+ static const ::rtl::OUString sSELECT = ::rtl::OUString::createFromAscii("SELECT");
+ static const ::rtl::OUString sINSERT = ::rtl::OUString::createFromAscii("INSERT");
+ static const ::rtl::OUString sUPDATE = ::rtl::OUString::createFromAscii("UPDATE");
+ static const ::rtl::OUString sDELETE = ::rtl::OUString::createFromAscii("DELETE");
+ static const ::rtl::OUString sREAD = ::rtl::OUString::createFromAscii("READ");
+ static const ::rtl::OUString sCREATE = ::rtl::OUString::createFromAscii("CREATE");
+ static const ::rtl::OUString sALTER = ::rtl::OUString::createFromAscii("ALTER");
+ static const ::rtl::OUString sREFERENCE = ::rtl::OUString::createFromAscii("REFERENCE");
+ static const ::rtl::OUString sDROP = ::rtl::OUString::createFromAscii("DROP");
+ static const ::rtl::OUString sYes = ::rtl::OUString::createFromAscii("YES");
+
+ nRightsWithGrant = nRights = 0;
+
+ Reference<XRow> xCurrentRow(xRes,UNO_QUERY);
+ while( xCurrentRow.is() && xRes->next() )
+ {
+ ::rtl::OUString sGrantee = xCurrentRow->getString(5);
+ ::rtl::OUString sPrivilege = xCurrentRow->getString(6);
+ ::rtl::OUString sGrantable = xCurrentRow->getString(7);
+
+ if (!m_Name.equalsIgnoreAsciiCase(sGrantee))
+ continue;
+
+ if (sPrivilege.equalsIgnoreAsciiCase(sSELECT))
+ {
+ nRights |= Privilege::SELECT;
+ if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
+ nRightsWithGrant |= Privilege::SELECT;
+ }
+ else if (sPrivilege.equalsIgnoreAsciiCase(sINSERT))
+ {
+ nRights |= Privilege::INSERT;
+ if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
+ nRightsWithGrant |= Privilege::INSERT;
+ }
+ else if (sPrivilege.equalsIgnoreAsciiCase(sUPDATE))
+ {
+ nRights |= Privilege::UPDATE;
+ if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
+ nRightsWithGrant |= Privilege::UPDATE;
+ }
+ else if (sPrivilege.equalsIgnoreAsciiCase(sDELETE))
+ {
+ nRights |= Privilege::DELETE;
+ if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
+ nRightsWithGrant |= Privilege::DELETE;
+ }
+ else if (sPrivilege.equalsIgnoreAsciiCase(sREAD))
+ {
+ nRights |= Privilege::READ;
+ if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
+ nRightsWithGrant |= Privilege::READ;
+ }
+ else if (sPrivilege.equalsIgnoreAsciiCase(sCREATE))
+ {
+ nRights |= Privilege::CREATE;
+ if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
+ nRightsWithGrant |= Privilege::CREATE;
+ }
+ else if (sPrivilege.equalsIgnoreAsciiCase(sALTER))
+ {
+ nRights |= Privilege::ALTER;
+ if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
+ nRightsWithGrant |= Privilege::ALTER;
+ }
+ else if (sPrivilege.equalsIgnoreAsciiCase(sREFERENCE))
+ {
+ nRights |= Privilege::REFERENCE;
+ if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
+ nRightsWithGrant |= Privilege::REFERENCE;
+ }
+ else if (sPrivilege.equalsIgnoreAsciiCase(sDROP))
+ {
+ nRights |= Privilege::DROP;
+ if ( sGrantable.equalsIgnoreAsciiCase(sYes) )
+ nRightsWithGrant |= Privilege::DROP;
+ }
+ }
+ ::comphelper::disposeComponent(xRes);
+ }
+}
+// -------------------------------------------------------------------------
+sal_Int32 SAL_CALL OMySQLUser::getGrantablePrivileges( const ::rtl::OUString& objName, sal_Int32 objType ) throw(SQLException, RuntimeException)
+{
+ ::osl::MutexGuard aGuard(m_aMutex);
+ checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed);
+
+ sal_Int32 nRights,nRightsWithGrant;
+ findPrivilegesAndGrantPrivileges(objName,objType,nRights,nRightsWithGrant);
+ return nRightsWithGrant;
+}
+// -------------------------------------------------------------------------
+void SAL_CALL OMySQLUser::grantPrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) throw(SQLException, RuntimeException)
+{
+ if ( objType != PrivilegeObject::TABLE )
+ {
+ ::connectivity::SharedResources aResources;
+ const ::rtl::OUString sError( aResources.getResourceString(STR_PRIVILEGE_NOT_GRANTED));
+ ::dbtools::throwGenericSQLException(sError,*this);
+ } // if ( objType != PrivilegeObject::TABLE )
+
+ ::osl::MutexGuard aGuard(m_aMutex);
+
+ ::rtl::OUString sPrivs = getPrivilegeString(objPrivileges);
+ if(sPrivs.getLength())
+ {
+ ::rtl::OUString sGrant;
+ sGrant += ::rtl::OUString::createFromAscii("GRANT ");
+ sGrant += sPrivs;
+ sGrant += ::rtl::OUString::createFromAscii(" ON ");
+ Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData();
+ sGrant += ::dbtools::quoteTableName(xMeta,objName,::dbtools::eInDataManipulation);
+ sGrant += ::rtl::OUString::createFromAscii(" TO ");
+ sGrant += m_Name;
+
+ Reference<XStatement> xStmt = m_xConnection->createStatement();
+ if(xStmt.is())
+ xStmt->execute(sGrant);
+ ::comphelper::disposeComponent(xStmt);
+ }
+}
+// -------------------------------------------------------------------------
+void SAL_CALL OMySQLUser::revokePrivileges( const ::rtl::OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges ) throw(SQLException, RuntimeException)
+{
+ if ( objType != PrivilegeObject::TABLE )
+ {
+ ::connectivity::SharedResources aResources;
+ const ::rtl::OUString sError( aResources.getResourceString(STR_PRIVILEGE_NOT_REVOKED));
+ ::dbtools::throwGenericSQLException(sError,*this);
+ }
+
+ ::osl::MutexGuard aGuard(m_aMutex);
+ checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed);
+ ::rtl::OUString sPrivs = getPrivilegeString(objPrivileges);
+ if(sPrivs.getLength())
+ {
+ ::rtl::OUString sGrant;
+ sGrant += ::rtl::OUString::createFromAscii("REVOKE ");
+ sGrant += sPrivs;
+ sGrant += ::rtl::OUString::createFromAscii(" ON ");
+ Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData();
+ sGrant += ::dbtools::quoteTableName(xMeta,objName,::dbtools::eInDataManipulation);
+ sGrant += ::rtl::OUString::createFromAscii(" FROM ");
+ sGrant += m_Name;
+
+ Reference<XStatement> xStmt = m_xConnection->createStatement();
+ if(xStmt.is())
+ xStmt->execute(sGrant);
+ ::comphelper::disposeComponent(xStmt);
+ }
+}
+// -----------------------------------------------------------------------------
+// XUser
+void SAL_CALL OMySQLUser::changePassword( const ::rtl::OUString& /*oldPassword*/, const ::rtl::OUString& newPassword ) throw(SQLException, RuntimeException)
+{
+ ::osl::MutexGuard aGuard(m_aMutex);
+ checkDisposed(OUser_BASE_RBHELPER::rBHelper.bDisposed);
+ ::rtl::OUString sAlterPwd;
+ sAlterPwd = ::rtl::OUString::createFromAscii("SET PASSWORD FOR ");
+ sAlterPwd += m_Name;
+ sAlterPwd += ::rtl::OUString::createFromAscii("@\"%\" = PASSWORD('") ;
+ sAlterPwd += newPassword;
+ sAlterPwd += ::rtl::OUString::createFromAscii("')") ;
+
+
+ Reference<XStatement> xStmt = m_xConnection->createStatement();
+ if ( xStmt.is() )
+ {
+ xStmt->execute(sAlterPwd);
+ ::comphelper::disposeComponent(xStmt);
+ }
+}
+// -----------------------------------------------------------------------------
+::rtl::OUString OMySQLUser::getPrivilegeString(sal_Int32 nRights) const
+{
+ ::rtl::OUString sPrivs;
+ if((nRights & Privilege::INSERT) == Privilege::INSERT)
+ sPrivs += ::rtl::OUString::createFromAscii("INSERT");
+
+ if((nRights & Privilege::DELETE) == Privilege::DELETE)
+ {
+ if(sPrivs.getLength())
+ sPrivs += ::rtl::OUString::createFromAscii(",");
+ sPrivs += ::rtl::OUString::createFromAscii("DELETE");
+ }
+
+ if((nRights & Privilege::UPDATE) == Privilege::UPDATE)
+ {
+ if(sPrivs.getLength())
+ sPrivs += ::rtl::OUString::createFromAscii(",");
+ sPrivs += ::rtl::OUString::createFromAscii("UPDATE");
+ }
+
+ if((nRights & Privilege::ALTER) == Privilege::ALTER)
+ {
+ if(sPrivs.getLength())
+ sPrivs += ::rtl::OUString::createFromAscii(",");
+ sPrivs += ::rtl::OUString::createFromAscii("ALTER");
+ }
+
+ if((nRights & Privilege::SELECT) == Privilege::SELECT)
+ {
+ if(sPrivs.getLength())
+ sPrivs += ::rtl::OUString::createFromAscii(",");
+ sPrivs += ::rtl::OUString::createFromAscii("SELECT");
+ }
+
+ if((nRights & Privilege::REFERENCE) == Privilege::REFERENCE)
+ {
+ if(sPrivs.getLength())
+ sPrivs += ::rtl::OUString::createFromAscii(",");
+ sPrivs += ::rtl::OUString::createFromAscii("REFERENCES");
+ }
+
+ return sPrivs;
+}
+// -----------------------------------------------------------------------------
+
diff --git a/connectivity/source/drivers/mysql/YUsers.cxx b/connectivity/source/drivers/mysql/YUsers.cxx
new file mode 100644
index 000000000000..f49463becfd0
--- /dev/null
+++ b/connectivity/source/drivers/mysql/YUsers.cxx
@@ -0,0 +1,118 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_connectivity.hxx"
+#include "mysql/YUsers.hxx"
+#include "mysql/YUser.hxx"
+#include "mysql/YTable.hxx"
+#include <com/sun/star/sdbc/XRow.hpp>
+#include <com/sun/star/sdbc/XResultSet.hpp>
+#include "connectivity/sdbcx/IRefreshable.hxx"
+#include <comphelper/types.hxx>
+#include "connectivity/dbexception.hxx"
+#include "connectivity/dbtools.hxx"
+#include "TConnection.hxx"
+
+using namespace ::comphelper;
+using namespace connectivity;
+using namespace connectivity::mysql;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+// using namespace ::com::sun::star::sdbcx;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::lang;
+typedef connectivity::sdbcx::OCollection OCollection_TYPE;
+
+OUsers::OUsers( ::cppu::OWeakObject& _rParent,
+ ::osl::Mutex& _rMutex,
+ const TStringVector &_rVector,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,
+ connectivity::sdbcx::IRefreshableUsers* _pParent)
+ : sdbcx::OCollection(_rParent,sal_True,_rMutex,_rVector)
+ ,m_xConnection(_xConnection)
+ ,m_pParent(_pParent)
+{
+}
+// -----------------------------------------------------------------------------
+
+sdbcx::ObjectType OUsers::createObject(const ::rtl::OUString& _rName)
+{
+ return new OMySQLUser(m_xConnection,_rName);
+}
+// -------------------------------------------------------------------------
+void OUsers::impl_refresh() throw(RuntimeException)
+{
+ m_pParent->refreshUsers();
+}
+// -------------------------------------------------------------------------
+Reference< XPropertySet > OUsers::createDescriptor()
+{
+ OUserExtend* pNew = new OUserExtend(m_xConnection);
+ return pNew;
+}
+// -------------------------------------------------------------------------
+// XAppend
+sdbcx::ObjectType OUsers::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor )
+{
+ ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("GRANT USAGE ON * TO ");
+ ::rtl::OUString aQuote = m_xConnection->getMetaData()->getIdentifierQuoteString( );
+ ::rtl::OUString sUserName( _rForName );
+ aSql += ::dbtools::quoteName(aQuote,sUserName)
+ + ::rtl::OUString::createFromAscii(" @\"%\" ");
+ ::rtl::OUString sPassword;
+ descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD)) >>= sPassword;
+ if ( sPassword.getLength() )
+ {
+ aSql += ::rtl::OUString::createFromAscii(" IDENTIFIED BY '");
+ aSql += sPassword;
+ aSql += ::rtl::OUString::createFromAscii("'");
+ }
+
+ Reference< XStatement > xStmt = m_xConnection->createStatement( );
+ if(xStmt.is())
+ xStmt->execute(aSql);
+ ::comphelper::disposeComponent(xStmt);
+
+ return createObject( _rForName );
+}
+// -------------------------------------------------------------------------
+// XDrop
+void OUsers::dropObject(sal_Int32 /*_nPos*/,const ::rtl::OUString _sElementName)
+{
+ ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("REVOKE ALL ON * FROM ");
+ ::rtl::OUString aQuote = m_xConnection->getMetaData()->getIdentifierQuoteString( );
+ aSql += ::dbtools::quoteName(aQuote,_sElementName);
+
+ Reference< XStatement > xStmt = m_xConnection->createStatement( );
+ if(xStmt.is())
+ xStmt->execute(aSql);
+ ::comphelper::disposeComponent(xStmt);
+}
+
+// -------------------------------------------------------------------------
diff --git a/connectivity/source/drivers/mysql/YViews.cxx b/connectivity/source/drivers/mysql/YViews.cxx
new file mode 100644
index 000000000000..92fc15d94d91
--- /dev/null
+++ b/connectivity/source/drivers/mysql/YViews.cxx
@@ -0,0 +1,162 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_connectivity.hxx"
+#include "mysql/YViews.hxx"
+#include "mysql/YTables.hxx"
+#include <com/sun/star/sdbc/XRow.hpp>
+#include <com/sun/star/sdbc/XResultSet.hpp>
+#include <com/sun/star/sdbc/ColumnValue.hpp>
+#include <com/sun/star/sdbc/KeyRule.hpp>
+#include <com/sun/star/sdbcx/KeyType.hpp>
+#include <com/sun/star/sdbcx/CheckOption.hpp>
+#include "mysql/YCatalog.hxx"
+#include <comphelper/extract.hxx>
+#include "connectivity/dbtools.hxx"
+#include "connectivity/dbexception.hxx"
+#include <cppuhelper/interfacecontainer.h>
+#include "connectivity/sdbcx/VView.hxx"
+#include <comphelper/types.hxx>
+#include "TConnection.hxx"
+
+using namespace ::comphelper;
+
+using namespace ::cppu;
+using namespace connectivity;
+using namespace connectivity::mysql;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::sdbcx;
+using namespace ::com::sun::star::sdbc;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::lang;
+using namespace dbtools;
+typedef connectivity::sdbcx::OCollection OCollection_TYPE;
+
+sdbcx::ObjectType OViews::createObject(const ::rtl::OUString& _rName)
+{
+ ::rtl::OUString sCatalog,sSchema,sTable;
+ ::dbtools::qualifiedNameComponents(m_xMetaData,
+ _rName,
+ sCatalog,
+ sSchema,
+ sTable,
+ ::dbtools::eInDataManipulation);
+ return new ::connectivity::sdbcx::OView(isCaseSensitive(),
+ sTable,
+ m_xMetaData,
+ 0,
+ ::rtl::OUString(),
+ sSchema,
+ sCatalog
+ );
+}
+// -------------------------------------------------------------------------
+void OViews::impl_refresh( ) throw(RuntimeException)
+{
+ static_cast<OMySQLCatalog&>(m_rParent).refreshTables();
+}
+// -------------------------------------------------------------------------
+void OViews::disposing(void)
+{
+m_xMetaData.clear();
+ OCollection::disposing();
+}
+// -------------------------------------------------------------------------
+Reference< XPropertySet > OViews::createDescriptor()
+{
+ Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
+ connectivity::sdbcx::OView* pNew = new connectivity::sdbcx::OView(sal_True,xConnection->getMetaData());
+ return pNew;
+}
+// -------------------------------------------------------------------------
+// XAppend
+sdbcx::ObjectType OViews::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor )
+{
+ createView(descriptor);
+ return createObject( _rForName );
+}
+// -------------------------------------------------------------------------
+// XDrop
+void OViews::dropObject(sal_Int32 _nPos,const ::rtl::OUString /*_sElementName*/)
+{
+ if ( m_bInDrop )
+ return;
+
+ Reference< XInterface > xObject( getObject( _nPos ) );
+ sal_Bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject );
+ if (!bIsNew)
+ {
+ ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("DROP VIEW");
+
+ Reference<XPropertySet> xProp(xObject,UNO_QUERY);
+ aSql += ::dbtools::composeTableName( m_xMetaData, xProp, ::dbtools::eInTableDefinitions, false, false, true );
+
+ Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
+ Reference< XStatement > xStmt = xConnection->createStatement( );
+ xStmt->execute(aSql);
+ ::comphelper::disposeComponent(xStmt);
+ }
+}
+// -----------------------------------------------------------------------------
+void OViews::dropByNameImpl(const ::rtl::OUString& elementName)
+{
+ m_bInDrop = sal_True;
+ OCollection_TYPE::dropByName(elementName);
+ m_bInDrop = sal_False;
+}
+// -----------------------------------------------------------------------------
+void OViews::createView( const Reference< XPropertySet >& descriptor )
+{
+ Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
+
+ ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("CREATE VIEW ");
+ ::rtl::OUString aQuote = xConnection->getMetaData()->getIdentifierQuoteString( );
+ ::rtl::OUString sSchema,sCommand;
+
+ aSql += ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::eInTableDefinitions, false, false, true );
+
+ aSql += ::rtl::OUString::createFromAscii(" AS ");
+ descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND)) >>= sCommand;
+ aSql += sCommand;
+
+ Reference< XStatement > xStmt = xConnection->createStatement( );
+ if ( xStmt.is() )
+ {
+ xStmt->execute(aSql);
+ ::comphelper::disposeComponent(xStmt);
+ }
+
+ // insert the new view also in the tables collection
+ OTables* pTables = static_cast<OTables*>(static_cast<OMySQLCatalog&>(m_rParent).getPrivateTables());
+ if ( pTables )
+ {
+ ::rtl::OUString sName = ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::eInDataManipulation, false, false, false );
+ pTables->appendNew(sName);
+ }
+}
diff --git a/connectivity/source/drivers/mysql/Yservices.cxx b/connectivity/source/drivers/mysql/Yservices.cxx
new file mode 100644
index 000000000000..b892e2f51066
--- /dev/null
+++ b/connectivity/source/drivers/mysql/Yservices.cxx
@@ -0,0 +1,124 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_connectivity.hxx"
+#include "mysql/YDriver.hxx"
+#include <cppuhelper/factory.hxx>
+
+using namespace connectivity::mysql;
+using ::rtl::OUString;
+using ::com::sun::star::uno::Reference;
+using ::com::sun::star::uno::Sequence;
+using ::com::sun::star::lang::XSingleServiceFactory;
+using ::com::sun::star::lang::XMultiServiceFactory;
+
+typedef Reference< XSingleServiceFactory > (SAL_CALL *createFactoryFunc)
+ (
+ const Reference< XMultiServiceFactory > & rServiceManager,
+ const OUString & rComponentName,
+ ::cppu::ComponentInstantiation pCreateFunction,
+ const Sequence< OUString > & rServiceNames,
+ rtl_ModuleCount* _pT
+ );
+
+//---------------------------------------------------------------------------------------
+struct ProviderRequest
+{
+ Reference< XSingleServiceFactory > xRet;
+ Reference< XMultiServiceFactory > const xServiceManager;
+ OUString const sImplementationName;
+
+ ProviderRequest(
+ void* pServiceManager,
+ sal_Char const* pImplementationName
+ )
+ : xServiceManager(reinterpret_cast<XMultiServiceFactory*>(pServiceManager))
+ , sImplementationName(OUString::createFromAscii(pImplementationName))
+ {
+ }
+
+ inline
+ sal_Bool CREATE_PROVIDER(
+ const OUString& Implname,
+ const Sequence< OUString > & Services,
+ ::cppu::ComponentInstantiation Factory,
+ createFactoryFunc creator
+ )
+ {
+ if (!xRet.is() && (Implname == sImplementationName))
+ try
+ {
+ xRet = creator( xServiceManager, sImplementationName,Factory, Services,0);
+ }
+ catch(...)
+ {
+ }
+ return xRet.is();
+ }
+
+ void* getProvider() const { return xRet.get(); }
+};
+
+//---------------------------------------------------------------------------------------
+
+extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL
+component_getImplementationEnvironment(
+ const sal_Char **ppEnvTypeName,
+ uno_Environment ** /*ppEnv*/
+ )
+{
+ *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+}
+
+//---------------------------------------------------------------------------------------
+extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(
+ const sal_Char* pImplementationName,
+ void* pServiceManager,
+ void* /*pRegistryKey*/)
+{
+ void* pRet = 0;
+ if (pServiceManager)
+ {
+ ProviderRequest aReq(pServiceManager,pImplementationName);
+
+ aReq.CREATE_PROVIDER(
+ ODriverDelegator::getImplementationName_Static(),
+ ODriverDelegator::getSupportedServiceNames_Static(),
+ ODriverDelegator_CreateInstance, ::cppu::createSingleFactory)
+ ;
+
+ if(aReq.xRet.is())
+ aReq.xRet->acquire();
+
+ pRet = aReq.getProvider();
+ }
+
+ return pRet;
+};
+
+
diff --git a/connectivity/source/drivers/mysql/exports.dxp b/connectivity/source/drivers/mysql/exports.dxp
new file mode 100644
index 000000000000..f0e1c69934bc
--- /dev/null
+++ b/connectivity/source/drivers/mysql/exports.dxp
@@ -0,0 +1,2 @@
+component_getImplementationEnvironment
+component_getFactory
diff --git a/connectivity/source/drivers/mysql/makefile.mk b/connectivity/source/drivers/mysql/makefile.mk
new file mode 100644
index 000000000000..453f4b652f21
--- /dev/null
+++ b/connectivity/source/drivers/mysql/makefile.mk
@@ -0,0 +1,92 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..$/..
+PRJINC=..$/..
+PRJNAME=connectivity
+TARGET=mysql
+
+ENABLE_EXCEPTIONS=TRUE
+VISIBILITY_HIDDEN=TRUE
+
+# --- Settings ----------------------------------
+.IF "$(DBGUTIL_OJ)"!=""
+ENVCFLAGS+=/FR$(SLO)$/
+.ENDIF
+
+.INCLUDE : $(PRJ)$/makefile.pmk
+.INCLUDE : $(PRJ)$/version.mk
+
+
+# --- Files -------------------------------------
+
+SLOFILES=\
+ $(SLO)$/YDriver.obj \
+ $(SLO)$/YTables.obj \
+ $(SLO)$/YTable.obj \
+ $(SLO)$/YViews.obj \
+ $(SLO)$/YCatalog.obj \
+ $(SLO)$/YColumns.obj \
+ $(SLO)$/YUser.obj \
+ $(SLO)$/YUsers.obj \
+ $(SLO)$/Yservices.obj
+
+SHL1VERSIONMAP=$(SOLARENV)/src/component.map
+
+# --- Library -----------------------------------
+
+SHL1TARGET= $(MYSQL_TARGET)$(DLLPOSTFIX)
+SHL1OBJS=$(SLOFILES)
+SHL1STDLIBS=\
+ $(CPPULIB) \
+ $(CPPUHELPERLIB) \
+ $(SALLIB) \
+ $(DBTOOLSLIB) \
+ $(COMPHELPERLIB)
+
+
+SHL1DEPN=
+SHL1IMPLIB= i$(MYSQL_TARGET)
+
+SHL1DEF= $(MISC)$/$(SHL1TARGET).def
+
+DEF1NAME= $(SHL1TARGET)
+DEF1EXPORTFILE= exports.dxp
+
+# --- Targets ----------------------------------
+
+.INCLUDE : $(PRJ)$/target.pmk
+
+
+
+ALLTAR : $(MISC)/mysql.component
+
+$(MISC)/mysql.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \
+ mysql.component
+ $(XSLTPROC) --nonet --stringparam uri \
+ '$(COMPONENTPREFIX_BASIS_NATIVE)$(SHL1TARGETN:f)' -o $@ \
+ $(SOLARENV)/bin/createcomponent.xslt mysql.component
diff --git a/connectivity/source/drivers/mysql/mysql.component b/connectivity/source/drivers/mysql/mysql.component
new file mode 100644
index 000000000000..ced2297fa07f
--- /dev/null
+++ b/connectivity/source/drivers/mysql/mysql.component
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--**********************************************************************
+*
+* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+*
+* Copyright 2000, 2010 Oracle and/or its affiliates.
+*
+* OpenOffice.org - a multi-platform office productivity suite
+*
+* This file is part of OpenOffice.org.
+*
+* OpenOffice.org is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License version 3
+* only, as published by the Free Software Foundation.
+*
+* OpenOffice.org is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License version 3 for more details
+* (a copy is included in the LICENSE file that accompanied this code).
+*
+* You should have received a copy of the GNU Lesser General Public License
+* version 3 along with OpenOffice.org. If not, see
+* <http://www.openoffice.org/license.html>
+* for a copy of the LGPLv3 License.
+*
+**********************************************************************-->
+
+<component loader="com.sun.star.loader.SharedLibrary"
+ xmlns="http://openoffice.org/2010/uno-components">
+ <implementation name="org.openoffice.comp.drivers.MySQL.Driver">
+ <service name="com.sun.star.sdbc.Driver"/>
+ <service name="com.sun.star.sdbcx.Driver"/>
+ </implementation>
+</component>
diff --git a/connectivity/source/drivers/mysql/mysql.xcu b/connectivity/source/drivers/mysql/mysql.xcu
new file mode 100755
index 000000000000..afc5c0d07f5d
--- /dev/null
+++ b/connectivity/source/drivers/mysql/mysql.xcu
@@ -0,0 +1,258 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--***********************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************ -->
+<oor:component-data oor:name="Drivers" oor:package="org.openoffice.Office.DataAccess" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+ <node oor:name="Installed">
+ <node oor:name="sdbc:mysql:jdbc:*" oor:op="replace">
+ <prop oor:name="Driver">
+ <value>org.openoffice.comp.drivers.MySQL.Driver</value>
+ </prop>
+ <prop oor:name="DriverTypeDisplayName" oor:type="xs:string">
+ <value xml:lang="en-US">MySQL (JDBC)</value>
+ </prop>
+ <node oor:name="Properties">
+ <node oor:name="CharSet" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:string">
+ <value></value>
+ </prop>
+ </node>
+ <node oor:name="JavaDriverClass" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:string">
+ <value>com.mysql.jdbc.Driver</value>
+ </prop>
+ </node>
+ <node oor:name="AddIndexAppendix" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ </node>
+ <node oor:name="Features">
+ <node oor:name="UseKeywordAsBeforeAlias" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="IgnoreDriverPrivileges" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="DisplayVersionColumns" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="UseDOSLineEnds" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="BooleanComparisonMode" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="FormsCheckRequiredFields" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ </node>
+ <node oor:name="MetaData">
+ <node oor:name="SupportsTableCreation" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="UseJava" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="Authentication" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:string">
+ <value>UserPassword</value>
+ </prop>
+ </node>
+ <node oor:name="SupportsColumnDescription" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ </node>
+ </node>
+ <node oor:name="sdbc:mysql:odbc:*" oor:op="replace">
+ <prop oor:name="Driver">
+ <value>org.openoffice.comp.drivers.MySQL.Driver</value>
+ </prop>
+ <prop oor:name="DriverTypeDisplayName" oor:type="xs:string">
+ <value xml:lang="en-US">MySQL (ODBC)</value>
+ </prop>
+ <node oor:name="Properties">
+ <node oor:name="CharSet" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:string">
+ <value></value>
+ </prop>
+ </node>
+ <node oor:name="AddIndexAppendix" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ </node>
+ <node oor:name="Features">
+ <node oor:name="UseKeywordAsBeforeAlias" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="IgnoreDriverPrivileges" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="DisplayVersionColumns" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="UseDOSLineEnds" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="BooleanComparisonMode" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="FormsCheckRequiredFields" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ </node>
+ <node oor:name="MetaData">
+ <node oor:name="SupportsTableCreation" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="SupportsBrowsing" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="Authentication" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:string">
+ <value>UserPassword</value>
+ </prop>
+ </node>
+ </node>
+ </node>
+ <node oor:name="sdbc:mysql:mysqlc:*" oor:op="replace">
+ <prop oor:name="Driver">
+ <value>org.openoffice.comp.drivers.MySQL.Driver</value>
+ </prop>
+ <prop oor:name="DriverTypeDisplayName" oor:type="xs:string">
+ <value xml:lang="en-US">MySQL (Native)</value>
+ </prop>
+ <node oor:name="Properties">
+ <node oor:name="CharSet" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:string">
+ <value></value>
+ </prop>
+ </node>
+ <node oor:name="LocalSocket" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:string">
+ <value></value>
+ </prop>
+ </node>
+ <node oor:name="NamedPipe" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:string">
+ <value></value>
+ </prop>
+ </node>
+ <node oor:name="AddIndexAppendix" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ </node>
+ <node oor:name="Features">
+ <node oor:name="UseKeywordAsBeforeAlias" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="IgnoreDriverPrivileges" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="DisplayVersionColumns" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="UseDOSLineEnds" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="BooleanComparisonMode" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="FormsCheckRequiredFields" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ </node>
+ <node oor:name="MetaData">
+ <node oor:name="SupportsTableCreation" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ <node oor:name="Authentication" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:string">
+ <value>UserPassword</value>
+ </prop>
+ </node>
+ <node oor:name="SupportsColumnDescription" oor:op="replace">
+ <prop oor:name="Value" oor:type="xs:boolean">
+ <value>true</value>
+ </prop>
+ </node>
+ </node>
+ </node>
+ </node>
+</oor:component-data>
diff --git a/connectivity/source/drivers/mysql/mysql.xml b/connectivity/source/drivers/mysql/mysql.xml
new file mode 100644
index 000000000000..22ab9d7c79b5
--- /dev/null
+++ b/connectivity/source/drivers/mysql/mysql.xml
@@ -0,0 +1,29 @@
+<?xml version='1.0' encoding="UTF-8"?>
+<!DOCTYPE module-description PUBLIC "-//W3C//DTD HTML 3.2//EN" "module-description.dtd">
+<module-description xmlns:xlink="http://www.w3.org/1999/xlink">
+ <module-name>odbc</module-name>
+ <component-description>
+ <author>Ocke Janssen</author>
+ <name>org.openoffice.comp.drivers.MySQL.Driver</name>
+ <description>
+ This is the implementation of the MySQL driver.
+ </description>
+ <loader-name>com.sun.star.loader.SharedLibrary</loader-name>
+ <language>c++</language>
+ <status value="final"/>
+ <supported-service>com.sun.star.sdbc.Driver</supported-service>
+ <supported-service>com.sun.star.sdbcx.Driver</supported-service>
+ </component-description>
+ <project-build-dependency>cppuhelper</project-build-dependency>
+ <project-build-dependency>cppu</project-build-dependency>
+ <project-build-dependency>sal</project-build-dependency>
+ <project-build-dependency>vos</project-build-dependency>
+ <runtime-module-dependency>cppuhelper</runtime-module-dependency>
+ <runtime-module-dependency>cppu</runtime-module-dependency>
+ <runtime-module-dependency>sal</runtime-module-dependency>
+ <runtime-module-dependency>vos</runtime-module-dependency>
+ <runtime-module-dependency>dbtools</runtime-module-dependency>
+ <runtime-module-dependency>comphelper</runtime-module-dependency>
+</module-description>
+
+