1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
,
59 ::dbtools::eInDataManipulation
);
60 return new ::connectivity::sdbcx::OView(isCaseSensitive(),
70 void OViews::impl_refresh( ) throw(RuntimeException
)
72 static_cast<OMySQLCatalog
&>(m_rParent
).refreshTables();
75 void OViews::disposing(void)
78 OCollection::disposing();
81 Reference
< XPropertySet
> OViews::createDescriptor()
83 Reference
<XConnection
> xConnection
= static_cast<OMySQLCatalog
&>(m_rParent
).getConnection();
84 connectivity::sdbcx::OView
* pNew
= new connectivity::sdbcx::OView(true, xConnection
->getMetaData());
89 sdbcx::ObjectType
OViews::appendObject( const OUString
& _rForName
, const Reference
< XPropertySet
>& descriptor
)
91 createView(descriptor
);
92 return createObject( _rForName
);
96 void OViews::dropObject(sal_Int32 _nPos
,const OUString
& /*_sElementName*/)
101 Reference
< XInterface
> xObject( getObject( _nPos
) );
102 bool bIsNew
= connectivity::sdbcx::ODescriptor::isNew( xObject
);
105 OUString
aSql( "DROP VIEW" );
107 Reference
<XPropertySet
> xProp(xObject
,UNO_QUERY
);
108 aSql
+= ::dbtools::composeTableName( m_xMetaData
, xProp
, ::dbtools::eInTableDefinitions
, false, false, true );
110 Reference
<XConnection
> xConnection
= static_cast<OMySQLCatalog
&>(m_rParent
).getConnection();
111 Reference
< XStatement
> xStmt
= xConnection
->createStatement( );
112 xStmt
->execute(aSql
);
113 ::comphelper::disposeComponent(xStmt
);
117 void OViews::dropByNameImpl(const OUString
& elementName
)
120 OCollection_TYPE::dropByName(elementName
);
124 void OViews::createView( const Reference
< XPropertySet
>& descriptor
)
126 Reference
<XConnection
> xConnection
= static_cast<OMySQLCatalog
&>(m_rParent
).getConnection();
128 OUString
aSql( "CREATE VIEW " );
131 aSql
+= ::dbtools::composeTableName( m_xMetaData
, descriptor
, ::dbtools::eInTableDefinitions
, false, false, true );
134 descriptor
->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_COMMAND
)) >>= sCommand
;
137 Reference
< XStatement
> xStmt
= xConnection
->createStatement( );
140 xStmt
->execute(aSql
);
141 ::comphelper::disposeComponent(xStmt
);
144 // insert the new view also in the tables collection
145 OTables
* pTables
= static_cast<OTables
*>(static_cast<OMySQLCatalog
&>(m_rParent
).getPrivateTables());
148 OUString sName
= ::dbtools::composeTableName( m_xMetaData
, descriptor
, ::dbtools::eInDataManipulation
, false, false, false );
149 pTables
->appendNew(sName
);
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */