1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
28 using namespace connectivity
;
29 using namespace connectivity::mysql
;
30 using namespace connectivity::sdbcx
;
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::beans
;
33 using namespace ::com::sun::star::sdbcx
;
34 using namespace ::com::sun::star::sdbc
;
35 using namespace ::com::sun::star::container
;
36 using namespace ::com::sun::star::lang
;
38 OMySQLCatalog::OMySQLCatalog(const Reference
<XConnection
>& _xConnection
)
39 : OCatalog(_xConnection
)
40 , m_xConnection(_xConnection
)
44 void OMySQLCatalog::refreshObjects(const Sequence
<OUString
>& _sKindOfObject
,
45 ::std::vector
<OUString
>& _rNames
)
47 Reference
<XResultSet
> xResult
= m_xMetaData
->getTables(Any(), "%", "%", _sKindOfObject
);
48 fillNames(xResult
, _rNames
);
51 void OMySQLCatalog::refreshTables()
53 ::std::vector
<OUString
> aVector
;
55 Sequence
<OUString
> sTableTypes
{
57 }; // this last one just to be sure to include anything else...
59 refreshObjects(sTableTypes
, aVector
);
62 m_pTables
->reFill(aVector
);
64 m_pTables
.reset(new OTables(m_xMetaData
, *this, m_aMutex
, aVector
));
67 void OMySQLCatalog::refreshViews()
69 Sequence
<OUString
> aTypes
{ "VIEW" };
71 // let's simply assume the server is new enough to support views. Current drivers
72 // as of this writing might not return the proper information in getTableTypes, so
75 ::std::vector
<OUString
> aVector
;
76 refreshObjects(aTypes
, aVector
);
79 m_pViews
->reFill(aVector
);
81 m_pViews
.reset(new OViews(m_xMetaData
, *this, m_aMutex
, aVector
));
84 void OMySQLCatalog::refreshGroups() {}
86 void OMySQLCatalog::refreshUsers()
88 ::std::vector
<OUString
> aVector
;
89 Reference
<XStatement
> xStmt
= m_xConnection
->createStatement();
90 Reference
<XResultSet
> xResult
= xStmt
->executeQuery(
91 "SELECT grantee FROM information_schema.user_privileges GROUP BY grantee");
94 Reference
<XRow
> xRow(xResult
, UNO_QUERY
);
95 while (xResult
->next())
96 aVector
.push_back(xRow
->getString(1));
97 ::comphelper::disposeComponent(xResult
);
99 ::comphelper::disposeComponent(xStmt
);
102 m_pUsers
->reFill(aVector
);
104 m_pUsers
.reset(new OUsers(*this, m_aMutex
, aVector
, m_xConnection
, this));
107 Any SAL_CALL
OMySQLCatalog::queryInterface(const Type
& rType
)
109 if (rType
== cppu::UnoType
<XGroupsSupplier
>::get())
112 return OCatalog::queryInterface(rType
);
115 Sequence
<Type
> SAL_CALL
OMySQLCatalog::getTypes()
117 Sequence
<Type
> aTypes
= OCatalog::getTypes();
118 std::vector
<Type
> aOwnTypes
;
119 aOwnTypes
.reserve(aTypes
.getLength());
120 const Type
* pBegin
= aTypes
.getConstArray();
121 const Type
* pEnd
= pBegin
+ aTypes
.getLength();
122 for (; pBegin
!= pEnd
; ++pBegin
)
124 if (*pBegin
!= cppu::UnoType
<XGroupsSupplier
>::get())
126 aOwnTypes
.push_back(*pBegin
);
129 return Sequence
<Type
>(aOwnTypes
.data(), aOwnTypes
.size());
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */