1*9b5730f6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9b5730f6SAndrew Rist * distributed with this work for additional information 6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance 9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an 15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the 17*9b5730f6SAndrew Rist * specific language governing permissions and limitations 18*9b5730f6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9b5730f6SAndrew Rist *************************************************************/ 21*9b5730f6SAndrew Rist 22*9b5730f6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 26cdf0e10cSrcweir #include "mysql/YCatalog.hxx" 27cdf0e10cSrcweir #include "mysql/YUsers.hxx" 28cdf0e10cSrcweir #include "mysql/YTables.hxx" 29cdf0e10cSrcweir #include "mysql/YViews.hxx" 30cdf0e10cSrcweir #include <com/sun/star/sdbc/XRow.hpp> 31cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp> 32cdf0e10cSrcweir #include <comphelper/types.hxx> 33cdf0e10cSrcweir 34cdf0e10cSrcweir 35cdf0e10cSrcweir // ------------------------------------------------------------------------- 36cdf0e10cSrcweir using namespace connectivity; 37cdf0e10cSrcweir using namespace connectivity::mysql; 38cdf0e10cSrcweir using namespace connectivity::sdbcx; 39cdf0e10cSrcweir using namespace ::com::sun::star::uno; 40cdf0e10cSrcweir using namespace ::com::sun::star::beans; 41cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 42cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 43cdf0e10cSrcweir using namespace ::com::sun::star::container; 44cdf0e10cSrcweir using namespace ::com::sun::star::lang; 45cdf0e10cSrcweir // ------------------------------------------------------------------------- 46cdf0e10cSrcweir OMySQLCatalog::OMySQLCatalog(const Reference< XConnection >& _xConnection) : OCatalog(_xConnection) 47cdf0e10cSrcweir ,m_xConnection(_xConnection) 48cdf0e10cSrcweir { 49cdf0e10cSrcweir } 50cdf0e10cSrcweir // ----------------------------------------------------------------------------- 51cdf0e10cSrcweir void OMySQLCatalog::refreshObjects(const Sequence< ::rtl::OUString >& _sKindOfObject,TStringVector& _rNames) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir Reference< XResultSet > xResult = m_xMetaData->getTables(Any(), 54cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")), 55cdf0e10cSrcweir ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")), 56cdf0e10cSrcweir _sKindOfObject); 57cdf0e10cSrcweir fillNames(xResult,_rNames); 58cdf0e10cSrcweir } 59cdf0e10cSrcweir // ------------------------------------------------------------------------- 60cdf0e10cSrcweir void OMySQLCatalog::refreshTables() 61cdf0e10cSrcweir { 62cdf0e10cSrcweir TStringVector aVector; 63cdf0e10cSrcweir static const ::rtl::OUString s_sTableTypeView(RTL_CONSTASCII_USTRINGPARAM("VIEW")); 64cdf0e10cSrcweir static const ::rtl::OUString s_sTableTypeTable(RTL_CONSTASCII_USTRINGPARAM("TABLE")); 65cdf0e10cSrcweir static const ::rtl::OUString s_sAll(RTL_CONSTASCII_USTRINGPARAM("%")); 66cdf0e10cSrcweir 67cdf0e10cSrcweir Sequence< ::rtl::OUString > sTableTypes(3); 68cdf0e10cSrcweir sTableTypes[0] = s_sTableTypeView; 69cdf0e10cSrcweir sTableTypes[1] = s_sTableTypeTable; 70cdf0e10cSrcweir sTableTypes[2] = s_sAll; // just to be sure to include anything else .... 71cdf0e10cSrcweir 72cdf0e10cSrcweir refreshObjects(sTableTypes,aVector); 73cdf0e10cSrcweir 74cdf0e10cSrcweir if ( m_pTables ) 75cdf0e10cSrcweir m_pTables->reFill(aVector); 76cdf0e10cSrcweir else 77cdf0e10cSrcweir m_pTables = new OTables(m_xMetaData,*this,m_aMutex,aVector); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir // ------------------------------------------------------------------------- 80cdf0e10cSrcweir void OMySQLCatalog::refreshViews() 81cdf0e10cSrcweir { 82cdf0e10cSrcweir Sequence< ::rtl::OUString > aTypes(1); 83cdf0e10cSrcweir aTypes[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("VIEW")); 84cdf0e10cSrcweir 85cdf0e10cSrcweir /* 86cdf0e10cSrcweir sal_Bool bSupportsViews = sal_False; 87cdf0e10cSrcweir try 88cdf0e10cSrcweir { 89cdf0e10cSrcweir Reference<XResultSet> xRes = m_xMetaData->getTableTypes(); 90cdf0e10cSrcweir Reference<XRow> xRow(xRes,UNO_QUERY); 91cdf0e10cSrcweir while ( !bSupportsViews && xRow.is() && xRes->next() ) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir ::rtl::OUString sTableType( xRow->getString( 1 ) ); 94cdf0e10cSrcweir bSupportsViews = sTableType.equalsIgnoreAsciiCase( aTypes[0] ); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir } 97cdf0e10cSrcweir catch(const SQLException&) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir } 100cdf0e10cSrcweir */ 101cdf0e10cSrcweir // let's simply assume the server is new enough to support views. Current drivers 102cdf0e10cSrcweir // as of this writing might not return the proper information in getTableTypes, so 103cdf0e10cSrcweir // don't rely on it. 104cdf0e10cSrcweir // during #73245# / 2007-10-26 / frank.schoenheit@sun.com 105cdf0e10cSrcweir bool bSupportsViews = sal_True; 106cdf0e10cSrcweir 107cdf0e10cSrcweir TStringVector aVector; 108cdf0e10cSrcweir if ( bSupportsViews ) 109cdf0e10cSrcweir refreshObjects(aTypes,aVector); 110cdf0e10cSrcweir 111cdf0e10cSrcweir if ( m_pViews ) 112cdf0e10cSrcweir m_pViews->reFill(aVector); 113cdf0e10cSrcweir else 114cdf0e10cSrcweir m_pViews = new OViews(m_xMetaData,*this,m_aMutex,aVector); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir // ------------------------------------------------------------------------- 117cdf0e10cSrcweir void OMySQLCatalog::refreshGroups() 118cdf0e10cSrcweir { 119cdf0e10cSrcweir } 120cdf0e10cSrcweir // ------------------------------------------------------------------------- 121cdf0e10cSrcweir void OMySQLCatalog::refreshUsers() 122cdf0e10cSrcweir { 123cdf0e10cSrcweir TStringVector aVector; 124cdf0e10cSrcweir Reference< XStatement > xStmt = m_xConnection->createStatement( ); 125cdf0e10cSrcweir Reference< XResultSet > xResult = xStmt->executeQuery(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("select User from mysql.user group by User"))); 126cdf0e10cSrcweir if ( xResult.is() ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir Reference< XRow > xRow(xResult,UNO_QUERY); 129cdf0e10cSrcweir TString2IntMap aMap; 130cdf0e10cSrcweir while( xResult->next() ) 131cdf0e10cSrcweir aVector.push_back(xRow->getString(1)); 132cdf0e10cSrcweir ::comphelper::disposeComponent(xResult); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir ::comphelper::disposeComponent(xStmt); 135cdf0e10cSrcweir 136cdf0e10cSrcweir if(m_pUsers) 137cdf0e10cSrcweir m_pUsers->reFill(aVector); 138cdf0e10cSrcweir else 139cdf0e10cSrcweir m_pUsers = new OUsers(*this,m_aMutex,aVector,m_xConnection,this); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir // ----------------------------------------------------------------------------- 142cdf0e10cSrcweir Any SAL_CALL OMySQLCatalog::queryInterface( const Type & rType ) throw(RuntimeException) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir if ( rType == ::getCppuType((const Reference<XGroupsSupplier>*)0) ) 145cdf0e10cSrcweir return Any(); 146cdf0e10cSrcweir 147cdf0e10cSrcweir 148cdf0e10cSrcweir return OCatalog::queryInterface(rType); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir // ----------------------------------------------------------------------------- 151cdf0e10cSrcweir Sequence< Type > SAL_CALL OMySQLCatalog::getTypes( ) throw(RuntimeException) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir Sequence< Type > aTypes = OCatalog::getTypes(); 154cdf0e10cSrcweir ::std::vector<Type> aOwnTypes; 155cdf0e10cSrcweir aOwnTypes.reserve(aTypes.getLength()); 156cdf0e10cSrcweir const Type* pBegin = aTypes.getConstArray(); 157cdf0e10cSrcweir const Type* pEnd = pBegin + aTypes.getLength(); 158cdf0e10cSrcweir for(;pBegin != pEnd;++pBegin) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir if ( !(*pBegin == ::getCppuType((const Reference<XGroupsSupplier>*)0))) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir aOwnTypes.push_back(*pBegin); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir } 165cdf0e10cSrcweir const Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0]; 166cdf0e10cSrcweir return Sequence< Type >(pTypes, aOwnTypes.size()); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir // ----------------------------------------------------------------------------- 169cdf0e10cSrcweir 170cdf0e10cSrcweir 171