tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / connectivity / source / drivers / hsqldb / HViews.cxx
blob56da442a286658888205bcb455f327f58c26a042
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 .
21 #include <hsqldb/HTables.hxx>
22 #include <hsqldb/HViews.hxx>
23 #include <hsqldb/HView.hxx>
24 #include <hsqldb/HCatalog.hxx>
25 #include <connectivity/dbtools.hxx>
26 #include <comphelper/types.hxx>
27 #include <TConnection.hxx>
29 using namespace ::comphelper;
31 using namespace ::cppu;
32 using namespace connectivity;
33 using namespace connectivity::hsqldb;
34 using namespace css::uno;
35 using namespace css::beans;
36 using namespace css::sdbc;
37 using namespace dbtools;
38 typedef connectivity::sdbcx::OCollection OCollection_TYPE;
41 HViews::HViews( const Reference< XConnection >& _rxConnection, ::cppu::OWeakObject& _rParent, ::osl::Mutex& _rMutex,
42 const ::std::vector< OUString> &_rVector )
43 :sdbcx::OCollection( _rParent, true, _rMutex, _rVector )
44 ,m_xConnection( _rxConnection )
45 ,m_xMetaData( _rxConnection->getMetaData() )
46 ,m_bInDrop( false )
51 sdbcx::ObjectType HViews::createObject(const OUString& _rName)
53 OUString sCatalog,sSchema,sTable;
54 ::dbtools::qualifiedNameComponents(m_xMetaData,
55 _rName,
56 sCatalog,
57 sSchema,
58 sTable,
59 ::dbtools::EComposeRule::InDataManipulation);
60 return new HView( m_xConnection, isCaseSensitive(), sSchema, sTable );
64 void HViews::impl_refresh( )
66 static_cast<OHCatalog&>(m_rParent).refreshTables();
69 void HViews::disposing()
71 m_xMetaData.clear();
72 OCollection::disposing();
75 Reference< XPropertySet > HViews::createDescriptor()
77 Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
78 return new connectivity::sdbcx::OView(true, xConnection->getMetaData());
81 // XAppend
82 sdbcx::ObjectType HViews::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
84 createView(descriptor);
85 return createObject( _rForName );
88 // XDrop
89 void HViews::dropObject(sal_Int32 _nPos,const OUString& /*_sElementName*/)
91 if ( m_bInDrop )
92 return;
94 Reference< XInterface > xObject( getObject( _nPos ) );
95 bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject );
96 if (!bIsNew)
98 OUString aSql( u"DROP VIEW"_ustr );
100 Reference<XPropertySet> xProp(xObject,UNO_QUERY);
101 aSql += ::dbtools::composeTableName( m_xMetaData, xProp, ::dbtools::EComposeRule::InTableDefinitions, true );
103 Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
104 Reference< XStatement > xStmt = xConnection->createStatement( );
105 xStmt->execute(aSql);
106 ::comphelper::disposeComponent(xStmt);
110 void HViews::dropByNameImpl(const OUString& elementName)
112 m_bInDrop = true;
113 OCollection_TYPE::dropByName(elementName);
114 m_bInDrop = false;
117 void HViews::createView( const Reference< XPropertySet >& descriptor )
119 Reference<XConnection> xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
121 OUString sCommand;
122 descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND)) >>= sCommand;
124 OUString aSql = "CREATE VIEW " +
125 ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::EComposeRule::InTableDefinitions, true ) +
126 " AS " + sCommand;
128 Reference< XStatement > xStmt = xConnection->createStatement( );
129 if ( xStmt.is() )
131 xStmt->execute(aSql);
132 ::comphelper::disposeComponent(xStmt);
135 // insert the new view also in the tables collection
136 OTables* pTables = static_cast<OTables*>(static_cast<OHCatalog&>(m_rParent).getPrivateTables());
137 if ( pTables )
139 OUString sName = ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::EComposeRule::InDataManipulation, false );
140 pTables->appendNew(sName);
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */