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