2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-12 22:04:38 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2002-11-11 07:30:50 +00:00
|
|
|
|
|
|
|
#include "mysql/YUsers.hxx"
|
|
|
|
#include "mysql/YUser.hxx"
|
|
|
|
#include "mysql/YTable.hxx"
|
|
|
|
#include <com/sun/star/sdbc/XRow.hpp>
|
|
|
|
#include <com/sun/star/sdbc/XResultSet.hpp>
|
2014-06-04 15:29:58 +02:00
|
|
|
#include <connectivity/sdbcx/IRefreshable.hxx>
|
2002-11-11 07:30:50 +00:00
|
|
|
#include <comphelper/types.hxx>
|
2014-06-04 15:29:58 +02:00
|
|
|
#include <connectivity/dbexception.hxx>
|
|
|
|
#include <connectivity/dbtools.hxx>
|
2002-11-11 07:30:50 +00:00
|
|
|
#include "TConnection.hxx"
|
|
|
|
|
|
|
|
using namespace ::comphelper;
|
|
|
|
using namespace connectivity;
|
|
|
|
using namespace connectivity::mysql;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::com::sun::star::beans;
|
|
|
|
using namespace ::com::sun::star::sdbc;
|
|
|
|
using namespace ::com::sun::star::container;
|
|
|
|
using namespace ::com::sun::star::lang;
|
|
|
|
|
|
|
|
OUsers::OUsers( ::cppu::OWeakObject& _rParent,
|
|
|
|
::osl::Mutex& _rMutex,
|
|
|
|
const TStringVector &_rVector,
|
|
|
|
const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection,
|
|
|
|
connectivity::sdbcx::IRefreshableUsers* _pParent)
|
2014-03-31 17:30:06 +02:00
|
|
|
: sdbcx::OCollection(_rParent, true, _rMutex, _rVector)
|
2002-11-11 07:30:50 +00:00
|
|
|
,m_xConnection(_xConnection)
|
|
|
|
,m_pParent(_pParent)
|
|
|
|
{
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2002-11-11 07:30:50 +00:00
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
sdbcx::ObjectType OUsers::createObject(const OUString& _rName)
|
2002-11-11 07:30:50 +00:00
|
|
|
{
|
|
|
|
return new OMySQLUser(m_xConnection,_rName);
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2002-11-11 07:30:50 +00:00
|
|
|
void OUsers::impl_refresh() throw(RuntimeException)
|
|
|
|
{
|
|
|
|
m_pParent->refreshUsers();
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2006-07-10 13:31:02 +00:00
|
|
|
Reference< XPropertySet > OUsers::createDescriptor()
|
2002-11-11 07:30:50 +00:00
|
|
|
{
|
|
|
|
OUserExtend* pNew = new OUserExtend(m_xConnection);
|
|
|
|
return pNew;
|
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2002-11-11 07:30:50 +00:00
|
|
|
// XAppend
|
2013-04-07 12:06:47 +02:00
|
|
|
sdbcx::ObjectType OUsers::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
|
2002-11-11 07:30:50 +00:00
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString aSql( "GRANT USAGE ON * TO " );
|
|
|
|
OUString aQuote = m_xConnection->getMetaData()->getIdentifierQuoteString( );
|
|
|
|
OUString sUserName( _rForName );
|
2002-11-11 07:30:50 +00:00
|
|
|
aSql += ::dbtools::quoteName(aQuote,sUserName)
|
2013-12-13 09:29:22 +02:00
|
|
|
+ " @\"%\" ";
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString sPassword;
|
2002-11-11 07:30:50 +00:00
|
|
|
descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD)) >>= sPassword;
|
2011-12-14 23:13:36 -02:00
|
|
|
if ( !sPassword.isEmpty() )
|
2002-11-11 07:30:50 +00:00
|
|
|
{
|
2013-10-25 17:17:50 +02:00
|
|
|
aSql += " IDENTIFIED BY '";
|
2002-11-11 07:30:50 +00:00
|
|
|
aSql += sPassword;
|
2013-10-25 17:17:50 +02:00
|
|
|
aSql += "'";
|
2002-11-11 07:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Reference< XStatement > xStmt = m_xConnection->createStatement( );
|
|
|
|
if(xStmt.is())
|
|
|
|
xStmt->execute(aSql);
|
|
|
|
::comphelper::disposeComponent(xStmt);
|
2006-07-10 13:31:02 +00:00
|
|
|
|
|
|
|
return createObject( _rForName );
|
2002-11-11 07:30:50 +00:00
|
|
|
}
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2002-11-11 07:30:50 +00:00
|
|
|
// XDrop
|
2014-03-14 07:46:08 +02:00
|
|
|
void OUsers::dropObject(sal_Int32 /*_nPos*/,const OUString& _sElementName)
|
2002-11-11 07:30:50 +00:00
|
|
|
{
|
2013-12-22 12:34:04 +01:00
|
|
|
OUString aSql( "DROP USER " );
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString aQuote = m_xConnection->getMetaData()->getIdentifierQuoteString( );
|
2006-06-20 00:53:53 +00:00
|
|
|
aSql += ::dbtools::quoteName(aQuote,_sElementName);
|
2002-11-11 07:30:50 +00:00
|
|
|
|
2006-06-20 00:53:53 +00:00
|
|
|
Reference< XStatement > xStmt = m_xConnection->createStatement( );
|
|
|
|
if(xStmt.is())
|
|
|
|
xStmt->execute(aSql);
|
|
|
|
::comphelper::disposeComponent(xStmt);
|
2002-11-11 07:30:50 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 21:20:15 +01:00
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|