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>
27 using namespace ::comphelper
;
28 using namespace connectivity
;
29 using namespace connectivity::mysql
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::beans
;
32 using namespace ::com::sun::star::sdbc
;
33 using namespace ::com::sun::star::container
;
34 using namespace ::com::sun::star::lang
;
36 OUsers::OUsers(::cppu::OWeakObject
& _rParent
, ::osl::Mutex
& _rMutex
,
37 const ::std::vector
<OUString
>& _rVector
,
38 const css::uno::Reference
<css::sdbc::XConnection
>& _xConnection
,
39 connectivity::sdbcx::IRefreshableUsers
* _pParent
)
40 : sdbcx::OCollection(_rParent
, true, _rMutex
, _rVector
)
41 , m_xConnection(_xConnection
)
46 sdbcx::ObjectType
OUsers::createObject(const OUString
& _rName
)
48 return new OMySQLUser(m_xConnection
, _rName
);
51 void OUsers::impl_refresh() { m_pParent
->refreshUsers(); }
53 Reference
<XPropertySet
> OUsers::createDescriptor() { return new OUserExtend(m_xConnection
); }
56 sdbcx::ObjectType
OUsers::appendObject(const OUString
& _rForName
,
57 const Reference
<XPropertySet
>& descriptor
)
59 OUString
aSql("GRANT USAGE ON * TO ");
60 OUString aQuote
= m_xConnection
->getMetaData()->getIdentifierQuoteString();
61 aSql
+= ::dbtools::quoteName(aQuote
, _rForName
) + " @\"%\" ";
63 descriptor
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD
))
65 if (!sPassword
.isEmpty())
67 aSql
+= " IDENTIFIED BY '" + sPassword
+ "'";
70 Reference
<XStatement
> xStmt
= m_xConnection
->createStatement();
73 ::comphelper::disposeComponent(xStmt
);
75 return createObject(_rForName
);
79 void OUsers::dropObject(sal_Int32
/*_nPos*/, const OUString
& _sElementName
)
81 OUString
aSql("DROP USER ");
82 OUString aQuote
= m_xConnection
->getMetaData()->getIdentifierQuoteString();
83 aSql
+= ::dbtools::quoteName(aQuote
, _sElementName
);
85 Reference
<XStatement
> xStmt
= m_xConnection
->createStatement();
88 ::comphelper::disposeComponent(xStmt
);
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */