build fix
[LibreOffice.git] / connectivity / source / drivers / mysql / YViews.cxx
blob0e45831c7ad2b1f0e41b3007d17ab35b7ef22bb4
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 .
20 #include "mysql/YViews.hxx"
21 #include "mysql/YTables.hxx"
22 #include <com/sun/star/sdbc/XRow.hpp>
23 #include <com/sun/star/sdbc/XResultSet.hpp>
24 #include <com/sun/star/sdbc/ColumnValue.hpp>
25 #include <com/sun/star/sdbc/KeyRule.hpp>
26 #include <com/sun/star/sdbcx/KeyType.hpp>
27 #include <com/sun/star/sdbcx/CheckOption.hpp>
28 #include "mysql/YCatalog.hxx"
29 #include <comphelper/extract.hxx>
30 #include <connectivity/dbtools.hxx>
31 #include <connectivity/dbexception.hxx>
32 #include <cppuhelper/interfacecontainer.h>
33 #include <connectivity/sdbcx/VView.hxx>
34 #include <comphelper/types.hxx>
35 #include "TConnection.hxx"
37 using namespace ::comphelper;
39 using namespace ::cppu;
40 using namespace connectivity;
41 using namespace connectivity::mysql;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::sdbcx;
45 using namespace ::com::sun::star::sdbc;
46 using namespace ::com::sun::star::container;
47 using namespace ::com::sun::star::lang;
48 using namespace dbtools;
49 typedef connectivity::sdbcx::OCollection OCollection_TYPE;
51 sdbcx::ObjectType OViews::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 ::connectivity::sdbcx::OView(isCaseSensitive(),
61 sTable,
62 m_xMetaData,
63 OUString(),
64 sSchema,
65 sCatalog
69 void OViews::impl_refresh( ) throw(RuntimeException)
71 static_cast<OMySQLCatalog&>(m_rParent).refreshTables();
74 void OViews::disposing()
76 m_xMetaData.clear();
77 OCollection::disposing();
80 Reference< XPropertySet > OViews::createDescriptor()
82 Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
83 connectivity::sdbcx::OView* pNew = new connectivity::sdbcx::OView(true, xConnection->getMetaData());
84 return pNew;
87 // XAppend
88 sdbcx::ObjectType OViews::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
90 createView(descriptor);
91 return createObject( _rForName );
94 // XDrop
95 void OViews::dropObject(sal_Int32 _nPos,const OUString& /*_sElementName*/)
97 if ( m_bInDrop )
98 return;
100 Reference< XInterface > xObject( getObject( _nPos ) );
101 bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject );
102 if (!bIsNew)
104 OUString aSql( "DROP VIEW" );
106 Reference<XPropertySet> xProp(xObject,UNO_QUERY);
107 aSql += ::dbtools::composeTableName( m_xMetaData, xProp, ::dbtools::EComposeRule::InTableDefinitions, false, false, true );
109 Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
110 Reference< XStatement > xStmt = xConnection->createStatement( );
111 xStmt->execute(aSql);
112 ::comphelper::disposeComponent(xStmt);
116 void OViews::dropByNameImpl(const OUString& elementName)
118 m_bInDrop = true;
119 OCollection_TYPE::dropByName(elementName);
120 m_bInDrop = false;
123 void OViews::createView( const Reference< XPropertySet >& descriptor )
125 Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
127 OUString aSql( "CREATE VIEW " );
128 OUString sCommand;
130 aSql += ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::EComposeRule::InTableDefinitions, false, false, true );
132 aSql += " AS ";
133 descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND)) >>= sCommand;
134 aSql += sCommand;
136 Reference< XStatement > xStmt = xConnection->createStatement( );
137 if ( xStmt.is() )
139 xStmt->execute(aSql);
140 ::comphelper::disposeComponent(xStmt);
143 // insert the new view also in the tables collection
144 OTables* pTables = static_cast<OTables*>(static_cast<OMySQLCatalog&>(m_rParent).getPrivateTables());
145 if ( pTables )
147 OUString sName = ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::EComposeRule::InDataManipulation, false, false, false );
148 pTables->appendNew(sName);
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */