LCOV - code coverage report
Current view: top level - connectivity/source/parse - PColumn.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 61 121 50.4 %
Date: 2015-06-13 12:38:46 Functions: 13 17 76.5 %
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             : 
      21             : #include <connectivity/PColumn.hxx>
      22             : #include <connectivity/dbtools.hxx>
      23             : #include "TConnection.hxx"
      24             : 
      25             : #include <comphelper/types.hxx>
      26             : #include <tools/diagnose_ex.h>
      27             : 
      28             : using namespace ::comphelper;
      29             : using namespace connectivity;
      30             : using namespace dbtools;
      31             : using namespace connectivity::parse;
      32             : using namespace ::com::sun::star::uno;
      33             : using namespace ::com::sun::star::sdbc;
      34             : using namespace ::com::sun::star::beans;
      35             : using namespace ::com::sun::star::container;
      36             : 
      37             : 
      38         251 : OParseColumn::OParseColumn(const Reference<XPropertySet>& _xColumn, bool _bCase)
      39         251 :     : connectivity::sdbcx::OColumn( getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME)))
      40         251 :                                 ,   getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME)))
      41         251 :                                 ,   getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE)))
      42         251 :                                 ,   getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION)))
      43         251 :                                 ,   getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE)))
      44         251 :                                 ,   getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)))
      45         251 :                                 ,   getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE)))
      46         251 :                                 ,   getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)))
      47         502 :                                 ,   getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT)))
      48             :                                 ,   false
      49         502 :                                 ,   getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))
      50             :                                 ,   _bCase
      51         251 :                                 ,   getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME)))
      52         251 :                                 ,   getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME)))
      53         251 :                                 ,   getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME)))
      54             :                                 )
      55             :     , m_bFunction(false)
      56             :     , m_bDbasePrecisionChanged(false)
      57             :     , m_bAggregateFunction(false)
      58        3514 :     , m_bIsSearchable( true )
      59             : {
      60         251 :     construct();
      61         251 : }
      62             : 
      63             : 
      64        2274 : OParseColumn::OParseColumn( const OUString& _Name,
      65             :                     const OUString& _TypeName,
      66             :                     const OUString& _DefaultValue,
      67             :                     const OUString& _Description,
      68             :                     sal_Int32       _IsNullable,
      69             :                     sal_Int32       _Precision,
      70             :                     sal_Int32       _Scale,
      71             :                     sal_Int32       _Type,
      72             :                     bool            _IsAutoIncrement,
      73             :                     bool            _IsCurrency,
      74             :                     bool            _bCase,
      75             :                     const OUString& _CatalogName,
      76             :                     const OUString& _SchemaName,
      77             :                     const OUString& _TableName
      78             :                 ) : connectivity::sdbcx::OColumn(_Name,
      79             :                                   _TypeName,
      80             :                                   _DefaultValue,
      81             :                                   _Description,
      82             :                                   _IsNullable,
      83             :                                   _Precision,
      84             :                                   _Scale,
      85             :                                   _Type,
      86             :                                   _IsAutoIncrement,
      87             :                                   false,
      88             :                                   _IsCurrency,
      89             :                                   _bCase,
      90             :                                   _CatalogName,
      91             :                                   _SchemaName,
      92             :                                   _TableName)
      93             :     , m_bFunction(false)
      94             :     , m_bDbasePrecisionChanged(false)
      95             :     , m_bAggregateFunction(false)
      96        2274 :     , m_bIsSearchable( true )
      97             : {
      98        2274 :     construct();
      99        2274 : }
     100             : 
     101             : 
     102           0 : ::rtl::Reference< OSQLColumns > OParseColumn::createColumnsForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
     103             :     const Reference< XDatabaseMetaData >& _rxDBMetaData,const Reference< XNameAccess>& i_xQueryColumns )
     104             : {
     105           0 :     sal_Int32 nColumnCount = _rxResMetaData->getColumnCount();
     106           0 :     ::rtl::Reference< OSQLColumns > aReturn( new OSQLColumns ); aReturn->get().reserve( nColumnCount );
     107             : 
     108           0 :     StringMap aColumnMap;
     109           0 :     for ( sal_Int32 i = 1; i <= nColumnCount; ++i )
     110             :     {
     111           0 :         OParseColumn* pColumn = createColumnForResultSet( _rxResMetaData, _rxDBMetaData, i,aColumnMap );
     112           0 :         aReturn->get().push_back( pColumn );
     113           0 :         if ( i_xQueryColumns.is() && i_xQueryColumns->hasByName(pColumn->getRealName()) )
     114             :         {
     115           0 :             Reference<XPropertySet> xColumn(i_xQueryColumns->getByName(pColumn->getRealName()),UNO_QUERY_THROW);
     116           0 :             OUString sLabel;
     117           0 :             xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LABEL)) >>= sLabel;
     118           0 :             if ( !sLabel.isEmpty() )
     119           0 :                 pColumn->setLabel(sLabel);
     120             :         }
     121             :     }
     122             : 
     123           0 :     return aReturn;
     124             : }
     125             : 
     126             : 
     127           0 : OParseColumn* OParseColumn::createColumnForResultSet( const Reference< XResultSetMetaData >& _rxResMetaData,
     128             :     const Reference< XDatabaseMetaData >& _rxDBMetaData, sal_Int32 _nColumnPos, StringMap& _rColumns )
     129             : {
     130           0 :     OUString sLabel = _rxResMetaData->getColumnLabel( _nColumnPos );
     131             :     // retrieve the name of the column
     132             :     // check for duplicate entries
     133           0 :     if(_rColumns.find(sLabel) != _rColumns.end())
     134             :     {
     135           0 :         OUString sAlias(sLabel);
     136           0 :         sal_Int32 searchIndex=1;
     137           0 :         while(_rColumns.find(sAlias) != _rColumns.end())
     138             :         {
     139           0 :             (sAlias = sLabel) += OUString::number(searchIndex++);
     140             :         }
     141           0 :         sLabel = sAlias;
     142             :     }
     143           0 :     _rColumns.insert(StringMap::value_type(sLabel,0));
     144             :     OParseColumn* pColumn = new OParseColumn(
     145             :         sLabel,
     146           0 :         _rxResMetaData->getColumnTypeName( _nColumnPos ),
     147             :         OUString(),
     148             :         OUString(),
     149           0 :         _rxResMetaData->isNullable( _nColumnPos ),
     150           0 :         _rxResMetaData->getPrecision( _nColumnPos ),
     151           0 :         _rxResMetaData->getScale( _nColumnPos ),
     152           0 :         _rxResMetaData->getColumnType( _nColumnPos ),
     153           0 :         _rxResMetaData->isAutoIncrement( _nColumnPos ),
     154           0 :         _rxResMetaData->isCurrency( _nColumnPos ),
     155           0 :         _rxDBMetaData->supportsMixedCaseQuotedIdentifiers(),
     156           0 :         _rxResMetaData->getCatalogName( _nColumnPos ),
     157           0 :         _rxResMetaData->getSchemaName( _nColumnPos ),
     158           0 :         _rxResMetaData->getTableName( _nColumnPos )
     159           0 :     );
     160           0 :     pColumn->setIsSearchable( _rxResMetaData->isSearchable( _nColumnPos ) );
     161           0 :     pColumn->setRealName(_rxResMetaData->getColumnName( _nColumnPos ));
     162           0 :     pColumn->setLabel(sLabel);
     163           0 :     return pColumn;
     164             : }
     165             : 
     166             : 
     167        5050 : OParseColumn::~OParseColumn()
     168             : {
     169        5050 : }
     170             : 
     171        2525 : void OParseColumn::construct()
     172             : {
     173        2525 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION),                PROPERTY_ID_FUNCTION,               0,  &m_bFunction,               cppu::UnoType<decltype(m_bFunction)>::get());
     174        2525 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_AGGREGATEFUNCTION),       PROPERTY_ID_AGGREGATEFUNCTION,      0,  &m_bAggregateFunction,      cppu::UnoType<decltype(m_bAggregateFunction)>::get());
     175        2525 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_REALNAME),                PROPERTY_ID_REALNAME,               0,  &m_aRealName,               cppu::UnoType<decltype(m_aRealName)>::get());
     176        2525 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DBASEPRECISIONCHANGED),   PROPERTY_ID_DBASEPRECISIONCHANGED,  0,  &m_bDbasePrecisionChanged,  cppu::UnoType<decltype(m_bDbasePrecisionChanged)>::get());
     177        2525 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISSEARCHABLE),            PROPERTY_ID_ISSEARCHABLE,           0,  &m_bIsSearchable,           cppu::UnoType<decltype(m_bIsSearchable)>::get());
     178        2525 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_LABEL),                   PROPERTY_ID_LABEL,                  0,  &m_sLabel,                  cppu::UnoType<decltype(m_sLabel)>::get());
     179        2525 : }
     180             : 
     181          24 : ::cppu::IPropertyArrayHelper* OParseColumn::createArrayHelper() const
     182             : {
     183          24 :     return doCreateArrayHelper();
     184             : }
     185             : 
     186      110487 : ::cppu::IPropertyArrayHelper & SAL_CALL OParseColumn::getInfoHelper()
     187             : {
     188             :     OSL_ENSURE( !isNew(), "OParseColumn::getInfoHelper: a *new* ParseColumn?" );
     189      110487 :     return *OParseColumn_PROP::getArrayHelper();
     190             : }
     191             : 
     192             : 
     193          14 : OOrderColumn::OOrderColumn( const Reference<XPropertySet>& _xColumn, const OUString& i_rOriginatingTableName,
     194             :                             bool _bCase, bool _bAscending )
     195             :     : connectivity::sdbcx::OColumn(
     196          14 :         getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),
     197          14 :         getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))),
     198          14 :         getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))),
     199          14 :         getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION))),
     200          14 :         getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))),
     201          14 :         getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))),
     202          14 :         getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))),
     203          14 :         getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))),
     204          28 :         getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT))),
     205             :         false,
     206          28 :         getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))),
     207             :         _bCase,
     208          14 :         getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME))),
     209          14 :         getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME))),
     210             :         i_rOriginatingTableName
     211             :     )
     212         182 :     ,m_bAscending(_bAscending)
     213             : {
     214          14 :     construct();
     215          14 : }
     216             : 
     217             : 
     218           0 : OOrderColumn::OOrderColumn( const Reference<XPropertySet>& _xColumn, bool _bCase, bool _bAscending )
     219             :     : connectivity::sdbcx::OColumn(
     220           0 :         getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))),
     221           0 :         getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))),
     222           0 :         getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DEFAULTVALUE))),
     223           0 :         getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_DESCRIPTION))),
     224           0 :         getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))),
     225           0 :         getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))),
     226           0 :         getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))),
     227           0 :         getINT32(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))),
     228           0 :         getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT))),
     229             :         false,
     230           0 :         getBOOL(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))),
     231             :         _bCase,
     232           0 :         getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_CATALOGNAME))),
     233           0 :         getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCHEMANAME))),
     234           0 :         getString(_xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TABLENAME)))
     235             :     )
     236           0 :     ,m_bAscending(_bAscending)
     237             : {
     238           0 :     construct();
     239           0 : }
     240             : 
     241             : 
     242          28 : OOrderColumn::~OOrderColumn()
     243             : {
     244          28 : }
     245             : 
     246             : 
     247          14 : void OOrderColumn::construct()
     248             : {
     249          14 :     registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISASCENDING), PROPERTY_ID_ISASCENDING,
     250          28 :         PropertyAttribute::READONLY,  const_cast< bool* >( &m_bAscending ),    cppu::UnoType<decltype(m_bAscending)>::get() );
     251          14 : }
     252             : 
     253           2 : ::cppu::IPropertyArrayHelper* OOrderColumn::createArrayHelper() const
     254             : {
     255           2 :     return doCreateArrayHelper();
     256             : }
     257             : 
     258          12 : ::cppu::IPropertyArrayHelper & SAL_CALL OOrderColumn::getInfoHelper()
     259             : {
     260             :     OSL_ENSURE( !isNew(), "OOrderColumn::getInfoHelper: a *new* OrderColumn?" );
     261          12 :     return *OOrderColumn_PROP::getArrayHelper();
     262             : }
     263             : 
     264           0 : ::com::sun::star::uno::Sequence< OUString > SAL_CALL OOrderColumn::getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     265             : {
     266           0 :     ::com::sun::star::uno::Sequence< OUString > aSupported(1);
     267           0 :     aSupported[0] = "com.sun.star.sdb.OrderColumn";
     268             : 
     269           0 :     return aSupported;
     270             : }
     271             : 
     272             : 
     273             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11