Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / connectivity / source / commontools / ParameterSubstitution.cxx
blobe5d08fbe499f6637ee26a40f25503bec437d02d5
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 .
19 #include <ParameterSubstitution.hxx>
20 #include <connectivity/sqlparse.hxx>
21 #include <comphelper/sequenceashashmap.hxx>
22 #include <cppuhelper/supportsservice.hxx>
23 #include <utility>
25 namespace connectivity
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::sdbc;
29 using namespace ::com::sun::star::lang;
30 using namespace ::com::sun::star;
32 ParameterSubstitution::ParameterSubstitution(css::uno::Reference< css::uno::XComponentContext > _xContext ) : m_xContext(std::move(_xContext))
35 void SAL_CALL ParameterSubstitution::initialize( const uno::Sequence< uno::Any >& _aArguments )
37 ::osl::MutexGuard aGuard(m_aMutex);
38 comphelper::SequenceAsHashMap aArgs(_aArguments);
39 uno::Reference< sdbc::XConnection > xConnection;
40 xConnection = aArgs.getUnpackedValueOrDefault(u"ActiveConnection"_ustr,xConnection);
41 m_xConnection = xConnection;
44 OUString SAL_CALL ParameterSubstitution::getImplementationName( )
46 return u"org.openoffice.comp.helper.ParameterSubstitution"_ustr;
49 sal_Bool SAL_CALL ParameterSubstitution::supportsService( const OUString& _rServiceName )
51 return cppu::supportsService(this, _rServiceName);
54 Sequence< OUString > SAL_CALL ParameterSubstitution::getSupportedServiceNames( )
56 return { u"com.sun.star.sdb.ParameterSubstitution"_ustr };
60 OUString SAL_CALL ParameterSubstitution::substituteVariables( const OUString& _sText, sal_Bool /*bSubstRequired*/ )
62 OUString sRet = _sText;
63 uno::Reference< sdbc::XConnection > xConnection = m_xConnection;
64 if ( xConnection.is() )
66 try
68 OSQLParser aParser( m_xContext );
69 OUString sErrorMessage;
70 std::unique_ptr<OSQLParseNode> pNode = aParser.parseTree(sErrorMessage,_sText);
71 if(pNode)
72 { // special handling for parameters
73 OSQLParseNode::substituteParameterNames(pNode.get());
74 OUString sNewSql;
75 pNode->parseNodeToStr( sNewSql, xConnection );
76 sRet = sNewSql;
79 catch(const Exception&)
83 return sRet;
86 OUString SAL_CALL ParameterSubstitution::reSubstituteVariables( const OUString& _sText )
88 return _sText;
91 OUString SAL_CALL ParameterSubstitution::getSubstituteVariableValue( const OUString& /*variable*/ )
93 throw container::NoSuchElementException();
97 } // connectivity
99 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
100 connectivity_dbtools_ParameterSubstitution_get_implementation(
101 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
103 return cppu::acquire(new connectivity::ParameterSubstitution(context));
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */