LCOV - code coverage report
Current view: top level - connectivity/source/commontools - TDatabaseMetaDataBase.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 115 0.0 %
Date: 2014-04-14 Functions: 0 33 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include "TDatabaseMetaDataBase.hxx"
      21             : #include "RowFunctionParser.hxx"
      22             : 
      23             : #include <comphelper/sequenceashashmap.hxx>
      24             : #include <comphelper/evtlistenerhlp.hxx>
      25             : #include <com/sun/star/lang/XComponent.hpp>
      26             : #include "resource/sharedresources.hxx"
      27             : #include "resource/common_res.hrc"
      28             : #include <connectivity/dbexception.hxx>
      29             : #include <sal/macros.h>
      30             : 
      31             : using namespace com::sun::star::uno;
      32             : using namespace com::sun::star::lang;
      33             : using namespace com::sun::star::sdbc;
      34             : using namespace com::sun::star::beans;
      35             : using namespace comphelper;
      36             : using namespace connectivity;
      37             : 
      38             : 
      39           0 : ODatabaseMetaDataBase::ODatabaseMetaDataBase(const Reference< XConnection >& _rxConnection,const Sequence< PropertyValue >& _rInfo)
      40             :     : m_aConnectionInfo(_rInfo)
      41             :     ,m_isCatalogAtStart(false,sal_False)
      42             :     ,m_sCatalogSeparator(false,OUString())
      43             :     ,m_sIdentifierQuoteString(false,OUString())
      44             :     ,m_supportsCatalogsInTableDefinitions(false,sal_False)
      45             :     ,m_supportsSchemasInTableDefinitions(false,sal_False)
      46             :     ,m_supportsCatalogsInDataManipulation(false,sal_False)
      47             :     ,m_supportsSchemasInDataManipulation(false,sal_False)
      48             :     ,m_supportsMixedCaseQuotedIdentifiers(false,sal_False)
      49             :     ,m_supportsAlterTableWithAddColumn(false,sal_False)
      50             :     ,m_supportsAlterTableWithDropColumn(false,sal_False)
      51             :     ,m_MaxStatements(false,0)
      52             :     ,m_MaxTablesInSelect(false,0)
      53             :     ,m_storesMixedCaseQuotedIdentifiers(false,sal_False)
      54           0 :     , m_xConnection(_rxConnection)
      55             : {
      56           0 :     osl_atomic_increment( &m_refCount );
      57             :     {
      58           0 :         m_xListenerHelper = new OEventListenerHelper(this);
      59           0 :         Reference<XComponent> xCom(m_xConnection,UNO_QUERY);
      60           0 :         if(xCom.is())
      61           0 :             xCom->addEventListener(m_xListenerHelper);
      62             :     }
      63           0 :     osl_atomic_decrement( &m_refCount );
      64           0 : }
      65             : 
      66           0 : ODatabaseMetaDataBase::~ODatabaseMetaDataBase()
      67             : {
      68           0 : }
      69             : 
      70             : 
      71           0 : Sequence< PropertyValue > SAL_CALL ODatabaseMetaDataBase::getConnectionInfo(  ) throw (RuntimeException, std::exception)
      72             : {
      73           0 :     return m_aConnectionInfo;
      74             : }
      75             : 
      76             : 
      77           0 : void SAL_CALL ODatabaseMetaDataBase::disposing( const EventObject& /*Source*/ ) throw(RuntimeException, std::exception)
      78             : {
      79             :     // cut off all references to the connection
      80           0 : m_xConnection.clear();
      81           0 : m_xListenerHelper.clear();
      82           0 : }
      83             : 
      84           0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getTypeInfo(  ) throw(SQLException, RuntimeException, std::exception)
      85             : {
      86           0 :     ::osl::MutexGuard aGuard( m_aMutex );
      87           0 :     if ( m_aTypeInfoRows.empty() )
      88             :     {
      89           0 :         Reference< XResultSet > xRet = impl_getTypeInfo_throw();
      90           0 :         Reference< XRow > xRow(xRet,UNO_QUERY);
      91           0 :         ::comphelper::SequenceAsHashMap aMap(m_aConnectionInfo);
      92           0 :         Sequence< Any > aTypeInfoSettings;
      93           0 :         aTypeInfoSettings = aMap.getUnpackedValueOrDefault("TypeInfoSettings",aTypeInfoSettings);
      94             : 
      95           0 :         if ( xRow.is() )
      96             :         {
      97             :             static const sal_Int32 pTypes[] = {
      98             :                                         DataType::VARCHAR
      99             :                                         ,DataType::INTEGER
     100             :                                         ,DataType::INTEGER
     101             :                                         ,DataType::VARCHAR
     102             :                                         ,DataType::VARCHAR
     103             :                                         ,DataType::VARCHAR
     104             :                                         ,DataType::INTEGER
     105             :                                         ,DataType::BOOLEAN
     106             :                                         ,DataType::INTEGER
     107             :                                         ,DataType::BOOLEAN
     108             :                                         ,DataType::BOOLEAN
     109             :                                         ,DataType::BOOLEAN
     110             :                                         ,DataType::VARCHAR
     111             :                                         ,DataType::INTEGER
     112             :                                         ,DataType::INTEGER
     113             :                                         ,DataType::INTEGER
     114             :                                         ,DataType::INTEGER
     115             :                                         ,DataType::INTEGER
     116             :                                     };
     117           0 :             ::std::vector<ExpressionNodeSharedPtr> aConditions;
     118           0 :             if ( aTypeInfoSettings.getLength() > 1 && ((aTypeInfoSettings.getLength() % 2) == 0) )
     119             :             {
     120           0 :                 const Any* pIter = aTypeInfoSettings.getConstArray();
     121           0 :                 const Any* pEnd  = pIter + aTypeInfoSettings.getLength();
     122             :                 try
     123             :                 {
     124           0 :                     for(;pIter != pEnd;++pIter)
     125           0 :                         aConditions.push_back(FunctionParser::parseFunction(::comphelper::getString(*pIter)));
     126             :                 }
     127           0 :                 catch(ParseError&)
     128             :                 {
     129           0 :                     ::connectivity::SharedResources aResources;
     130           0 :                     const OUString sError( aResources.getResourceString(STR_FORMULA_WRONG));
     131           0 :                     ::dbtools::throwGenericSQLException(sError,*this);
     132             :                 }
     133             :             }
     134             : 
     135           0 :             ::connectivity::ODatabaseMetaDataResultSet::ORows aTypeInfoRows;
     136           0 :             while( xRet->next() )
     137             :             {
     138           0 :                 ::connectivity::ODatabaseMetaDataResultSet::ORow aRow;
     139           0 :                 aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue());
     140           0 :                 const sal_Int32* pType = pTypes;
     141           0 :                 for (sal_Int32 i = 1; i <= sal_Int32(sizeof(pTypes)/sizeof(pTypes[0])); ++i,++pType)
     142             :                 {
     143           0 :                     ORowSetValue aValue;
     144           0 :                     aValue.fill(i,*pType,xRow);
     145           0 :                     aRow.push_back(new ORowSetValueDecorator(aValue));
     146           0 :                 }
     147             : 
     148           0 :                 ::std::vector<ExpressionNodeSharedPtr>::iterator aIter = aConditions.begin();
     149           0 :                 ::std::vector<ExpressionNodeSharedPtr>::iterator aEnd = aConditions.end();
     150           0 :                 for (; aIter != aEnd; ++aIter)
     151             :                 {
     152           0 :                     if ( (*aIter)->evaluate(aRow)->getValue().getBool() )
     153             :                     {
     154           0 :                         ++aIter;
     155           0 :                         (*aIter)->fill(aRow);
     156             :                     }
     157             :                     else
     158           0 :                         ++aIter;
     159             :                 }
     160           0 :                 aTypeInfoRows.push_back(aRow);
     161           0 :             }
     162           0 :             m_aTypeInfoRows = aTypeInfoRows;
     163           0 :         }
     164             :     }
     165           0 :     ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo);
     166           0 :     Reference< XResultSet > xRet = pResult;
     167           0 :     pResult->setRows(m_aTypeInfoRows);
     168           0 :     return xRet;
     169             : }
     170             : 
     171           0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getExportedKeys(
     172             :         const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/ ) throw(SQLException, RuntimeException, std::exception)
     173             : {
     174           0 :     return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eExportedKeys );
     175             : }
     176             : 
     177           0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getImportedKeys(
     178             :         const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/ ) throw(SQLException, RuntimeException, std::exception)
     179             : {
     180           0 :     return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eImportedKeys );
     181             : }
     182             : 
     183           0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getPrimaryKeys(
     184             :         const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/ ) throw(SQLException, RuntimeException, std::exception)
     185             : {
     186           0 :     return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::ePrimaryKeys );
     187             : }
     188             : 
     189           0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getIndexInfo(
     190             :         const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/,
     191             :         sal_Bool /*unique*/, sal_Bool /*approximate*/ ) throw(SQLException, RuntimeException, std::exception)
     192             : {
     193           0 :     return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eIndexInfo );
     194             : }
     195             : 
     196           0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getBestRowIdentifier(
     197             :         const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/, sal_Int32 /*scope*/,
     198             :         sal_Bool /*nullable*/ ) throw(SQLException, RuntimeException, std::exception)
     199             : {
     200           0 :     return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eBestRowIdentifier );
     201             : }
     202             : 
     203           0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getCrossReference(
     204             :         const Any& /*primaryCatalog*/, const OUString& /*primarySchema*/,
     205             :         const OUString& /*primaryTable*/, const Any& /*foreignCatalog*/,
     206             :         const OUString& /*foreignSchema*/, const OUString& /*foreignTable*/ ) throw(SQLException, RuntimeException, std::exception)
     207             : {
     208           0 :     return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCrossReference );
     209             : }
     210             : 
     211           0 : Reference< XConnection > SAL_CALL ODatabaseMetaDataBase::getConnection(  ) throw(SQLException, RuntimeException, std::exception)
     212             : {
     213           0 :     return m_xConnection;
     214             : }
     215             : 
     216           0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getProcedureColumns(
     217             :         const Any& /*catalog*/, const OUString& /*schemaPattern*/,
     218             :         const OUString& /*procedureNamePattern*/, const OUString& /*columnNamePattern*/ ) throw(SQLException, RuntimeException, std::exception)
     219             : {
     220           0 :     return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedureColumns );
     221             : }
     222             : 
     223           0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getProcedures(
     224             :         const Any& /*catalog*/, const OUString& /*schemaPattern*/,
     225             :         const OUString& /*procedureNamePattern*/ ) throw(SQLException, RuntimeException, std::exception)
     226             : {
     227           0 :     return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedures );
     228             : }
     229             : 
     230           0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getVersionColumns(
     231             :         const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/ ) throw(SQLException, RuntimeException, std::exception)
     232             : {
     233           0 :     return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eVersionColumns );
     234             : }
     235             : 
     236           0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getSchemas(  ) throw(SQLException, RuntimeException, std::exception)
     237             : {
     238           0 :     return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eSchemas );
     239             : }
     240             : 
     241           0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getColumnPrivileges(
     242             :         const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/,
     243             :         const OUString& /*columnNamePattern*/ ) throw(SQLException, RuntimeException, std::exception)
     244             : {
     245           0 :     return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eColumnPrivileges );
     246             : }
     247             : 
     248           0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getTablePrivileges(
     249             :         const Any& /*catalog*/, const OUString& /*schema*/, const OUString& /*table*/) throw(SQLException, RuntimeException, std::exception)
     250             : {
     251           0 :     return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges );
     252             : }
     253             : 
     254           0 : Reference< XResultSet > SAL_CALL ODatabaseMetaDataBase::getCatalogs(  ) throw(SQLException, RuntimeException, std::exception)
     255             : {
     256           0 :     return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCatalogs );
     257             : }
     258             : 
     259           0 : OUString SAL_CALL ODatabaseMetaDataBase::getIdentifierQuoteString(  ) throw(SQLException, RuntimeException, std::exception)
     260             : {
     261           0 :     return callImplMethod(m_sIdentifierQuoteString,::std::mem_fun_t< OUString ,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getIdentifierQuoteString_throw));
     262             : }
     263             : 
     264           0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::isCatalogAtStart(  ) throw(SQLException, RuntimeException, std::exception)
     265             : {
     266           0 :     return callImplMethod(m_isCatalogAtStart,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_isCatalogAtStart_throw));
     267             : }
     268             : 
     269           0 : OUString SAL_CALL ODatabaseMetaDataBase::getCatalogSeparator(  ) throw(SQLException, RuntimeException, std::exception)
     270             : {
     271           0 :     return callImplMethod(m_sCatalogSeparator,::std::mem_fun_t< OUString,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getCatalogSeparator_throw));
     272             : }
     273             : 
     274           0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsCatalogsInTableDefinitions(  ) throw(SQLException, RuntimeException, std::exception)
     275             : {
     276           0 :     return callImplMethod(m_supportsCatalogsInTableDefinitions,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsCatalogsInTableDefinitions_throw));
     277             : }
     278             : 
     279           0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsSchemasInTableDefinitions(  ) throw(SQLException, RuntimeException, std::exception)
     280             : {
     281           0 :     return callImplMethod(m_supportsSchemasInTableDefinitions,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsSchemasInTableDefinitions_throw));
     282             : }
     283             : 
     284           0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsCatalogsInDataManipulation(  ) throw(SQLException, RuntimeException, std::exception)
     285             : {
     286           0 :     return callImplMethod(m_supportsCatalogsInDataManipulation,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsCatalogsInDataManipulation_throw));
     287             : }
     288             : 
     289           0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsSchemasInDataManipulation(  ) throw(SQLException, RuntimeException, std::exception)
     290             : {
     291           0 :     return callImplMethod(m_supportsSchemasInDataManipulation,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsSchemasInDataManipulation_throw));
     292             : }
     293             : 
     294           0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsMixedCaseQuotedIdentifiers(  ) throw(SQLException, RuntimeException, std::exception)
     295             : {
     296           0 :     return callImplMethod(m_supportsMixedCaseQuotedIdentifiers,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsMixedCaseQuotedIdentifiers_throw));
     297             : }
     298             : 
     299           0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsAlterTableWithAddColumn(  ) throw(SQLException, RuntimeException, std::exception)
     300             : {
     301           0 :     return callImplMethod(m_supportsAlterTableWithAddColumn,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsAlterTableWithAddColumn_throw));
     302             : }
     303             : 
     304           0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::supportsAlterTableWithDropColumn(  ) throw(SQLException, RuntimeException, std::exception)
     305             : {
     306           0 :     return callImplMethod(m_supportsAlterTableWithDropColumn,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_supportsAlterTableWithDropColumn_throw));
     307             : }
     308             : 
     309           0 : sal_Int32 SAL_CALL ODatabaseMetaDataBase::getMaxStatements(  ) throw(SQLException, RuntimeException, std::exception)
     310             : {
     311           0 :     return callImplMethod(m_MaxStatements,::std::mem_fun_t< sal_Int32,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getMaxStatements_throw));
     312             : }
     313             : 
     314           0 : sal_Int32 SAL_CALL ODatabaseMetaDataBase::getMaxTablesInSelect(  ) throw(SQLException, RuntimeException, std::exception)
     315             : {
     316           0 :     return callImplMethod(m_MaxTablesInSelect,::std::mem_fun_t< sal_Int32,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_getMaxTablesInSelect_throw));
     317             : }
     318             : 
     319           0 : sal_Bool SAL_CALL ODatabaseMetaDataBase::storesMixedCaseQuotedIdentifiers(  ) throw(SQLException, RuntimeException, std::exception)
     320             : {
     321           0 :     return callImplMethod(m_storesMixedCaseQuotedIdentifiers,::std::mem_fun_t< sal_Bool,ODatabaseMetaDataBase>(&ODatabaseMetaDataBase::impl_storesMixedCaseQuotedIdentifiers_throw));
     322             : }
     323             : 
     324             : 
     325             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10