20#include <core_resource.hxx>
22#include <osl/diagnose.h>
23#include <com/sun/star/sdbc/XWarningsSupplier.hpp>
24#include <com/sun/star/beans/XPropertySet.hpp>
25#include <com/sun/star/sdb/XCompletedConnection.hpp>
26#include <com/sun/star/task/InteractionHandler.hpp>
27#include <com/sun/star/frame/XModel.hpp>
28#include <com/sun/star/sdbc/SQLWarning.hpp>
31#include <com/sun/star/sdbc/XDataSource.hpp>
58 :m_pErrorMessageParent(_pMessageParent)
63 ODatasourceConnector::ODatasourceConnector(
const Reference< XComponentContext >& _rxContext,
weld::Window* _pMessageParent,
64 OUString _sContextInformation )
65 :m_pErrorMessageParent(_pMessageParent)
67 ,m_sContextInformation(
std::move( _sContextInformation ))
76 OSL_ENSURE(isValid(),
"ODatasourceConnector::connect: invalid object!");
84 if ( xDatasource.is() )
85 xConnection = connect( xDatasource, _pErrorInfo );
94 OSL_ENSURE( isValid() && _xDataSource.is(),
"ODatasourceConnector::connect: invalid object or argument!" );
95 if ( !isValid() || !_xDataSource.is() )
99 OUString sPassword, sUser;
100 bool bPwdRequired =
false;
114 SQLExceptionInfo aInfo;
117 if (bPwdRequired && sPassword.isEmpty())
119 Reference< XCompletedConnection > xConnectionCompletion( _xDataSource, UNO_QUERY_THROW );
123 Reference< XInteractionHandler > xHandler( aArgs.getOrDefault(
"InteractionHandler", Reference< XInteractionHandler >() ) );
125 if ( !xHandler.is() )
128 xHandler = InteractionHandler::createWithParent(
m_xContext, m_pErrorMessageParent ? m_pErrorMessageParent->GetXWindow() :
nullptr);
131 xConnection = xConnectionCompletion->connectWithCompletion(xHandler);
135 xConnection = _xDataSource->getConnection(sUser, sPassword);
138 catch(
const SQLException& )
140 aInfo = ::cppu::getCaughtException();
142 catch(
const Exception&)
147 if ( !aInfo.isValid() )
150 Reference< XWarningsSupplier > xConnectionWarnings( xConnection, UNO_QUERY );
151 if ( xConnectionWarnings.is() )
155 Any aWarnings( xConnectionWarnings->getWarnings() );
156 if ( aWarnings.hasValue() )
164 aContext.NextException = aWarnings;
167 xConnectionWarnings->clearWarnings();
169 catch(
const Exception& )
177 if ( !m_sContextInformation.isEmpty() )
180 aError.Message = m_sContextInformation;
181 aError.NextException = aInfo.get();
188 if ( aInfo.isValid() )
192 *_pErrorInfo = aInfo;
196 showError(aInfo, m_pErrorMessageParent ? m_pErrorMessageParent->GetXWindow() :
nullptr,
m_xContext);
ODatasourceConnector(const css::uno::Reference< css::uno::XComponentContext > &_rxContext, weld::Window *_pMessageParent)
Reference< XComponentContext > m_xContext
#define DBG_UNHANDLED_EXCEPTION(...)
VCL_DLLPUBLIC OUString removeMnemonicFromString(OUString const &rStr, sal_Int32 &rMnemonicPos)
css::uno::Reference< css::sdbc::XDataSource > getDataSourceByName(const OUString &_rDataSourceName, weld::Window *_pErrorMessageParent, const css::uno::Reference< css::uno::XComponentContext > &_rxContext, ::dbtools::SQLExceptionInfo *_pErrorInfo)
retrieves a data source given by name or URL, and displays an error if this fails
css::uno::Reference< css::uno::XInterface > getDataSourceOrModel(const css::uno::Reference< css::uno::XInterface > &_xObject)
returns either the model when data source is given as parameter, or returns a data source when a mode...
OUString VCL_DLLPUBLIC GetStandardText(StandardButtonType eButton)
constexpr OUStringLiteral PROPERTY_USER(u"User")
constexpr OUStringLiteral PROPERTY_PASSWORD(u"Password")
constexpr OUStringLiteral PROPERTY_ISPASSWORDREQUIRED(u"IsPasswordRequired")
Reference< XModel > xModel
the model of the sub component. Might be <NULL>