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

Generated by: LCOV version 1.10