Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / connectivity / source / drivers / firebird / Views.cxx
blob2e5bec42adc3de30ce7d0d18b0c20a671fe3efe4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
8 */
9 #include "Tables.hxx"
10 #include "Views.hxx"
11 #include "View.hxx"
12 #include "Catalog.hxx"
13 #include <connectivity/dbtools.hxx>
14 #include <comphelper/types.hxx>
15 #include <TConnection.hxx>
17 connectivity::firebird::Views::Views(
18 const css::uno::Reference<css::sdbc::XConnection>& _rxConnection, ::cppu::OWeakObject& _rParent,
19 ::osl::Mutex& _rMutex, const ::std::vector<OUString>& _rVector)
20 : sdbcx::OCollection(_rParent, true, _rMutex, _rVector)
21 , m_xConnection(_rxConnection)
22 , m_xMetaData(_rxConnection->getMetaData())
23 , m_bInDrop(false)
27 connectivity::sdbcx::ObjectType connectivity::firebird::Views::createObject(const OUString& _rName)
29 OUString sCatalog, sSchema, sTable;
30 ::dbtools::qualifiedNameComponents(m_xMetaData, _rName, sCatalog, sSchema, sTable,
31 ::dbtools::EComposeRule::InDataManipulation);
32 return new View(m_xConnection, isCaseSensitive(), sSchema, sTable);
35 void connectivity::firebird::Views::impl_refresh()
37 static_cast<Catalog&>(m_rParent).refreshViews();
40 css::uno::Reference<css::beans::XPropertySet> connectivity::firebird::Views::createDescriptor()
42 return new connectivity::sdbcx::OView(true, m_xMetaData);
45 // XAppend
46 connectivity::sdbcx::ObjectType connectivity::firebird::Views::appendObject(
47 const OUString& _rForName, const css::uno::Reference<css::beans::XPropertySet>& descriptor)
49 createView(descriptor);
50 return createObject(_rForName);
53 // XDrop
54 void connectivity::firebird::Views::dropObject(sal_Int32 _nPos, const OUString& /*_sElementName*/)
56 if (m_bInDrop)
57 return;
59 css::uno::Reference<XInterface> xObject(getObject(_nPos));
60 bool bIsNew = connectivity::sdbcx::ODescriptor::isNew(xObject);
61 if (!bIsNew)
63 OUString aSql("DROP VIEW");
65 css::uno::Reference<css::beans::XPropertySet> xProp(xObject, css::uno::UNO_QUERY);
66 aSql += ::dbtools::composeTableName(m_xMetaData, xProp,
67 ::dbtools::EComposeRule::InTableDefinitions, true);
69 css::uno::Reference<css::sdbc::XConnection> xConnection = m_xMetaData->getConnection();
70 css::uno::Reference<css::sdbc::XStatement> xStmt = xConnection->createStatement();
71 xStmt->execute(aSql);
72 ::comphelper::disposeComponent(xStmt);
76 void connectivity::firebird::Views::dropByNameImpl(const OUString& elementName)
78 m_bInDrop = true;
79 connectivity::sdbcx::OCollection::dropByName(elementName);
80 m_bInDrop = false;
83 void connectivity::firebird::Views::createView(
84 const css::uno::Reference<css::beans::XPropertySet>& descriptor)
86 css::uno::Reference<css::sdbc::XConnection> xConnection = m_xMetaData->getConnection();
88 OUString sCommand;
89 descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND))
90 >>= sCommand;
92 OUString aSql = "CREATE VIEW "
93 + ::dbtools::composeTableName(m_xMetaData, descriptor,
94 ::dbtools::EComposeRule::InTableDefinitions, true)
95 + " AS " + sCommand;
97 css::uno::Reference<css::sdbc::XStatement> xStmt = xConnection->createStatement();
98 if (xStmt.is())
100 xStmt->execute(aSql);
101 ::comphelper::disposeComponent(xStmt);
103 connectivity::firebird::Tables* pTables = static_cast<connectivity::firebird::Tables*>(
104 static_cast<connectivity::firebird::Catalog&>(m_rParent).getPrivateTables());
105 if (pTables)
107 OUString sName = ::dbtools::composeTableName(
108 m_xMetaData, descriptor, ::dbtools::EComposeRule::InDataManipulation, false);
109 pTables->appendNew(sName);
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */