Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / mysql / YCatalog.cxx
blob5510faec00502ada07b275c7fe78aafb3181a9cb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "mysql/YCatalog.hxx"
21 #include "mysql/YUsers.hxx"
22 #include "mysql/YTables.hxx"
23 #include "mysql/YViews.hxx"
24 #include <com/sun/star/sdbc/XRow.hpp>
25 #include <com/sun/star/sdbc/XResultSet.hpp>
26 #include <comphelper/types.hxx>
30 using namespace connectivity;
31 using namespace connectivity::mysql;
32 using namespace connectivity::sdbcx;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::sdbcx;
36 using namespace ::com::sun::star::sdbc;
37 using namespace ::com::sun::star::container;
38 using namespace ::com::sun::star::lang;
40 OMySQLCatalog::OMySQLCatalog(const Reference< XConnection >& _xConnection) : OCatalog(_xConnection)
41 ,m_xConnection(_xConnection)
45 void OMySQLCatalog::refreshObjects(const Sequence< OUString >& _sKindOfObject,TStringVector& _rNames)
47 Reference< XResultSet > xResult = m_xMetaData->getTables(Any(),
48 OUString("%"),
49 OUString("%"),
50 _sKindOfObject);
51 fillNames(xResult,_rNames);
54 void OMySQLCatalog::refreshTables()
56 TStringVector aVector;
57 static const OUString s_sTableTypeView("VIEW");
58 static const OUString s_sTableTypeTable("TABLE");
59 static const OUString s_sAll("%");
61 Sequence< OUString > sTableTypes(3);
62 sTableTypes[0] = s_sTableTypeView;
63 sTableTypes[1] = s_sTableTypeTable;
64 sTableTypes[2] = s_sAll; // just to be sure to include anything else ....
66 refreshObjects(sTableTypes,aVector);
68 if ( m_pTables )
69 m_pTables->reFill(aVector);
70 else
71 m_pTables = new OTables(m_xMetaData,*this,m_aMutex,aVector);
74 void OMySQLCatalog::refreshViews()
76 Sequence< OUString > aTypes(1);
77 aTypes[0] = "VIEW";
79 // let's simply assume the server is new enough to support views. Current drivers
80 // as of this writing might not return the proper information in getTableTypes, so
81 // don't rely on it.
82 // during #73245# / 2007-10-26 / frank.schoenheit@sun.com
83 bool bSupportsViews = true;
85 TStringVector aVector;
86 if ( bSupportsViews )
87 refreshObjects(aTypes,aVector);
89 if ( m_pViews )
90 m_pViews->reFill(aVector);
91 else
92 m_pViews = new OViews(m_xMetaData,*this,m_aMutex,aVector);
95 void OMySQLCatalog::refreshGroups()
99 void OMySQLCatalog::refreshUsers()
101 TStringVector aVector;
102 Reference< XStatement > xStmt = m_xConnection->createStatement( );
103 Reference< XResultSet > xResult = xStmt->executeQuery(OUString("SELECT grantee FROM information_schema.user_privileges GROUP BY grantee"));
104 if ( xResult.is() )
106 Reference< XRow > xRow(xResult,UNO_QUERY);
107 TString2IntMap aMap;
108 while( xResult->next() )
109 aVector.push_back(xRow->getString(1));
110 ::comphelper::disposeComponent(xResult);
112 ::comphelper::disposeComponent(xStmt);
114 if(m_pUsers)
115 m_pUsers->reFill(aVector);
116 else
117 m_pUsers = new OUsers(*this,m_aMutex,aVector,m_xConnection,this);
120 Any SAL_CALL OMySQLCatalog::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
122 if ( rType == ::getCppuType((const Reference<XGroupsSupplier>*)0) )
123 return Any();
126 return OCatalog::queryInterface(rType);
129 Sequence< Type > SAL_CALL OMySQLCatalog::getTypes( ) throw(RuntimeException, std::exception)
131 Sequence< Type > aTypes = OCatalog::getTypes();
132 ::std::vector<Type> aOwnTypes;
133 aOwnTypes.reserve(aTypes.getLength());
134 const Type* pBegin = aTypes.getConstArray();
135 const Type* pEnd = pBegin + aTypes.getLength();
136 for(;pBegin != pEnd;++pBegin)
138 if ( !(*pBegin == ::getCppuType((const Reference<XGroupsSupplier>*)0)))
140 aOwnTypes.push_back(*pBegin);
143 const Type* pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
144 return Sequence< Type >(pTypes, aOwnTypes.size());
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */