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/YUsers.hxx>
21 #include <mysql/YUser.hxx>
22 #include <connectivity/sdbcx/IRefreshable.hxx>
23 #include <comphelper/types.hxx>
24 #include <connectivity/dbtools.hxx>
25 #include <TConnection.hxx>
28 using namespace ::comphelper
;
29 using namespace connectivity
;
30 using namespace connectivity::mysql
;
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::beans
;
33 using namespace ::com::sun::star::sdbc
;
35 OUsers::OUsers(::cppu::OWeakObject
& _rParent
, ::osl::Mutex
& _rMutex
,
36 const ::std::vector
<OUString
>& _rVector
,
37 css::uno::Reference
<css::sdbc::XConnection
> _xConnection
,
38 connectivity::sdbcx::IRefreshableUsers
* _pParent
)
39 : sdbcx::OCollection(_rParent
, true, _rMutex
, _rVector
)
40 , m_xConnection(std::move(_xConnection
))
45 sdbcx::ObjectType
OUsers::createObject(const OUString
& _rName
)
47 return new OMySQLUser(m_xConnection
, _rName
);
50 void OUsers::impl_refresh() { m_pParent
->refreshUsers(); }
52 Reference
<XPropertySet
> OUsers::createDescriptor() { return new OUserExtend(m_xConnection
); }
55 sdbcx::ObjectType
OUsers::appendObject(const OUString
& _rForName
,
56 const Reference
<XPropertySet
>& descriptor
)
58 OUString
aSql(u
"GRANT USAGE ON * TO "_ustr
);
59 OUString aQuote
= m_xConnection
->getMetaData()->getIdentifierQuoteString();
60 aSql
+= ::dbtools::quoteName(aQuote
, _rForName
) + " @\"%\" ";
62 descriptor
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD
))
64 if (!sPassword
.isEmpty())
66 aSql
+= " IDENTIFIED BY '" + sPassword
+ "'";
69 Reference
<XStatement
> xStmt
= m_xConnection
->createStatement();
72 ::comphelper::disposeComponent(xStmt
);
74 return createObject(_rForName
);
78 void OUsers::dropObject(sal_Int32
/*_nPos*/, const OUString
& _sElementName
)
80 OUString
aSql(u
"DROP USER "_ustr
);
81 OUString aQuote
= m_xConnection
->getMetaData()->getIdentifierQuoteString();
82 aSql
+= ::dbtools::quoteName(aQuote
, _sElementName
);
84 Reference
<XStatement
> xStmt
= m_xConnection
->createStatement();
87 ::comphelper::disposeComponent(xStmt
);
90 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */