merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / mysql / YViews.cxx
blob3a2e133421b7633d1efe44b8a1aaaa9cdbc07a89
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: YViews.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "mysql/YViews.hxx"
34 #include "mysql/YTables.hxx"
35 #include <com/sun/star/sdbc/XRow.hpp>
36 #include <com/sun/star/sdbc/XResultSet.hpp>
37 #include <com/sun/star/sdbc/ColumnValue.hpp>
38 #include <com/sun/star/sdbc/KeyRule.hpp>
39 #include <com/sun/star/sdbcx/KeyType.hpp>
40 #include <com/sun/star/sdbcx/CheckOption.hpp>
41 #include "mysql/YCatalog.hxx"
42 #include <comphelper/extract.hxx>
43 #include "connectivity/dbtools.hxx"
44 #include "connectivity/dbexception.hxx"
45 #include <cppuhelper/interfacecontainer.h>
46 #include "connectivity/sdbcx/VView.hxx"
47 #include <comphelper/types.hxx>
48 #include "TConnection.hxx"
50 using namespace ::comphelper;
52 using namespace ::cppu;
53 using namespace connectivity;
54 using namespace connectivity::mysql;
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::beans;
57 using namespace ::com::sun::star::sdbcx;
58 using namespace ::com::sun::star::sdbc;
59 using namespace ::com::sun::star::container;
60 using namespace ::com::sun::star::lang;
61 using namespace dbtools;
62 typedef connectivity::sdbcx::OCollection OCollection_TYPE;
64 sdbcx::ObjectType OViews::createObject(const ::rtl::OUString& _rName)
66 ::rtl::OUString sCatalog,sSchema,sTable;
67 ::dbtools::qualifiedNameComponents(m_xMetaData,
68 _rName,
69 sCatalog,
70 sSchema,
71 sTable,
72 ::dbtools::eInDataManipulation);
73 return new ::connectivity::sdbcx::OView(isCaseSensitive(),
74 sTable,
75 m_xMetaData,
77 ::rtl::OUString(),
78 sSchema,
79 sCatalog
82 // -------------------------------------------------------------------------
83 void OViews::impl_refresh( ) throw(RuntimeException)
85 static_cast<OMySQLCatalog&>(m_rParent).refreshTables();
87 // -------------------------------------------------------------------------
88 void OViews::disposing(void)
90 m_xMetaData.clear();
91 OCollection::disposing();
93 // -------------------------------------------------------------------------
94 Reference< XPropertySet > OViews::createDescriptor()
96 Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
97 connectivity::sdbcx::OView* pNew = new connectivity::sdbcx::OView(sal_True,xConnection->getMetaData());
98 return pNew;
100 // -------------------------------------------------------------------------
101 // XAppend
102 sdbcx::ObjectType OViews::appendObject( const ::rtl::OUString& _rForName, const Reference< XPropertySet >& descriptor )
104 createView(descriptor);
105 return createObject( _rForName );
107 // -------------------------------------------------------------------------
108 // XDrop
109 void OViews::dropObject(sal_Int32 _nPos,const ::rtl::OUString /*_sElementName*/)
111 if ( m_bInDrop )
112 return;
114 Reference< XInterface > xObject( getObject( _nPos ) );
115 sal_Bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject );
116 if (!bIsNew)
118 ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("DROP VIEW");
120 Reference<XPropertySet> xProp(xObject,UNO_QUERY);
121 aSql += ::dbtools::composeTableName( m_xMetaData, xProp, ::dbtools::eInTableDefinitions, false, false, true );
123 Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
124 Reference< XStatement > xStmt = xConnection->createStatement( );
125 xStmt->execute(aSql);
126 ::comphelper::disposeComponent(xStmt);
129 // -----------------------------------------------------------------------------
130 void OViews::dropByNameImpl(const ::rtl::OUString& elementName)
132 m_bInDrop = sal_True;
133 OCollection_TYPE::dropByName(elementName);
134 m_bInDrop = sal_False;
136 // -----------------------------------------------------------------------------
137 void OViews::createView( const Reference< XPropertySet >& descriptor )
139 Reference<XConnection> xConnection = static_cast<OMySQLCatalog&>(m_rParent).getConnection();
141 ::rtl::OUString aSql = ::rtl::OUString::createFromAscii("CREATE VIEW ");
142 ::rtl::OUString aQuote = xConnection->getMetaData()->getIdentifierQuoteString( );
143 ::rtl::OUString sSchema,sCommand;
145 aSql += ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::eInTableDefinitions, false, false, true );
147 aSql += ::rtl::OUString::createFromAscii(" AS ");
148 descriptor->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND)) >>= sCommand;
149 aSql += sCommand;
151 Reference< XStatement > xStmt = xConnection->createStatement( );
152 if ( xStmt.is() )
154 xStmt->execute(aSql);
155 ::comphelper::disposeComponent(xStmt);
158 // insert the new view also in the tables collection
159 OTables* pTables = static_cast<OTables*>(static_cast<OMySQLCatalog&>(m_rParent).getPrivateTables());
160 if ( pTables )
162 ::rtl::OUString sName = ::dbtools::composeTableName( m_xMetaData, descriptor, ::dbtools::eInDataManipulation, false, false, false );
163 pTables->appendNew(sName);