tdf#144694 In direct SQL dialog, activate options 'Run SQL command
[LibreOffice.git] / connectivity / source / drivers / mysql_jdbc / YCatalog.cxx
blob7f4b0232e0c861fea33bf53785b55d9d446dc0e6
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>
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::sdbcx;
33 using namespace ::com::sun::star::sdbc;
35 OMySQLCatalog::OMySQLCatalog(const Reference<XConnection>& _xConnection)
36 : OCatalog(_xConnection)
37 , m_xConnection(_xConnection)
41 void OMySQLCatalog::refreshObjects(const Sequence<OUString>& _sKindOfObject,
42 ::std::vector<OUString>& _rNames)
44 Reference<XResultSet> xResult
45 = m_xMetaData->getTables(Any(), u"%"_ustr, u"%"_ustr, _sKindOfObject);
46 fillNames(xResult, _rNames);
49 void OMySQLCatalog::refreshTables()
51 ::std::vector<OUString> aVector;
53 Sequence<OUString> sTableTypes{
54 u"VIEW"_ustr, u"TABLE"_ustr, u"%"_ustr
55 }; // this last one just to be sure to include anything else...
57 refreshObjects(sTableTypes, aVector);
59 if (m_pTables)
60 m_pTables->reFill(aVector);
61 else
62 m_pTables.reset(new OTables(m_xMetaData, *this, m_aMutex, aVector));
65 void OMySQLCatalog::refreshViews()
67 Sequence<OUString> aTypes{ u"VIEW"_ustr };
69 // let's simply assume the server is new enough to support views. Current drivers
70 // as of this writing might not return the proper information in getTableTypes, so
71 // don't rely on it.
73 ::std::vector<OUString> aVector;
74 refreshObjects(aTypes, aVector);
76 if (m_pViews)
77 m_pViews->reFill(aVector);
78 else
79 m_pViews.reset(new OViews(m_xMetaData, *this, m_aMutex, aVector));
82 void OMySQLCatalog::refreshGroups() {}
84 void OMySQLCatalog::refreshUsers()
86 ::std::vector<OUString> aVector;
87 Reference<XStatement> xStmt = m_xConnection->createStatement();
88 Reference<XResultSet> xResult = xStmt->executeQuery(
89 u"SELECT grantee FROM information_schema.user_privileges GROUP BY grantee"_ustr);
90 if (xResult.is())
92 Reference<XRow> xRow(xResult, UNO_QUERY);
93 while (xResult->next())
94 aVector.push_back(xRow->getString(1));
95 ::comphelper::disposeComponent(xResult);
97 ::comphelper::disposeComponent(xStmt);
99 if (m_pUsers)
100 m_pUsers->reFill(aVector);
101 else
102 m_pUsers.reset(new OUsers(*this, m_aMutex, aVector, m_xConnection, this));
105 Any SAL_CALL OMySQLCatalog::queryInterface(const Type& rType)
107 if (rType == cppu::UnoType<XGroupsSupplier>::get())
108 return Any();
110 return OCatalog::queryInterface(rType);
113 Sequence<Type> SAL_CALL OMySQLCatalog::getTypes()
115 Sequence<Type> aTypes = OCatalog::getTypes();
116 std::vector<Type> aOwnTypes;
117 aOwnTypes.reserve(aTypes.getLength());
118 const Type* pBegin = aTypes.getConstArray();
119 const Type* pEnd = pBegin + aTypes.getLength();
120 for (; pBegin != pEnd; ++pBegin)
122 if (*pBegin != cppu::UnoType<XGroupsSupplier>::get())
124 aOwnTypes.push_back(*pBegin);
127 return Sequence<Type>(aOwnTypes.data(), aOwnTypes.size());
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */