LibreOffice Module connectivity (master) 1
mysqlc_view.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "mysqlc_view.hxx"
21
22#include <propertyids.hxx>
23
24#include <com/sun/star/sdbc/XRow.hpp>
25
27{
28View::View(const css::uno::Reference<css::sdbc::XConnection>& _rxConnection, bool _bCaseSensitive,
29 const OUString& _rSchemaName, const OUString& _rName)
30 : View_Base(_bCaseSensitive, _rName, _rxConnection->getMetaData(), OUString(), _rSchemaName,
31 OUString())
32 , m_xConnection(_rxConnection)
33{
34}
35
37
38void SAL_CALL View::acquire() noexcept { View_Base::acquire(); };
39void SAL_CALL View::release() noexcept { View_Base::release(); };
40css::uno::Any SAL_CALL View::queryInterface(const css::uno::Type& _rType)
41{
42 css::uno::Any aReturn = View_Base::queryInterface(_rType);
43 if (!aReturn.hasValue())
44 aReturn = View_IBASE::queryInterface(_rType);
45 return aReturn;
46}
47
48css::uno::Sequence<css::uno::Type> SAL_CALL View::getTypes()
49{
50 return ::comphelper::concatSequences(View_Base::getTypes(), View_IBASE::getTypes());
51}
52
53css::uno::Sequence<sal_Int8> SAL_CALL View::getImplementationId()
54{
55 return css::uno::Sequence<sal_Int8>();
56}
57
58void SAL_CALL View::alterCommand(const OUString& _rNewCommand)
59{
60 OUString aCommand = "ALTER VIEW " + m_SchemaName + "." + m_Name + " AS " + _rNewCommand;
61 m_xMetaData->getConnection()->createStatement()->execute(aCommand);
62}
63
64void SAL_CALL View::getFastPropertyValue(css::uno::Any& _rValue, sal_Int32 _nHandle) const
65{
66 if (_nHandle == PROPERTY_ID_COMMAND)
67 {
68 // retrieve the very current command, don't rely on the base classes cached value
69 // (which we initialized empty, anyway)
70 _rValue <<= impl_getCommand();
71 return;
72 }
73
74 View_Base::getFastPropertyValue(_rValue, _nHandle);
75}
76
77OUString View::impl_getCommand() const
78{
79 OUString aCommand("SELECT VIEW_DEFINITION FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = '"
80 + m_SchemaName + "' AND TABLE_NAME = '" + m_Name + "'");
81 //::utl::SharedUNOComponent< XStatement > xStatement; xStatement.set( m_xConnection->createStatement(), UNO_QUERY_THROW );
82 css::uno::Reference<css::sdbc::XResultSet> xResult(
83 m_xMetaData->getConnection()->createStatement()->executeQuery(aCommand),
84 css::uno::UNO_SET_THROW);
85 if (!xResult->next())
86 {
87 // hmm. There is no view the name as we know it. Can only mean some other instance
88 // dropped this view meanwhile...
89 std::abort();
90 }
91
92 css::uno::Reference<css::sdbc::XRow> xRow(xResult, css::uno::UNO_QUERY_THROW);
93 return xRow->getString(1);
94}
95
96} // namespace connectivity::mysqlc
97
98/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
virtual ~View() override
Definition: mysqlc_view.cxx:36
virtual void SAL_CALL release() noexcept override
Definition: mysqlc_view.cxx:39
View(const css::uno::Reference< css::sdbc::XConnection > &_rxConnection, bool _bCaseSensitive, const OUString &_rSchemaName, const OUString &_rName)
Definition: mysqlc_view.cxx:28
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: mysqlc_view.cxx:53
virtual void SAL_CALL alterCommand(const OUString &NewCommand) override
Definition: mysqlc_view.cxx:58
virtual void SAL_CALL acquire() noexcept override
Definition: mysqlc_view.cxx:38
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: mysqlc_view.cxx:48
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &_rValue, sal_Int32 _nHandle) const override
Definition: mysqlc_view.cxx:64
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
Definition: mysqlc_view.cxx:40
OUString impl_getCommand() const
retrieves the current command of the View
Definition: mysqlc_view.cxx:77
virtual void SAL_CALL release() noexcept override
Definition: VView.cxx:127
virtual void SAL_CALL acquire() noexcept override
Definition: VView.cxx:122
css::uno::Reference< css::sdbc::XDatabaseMetaData > m_xMetaData
Definition: VView.hxx:54
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: VView.cxx:83
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: VView.cxx:78
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
Reference< XConnection > m_xConnection
#define PROPERTY_ID_COMMAND
Definition: propertyids.hxx:72
OUString aCommand