tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / connectivity / source / drivers / hsqldb / HTables.cxx
blobbec309c0950dacf62cbb906042748252ef0e73ca
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 <hsqldb/HTables.hxx>
21 #include <hsqldb/HViews.hxx>
22 #include <hsqldb/HTable.hxx>
23 #include <com/sun/star/sdbc/XRow.hpp>
24 #include <com/sun/star/sdbc/XResultSet.hpp>
25 #include <com/sun/star/sdbcx/Privilege.hpp>
26 #include <hsqldb/HCatalog.hxx>
27 #include <connectivity/dbtools.hxx>
28 #include <comphelper/types.hxx>
29 #include <TConnection.hxx>
31 using namespace ::comphelper;
32 using namespace connectivity;
33 using namespace ::cppu;
34 using namespace connectivity::hsqldb;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::sdbcx;
38 using namespace ::com::sun::star::sdbc;
39 using namespace ::com::sun::star::container;
40 using namespace dbtools;
42 sdbcx::ObjectType OTables::createObject(const OUString& _rName)
44 OUString sCatalog,sSchema,sTable;
45 ::dbtools::qualifiedNameComponents(m_xMetaData,_rName,sCatalog,sSchema,sTable,::dbtools::EComposeRule::InDataManipulation);
47 Sequence< OUString > sTableTypes {u"VIEW"_ustr, u"TABLE"_ustr, u"%"_ustr}; // this last one just to be sure to include anything else...
49 Any aCatalog;
50 if ( !sCatalog.isEmpty() )
51 aCatalog <<= sCatalog;
52 Reference< XResultSet > xResult = m_xMetaData->getTables(aCatalog,sSchema,sTable,sTableTypes);
54 sdbcx::ObjectType xRet;
55 if ( xResult.is() )
57 Reference< XRow > xRow(xResult,UNO_QUERY);
58 if ( xResult->next() ) // there can be only one table with this name
60 sal_Int32 nPrivileges = ::dbtools::getTablePrivileges( m_xMetaData, sCatalog, sSchema, sTable );
61 if ( m_xMetaData->isReadOnly() )
62 nPrivileges &= ~( Privilege::INSERT | Privilege::UPDATE | Privilege::DELETE | Privilege::CREATE | Privilege::ALTER | Privilege::DROP );
64 // obtain privileges
65 xRet = new OHSQLTable( this
66 ,static_cast<OHCatalog&>(m_rParent).getConnection()
67 ,sTable
68 ,xRow->getString(4)
69 ,xRow->getString(5)
70 ,sSchema
71 ,sCatalog
72 ,nPrivileges);
74 ::comphelper::disposeComponent(xResult);
77 return xRet;
80 void OTables::impl_refresh( )
82 static_cast<OHCatalog&>(m_rParent).refreshTables();
85 void OTables::disposing()
87 m_xMetaData.clear();
88 OCollection::disposing();
91 Reference< XPropertySet > OTables::createDescriptor()
93 return new OHSQLTable(this,static_cast<OHCatalog&>(m_rParent).getConnection());
96 // XAppend
97 sdbcx::ObjectType OTables::appendObject( const OUString& _rForName, const Reference< XPropertySet >& descriptor )
99 createTable(descriptor);
100 return createObject( _rForName );
103 // XDrop
104 void OTables::dropObject(sal_Int32 _nPos,const OUString& _sElementName)
106 Reference< XInterface > xObject( getObject( _nPos ) );
107 bool bIsNew = connectivity::sdbcx::ODescriptor::isNew( xObject );
108 if (bIsNew)
109 return;
111 Reference< XConnection > xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
114 OUString sCatalog,sSchema,sTable;
115 ::dbtools::qualifiedNameComponents(m_xMetaData,_sElementName,sCatalog,sSchema,sTable,::dbtools::EComposeRule::InDataManipulation);
117 OUString aSql( u"DROP "_ustr );
119 Reference<XPropertySet> xProp(xObject,UNO_QUERY);
120 bool bIsView;
121 if((bIsView = (xProp.is() && ::comphelper::getString(xProp->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))) == "VIEW"))) // here we have a view
122 aSql += "VIEW ";
123 else
124 aSql += "TABLE ";
126 OUString sComposedName(
127 ::dbtools::composeTableName( m_xMetaData, sCatalog, sSchema, sTable, true, ::dbtools::EComposeRule::InDataManipulation ) );
128 aSql += sComposedName;
129 Reference< XStatement > xStmt = xConnection->createStatement( );
130 if ( xStmt.is() )
132 xStmt->execute(aSql);
133 ::comphelper::disposeComponent(xStmt);
135 // if no exception was thrown we must delete it from the views
136 if ( bIsView )
138 HViews* pViews = static_cast<HViews*>(static_cast<OHCatalog&>(m_rParent).getPrivateViews());
139 if ( pViews && pViews->hasByName(_sElementName) )
140 pViews->dropByNameImpl(_sElementName);
144 void OTables::createTable( const Reference< XPropertySet >& descriptor )
146 Reference< XConnection > xConnection = static_cast<OHCatalog&>(m_rParent).getConnection();
147 OUString aSql = ::dbtools::createSqlCreateTableStatement(descriptor,xConnection);
149 Reference< XStatement > xStmt = xConnection->createStatement( );
150 if ( xStmt.is() )
152 xStmt->execute(aSql);
153 ::comphelper::disposeComponent(xStmt);
157 void OTables::appendNew(const OUString& _rsNewTable)
159 insertElement(_rsNewTable,nullptr);
161 // notify our container listeners
162 ContainerEvent aEvent(static_cast<XContainer*>(this), Any(_rsNewTable), Any(), Any());
163 OInterfaceIteratorHelper3 aListenerLoop(m_aContainerListeners);
164 while (aListenerLoop.hasMoreElements())
165 aListenerLoop.next()->elementInserted(aEvent);
168 OUString OTables::getNameForObject(const sdbcx::ObjectType& _xObject)
170 OSL_ENSURE(_xObject.is(),"OTables::getNameForObject: Object is NULL!");
171 return ::dbtools::composeTableName( m_xMetaData, _xObject, ::dbtools::EComposeRule::InDataManipulation, false );
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */