LCOV - code coverage report
Current view: top level - ucb/source/ucp/file - filrow.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 29 158 18.4 %
Date: 2015-06-13 12:38:46 Functions: 10 41 24.4 %
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 "filrow.hxx"
      21             : #include "shell.hxx"
      22             : #include "prov.hxx"
      23             : #include <com/sun/star/script/Converter.hpp>
      24             : #include <comphelper/processfactory.hxx>
      25             : 
      26             : using namespace fileaccess;
      27             : using namespace com::sun::star;
      28             : using namespace com::sun::star::uno;
      29             : 
      30             : #if OSL_DEBUG_LEVEL > 0
      31             : #define THROW_WHERE SAL_WHERE
      32             : #else
      33             : #define THROW_WHERE ""
      34             : #endif
      35             : 
      36             : // Function for TypeConverting
      37             : 
      38             : template< class _type_ >
      39       61444 : bool convert( shell* pShell,
      40             :                   uno::Reference< script::XTypeConverter >& xConverter,
      41             :                   uno::Any& rValue,
      42             :                   _type_& aReturn  )
      43             : {
      44             :     // Try first without converting
      45       61444 :     bool no_success = ! ( rValue >>= aReturn );
      46             : 
      47       61444 :     if ( no_success )
      48             :     {
      49           0 :         if( ! xConverter.is() )
      50             :         {
      51           0 :             xConverter = script::Converter::create(pShell->m_xContext);
      52             :         }
      53             : 
      54             :         try
      55             :         {
      56           0 :             if( rValue.hasValue() )
      57             :             {
      58             :                 uno::Any aConvertedValue
      59           0 :                     = xConverter->convertTo( rValue,cppu::UnoType<_type_>::get() );
      60           0 :                 no_success = ! ( aConvertedValue >>= aReturn );
      61             :             }
      62             :             else
      63           0 :                 no_success = true;
      64             :         }
      65           0 :         catch (const lang::IllegalArgumentException&)
      66             :         {
      67           0 :             no_success = true;
      68             :         }
      69           0 :         catch (const script::CannotConvertException&)
      70             :         {
      71           0 :             no_success = true;
      72             :         }
      73             :     }
      74       61444 :     return no_success;
      75             : }
      76             : 
      77             : 
      78       81181 : XRow_impl::XRow_impl( shell* pMyShell,const uno::Sequence< uno::Any >& seq )
      79             :     : m_aValueMap( seq ),
      80             :       m_nWasNull(false),
      81             :       m_pMyShell( pMyShell ),
      82             :       m_xProvider( pMyShell->m_pProvider ),
      83       81181 :       m_xTypeConverter( 0 )
      84             : {
      85       81181 : }
      86             : 
      87      162362 : XRow_impl::~XRow_impl()
      88             : {
      89      162362 : }
      90             : 
      91             : 
      92             : sal_Bool SAL_CALL
      93       11174 : XRow_impl::wasNull(
      94             :            void )
      95             :   throw( sdbc::SQLException,
      96             :      uno::RuntimeException, std::exception)
      97             : {
      98       11174 :   return m_nWasNull;
      99             : }
     100             : 
     101             : 
     102             : OUString SAL_CALL
     103        5411 : XRow_impl::getString(
     104             :              sal_Int32 columnIndex )
     105             :   throw( sdbc::SQLException,
     106             :      uno::RuntimeException, std::exception)
     107             : {
     108        5411 :   if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     109           0 :     throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     110        5411 :   OUString  Value;
     111       10822 :   osl::MutexGuard aGuard( m_aMutex );
     112        5411 :   m_nWasNull = ::convert<OUString>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     113       10822 :   return Value;
     114             : }
     115             : 
     116             : sal_Bool SAL_CALL
     117       11117 : XRow_impl::getBoolean(
     118             :     sal_Int32 columnIndex )
     119             :     throw( sdbc::SQLException,
     120             :            uno::RuntimeException, std::exception)
     121             : {
     122       11117 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     123           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     124       11117 :     bool  Value( false );
     125       11117 :     osl::MutexGuard aGuard( m_aMutex );
     126       11117 :     m_nWasNull = ::convert<bool>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     127       11117 :     return Value;
     128             : }
     129             : 
     130             : 
     131             : sal_Int8 SAL_CALL
     132           0 : XRow_impl::getByte(
     133             :     sal_Int32 columnIndex )
     134             :     throw( sdbc::SQLException,
     135             :            uno::RuntimeException, std::exception)
     136             : {
     137           0 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     138           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     139           0 :     sal_Int8  Value( 0 );
     140           0 :     osl::MutexGuard aGuard( m_aMutex );
     141           0 :     m_nWasNull = ::convert<sal_Int8>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     142           0 :     return Value;
     143             : }
     144             : 
     145             : sal_Int16 SAL_CALL
     146           0 : XRow_impl::getShort(
     147             :     sal_Int32 columnIndex )
     148             :     throw( sdbc::SQLException,
     149             :            uno::RuntimeException, std::exception)
     150             : {
     151           0 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     152           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     153           0 :     sal_Int16  Value( 0 );
     154           0 :     osl::MutexGuard aGuard( m_aMutex );
     155           0 :     m_nWasNull = ::convert<sal_Int16>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     156           0 :     return Value;
     157             : }
     158             : 
     159             : 
     160             : sal_Int32 SAL_CALL
     161           0 : XRow_impl::getInt(
     162             :           sal_Int32 columnIndex )
     163             :     throw( sdbc::SQLException,
     164             :            uno::RuntimeException, std::exception)
     165             : {
     166           0 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     167           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     168           0 :     sal_Int32  Value( 0 );
     169           0 :     osl::MutexGuard aGuard( m_aMutex );
     170           0 :     m_nWasNull = ::convert<sal_Int32>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     171           0 :     return Value;
     172             : }
     173             : 
     174             : sal_Int64 SAL_CALL
     175           0 : XRow_impl::getLong(
     176             :            sal_Int32 columnIndex )
     177             :   throw( sdbc::SQLException,
     178             :      uno::RuntimeException, std::exception)
     179             : {
     180           0 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     181           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     182           0 :     sal_Int64  Value( 0 );
     183           0 :     osl::MutexGuard aGuard( m_aMutex );
     184           0 :     m_nWasNull = ::convert<sal_Int64>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     185           0 :     return Value;
     186             : }
     187             : 
     188             : float SAL_CALL
     189           0 : XRow_impl::getFloat(
     190             :     sal_Int32 columnIndex )
     191             :     throw( sdbc::SQLException,
     192             :            uno::RuntimeException, std::exception)
     193             : {
     194           0 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     195           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     196           0 :     float  Value( 0 );
     197           0 :     osl::MutexGuard aGuard( m_aMutex );
     198           0 :     m_nWasNull = ::convert<float>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     199           0 :     return Value;
     200             : }
     201             : 
     202             : double SAL_CALL
     203           0 : XRow_impl::getDouble(
     204             :     sal_Int32 columnIndex )
     205             :     throw( sdbc::SQLException,
     206             :            uno::RuntimeException, std::exception)
     207             : {
     208           0 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     209           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     210           0 :     double  Value( 0 );
     211           0 :     osl::MutexGuard aGuard( m_aMutex );
     212           0 :     m_nWasNull = ::convert<double>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     213           0 :     return Value;
     214             : }
     215             : 
     216             : uno::Sequence< sal_Int8 > SAL_CALL
     217           0 : XRow_impl::getBytes(
     218             :     sal_Int32 columnIndex )
     219             :     throw( sdbc::SQLException,
     220             :            uno::RuntimeException, std::exception)
     221             : {
     222           0 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     223           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     224           0 :     uno::Sequence< sal_Int8 >  Value(0);
     225           0 :     osl::MutexGuard aGuard( m_aMutex );
     226           0 :     m_nWasNull = ::convert<uno::Sequence< sal_Int8 > >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     227           0 :     return Value;
     228             : }
     229             : 
     230             : util::Date SAL_CALL
     231           0 : XRow_impl::getDate(
     232             :     sal_Int32 columnIndex )
     233             :     throw( sdbc::SQLException,
     234             :            uno::RuntimeException, std::exception)
     235             : {
     236           0 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     237           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     238           0 :     util::Date  Value;
     239           0 :     osl::MutexGuard aGuard( m_aMutex );
     240           0 :     m_nWasNull = ::convert<util::Date>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     241           0 :     return Value;
     242             : }
     243             : 
     244             : util::Time SAL_CALL
     245           0 : XRow_impl::getTime(
     246             :     sal_Int32 columnIndex )
     247             :   throw( sdbc::SQLException,
     248             :          uno::RuntimeException, std::exception)
     249             : {
     250           0 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     251           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     252           0 :     util::Time  Value;
     253           0 :     osl::MutexGuard aGuard( m_aMutex );
     254           0 :     m_nWasNull = ::convert<util::Time>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     255           0 :     return Value;
     256             : }
     257             : 
     258             : util::DateTime SAL_CALL
     259           0 : XRow_impl::getTimestamp(
     260             :             sal_Int32 columnIndex )
     261             :   throw( sdbc::SQLException,
     262             :      uno::RuntimeException, std::exception)
     263             : {
     264           0 :   if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     265           0 :     throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     266           0 :   util::DateTime  Value;
     267           0 :   osl::MutexGuard aGuard( m_aMutex );
     268           0 :   m_nWasNull = ::convert<util::DateTime>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     269           0 :   return Value;
     270             : }
     271             : 
     272             : 
     273             : uno::Reference< io::XInputStream > SAL_CALL
     274           0 : XRow_impl::getBinaryStream(
     275             :                sal_Int32 columnIndex )
     276             :   throw( sdbc::SQLException,
     277             :      uno::RuntimeException, std::exception)
     278             : {
     279           0 :   if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     280           0 :     throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     281           0 :   uno::Reference< io::XInputStream >  Value;
     282           0 :   osl::MutexGuard aGuard( m_aMutex );
     283           0 :   m_nWasNull = ::convert<uno::Reference< io::XInputStream > >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     284           0 :   return Value;
     285             : }
     286             : 
     287             : 
     288             : uno::Reference< io::XInputStream > SAL_CALL
     289           0 : XRow_impl::getCharacterStream(
     290             :                   sal_Int32 columnIndex )
     291             :     throw( sdbc::SQLException,
     292             :            uno::RuntimeException, std::exception)
     293             : {
     294           0 :   if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     295           0 :       throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     296           0 :   uno::Reference< io::XInputStream > Value;
     297           0 :   osl::MutexGuard aGuard( m_aMutex );
     298           0 :   m_nWasNull = ::convert< uno::Reference< io::XInputStream> >( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     299           0 :   return Value;
     300             : }
     301             : 
     302             : 
     303             : uno::Any SAL_CALL
     304       44916 : XRow_impl::getObject(
     305             :     sal_Int32 columnIndex,
     306             :     const uno::Reference< container::XNameAccess >& )
     307             :     throw( sdbc::SQLException,
     308             :            uno::RuntimeException, std::exception)
     309             : {
     310       44916 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     311           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     312       44916 :     uno::Any  Value;
     313       89832 :     osl::MutexGuard aGuard( m_aMutex );
     314       44916 :     m_nWasNull = ::convert<uno::Any>( m_pMyShell,m_xTypeConverter,m_aValueMap[ --columnIndex ],Value );
     315       89832 :     return Value;
     316             : }
     317             : 
     318             : uno::Reference< sdbc::XRef > SAL_CALL
     319           0 : XRow_impl::getRef(
     320             :     sal_Int32 columnIndex )
     321             :     throw( sdbc::SQLException,
     322             :            uno::RuntimeException, std::exception)
     323             : {
     324           0 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     325           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     326           0 :     uno::Reference< sdbc::XRef > Value;
     327           0 :     osl::MutexGuard aGuard( m_aMutex );
     328             :     m_nWasNull = ::convert<uno::Reference< sdbc::XRef> >( m_pMyShell,
     329             :                                                           m_xTypeConverter,
     330           0 :                                                           m_aValueMap[ --columnIndex ],
     331           0 :                                                           Value );
     332           0 :     return Value;
     333             : }
     334             : 
     335             : uno::Reference< sdbc::XBlob > SAL_CALL
     336           0 : XRow_impl::getBlob(
     337             :            sal_Int32 columnIndex )
     338             :   throw( sdbc::SQLException,
     339             :      uno::RuntimeException, std::exception)
     340             : {
     341           0 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     342           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     343           0 :     uno::Reference< sdbc::XBlob > Value;
     344           0 :     osl::MutexGuard aGuard( m_aMutex );
     345             :     m_nWasNull = ::convert<uno::Reference< sdbc::XBlob> >( m_pMyShell,
     346             :                                                            m_xTypeConverter,
     347           0 :                                                            m_aValueMap[ --columnIndex ],
     348           0 :                                                            Value );
     349           0 :     return Value;
     350             : }
     351             : 
     352             : uno::Reference< sdbc::XClob > SAL_CALL
     353           0 : XRow_impl::getClob(
     354             :            sal_Int32 columnIndex )
     355             :   throw( sdbc::SQLException,
     356             :      uno::RuntimeException, std::exception)
     357             : {
     358           0 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     359           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     360           0 :     uno::Reference< sdbc::XClob > Value;
     361           0 :     osl::MutexGuard aGuard( m_aMutex );
     362             :     m_nWasNull = ::convert<uno::Reference< sdbc::XClob> >( m_pMyShell,
     363             :                                                            m_xTypeConverter,
     364           0 :                                                            m_aValueMap[ --columnIndex ],
     365           0 :                                                            Value );
     366           0 :     return Value;
     367             : }
     368             : 
     369             : 
     370             : uno::Reference< sdbc::XArray > SAL_CALL
     371           0 : XRow_impl::getArray(
     372             :     sal_Int32 columnIndex )
     373             :     throw( sdbc::SQLException,
     374             :            uno::RuntimeException, std::exception)
     375             : {
     376           0 :     if( columnIndex < 1 || columnIndex > m_aValueMap.getLength() )
     377           0 :         throw sdbc::SQLException( THROW_WHERE, uno::Reference< uno::XInterface >(), OUString(), 0, uno::Any() );
     378           0 :     uno::Reference< sdbc::XArray > Value;
     379           0 :     osl::MutexGuard aGuard( m_aMutex );
     380             :     m_nWasNull = ::convert<uno::Reference< sdbc::XArray> >( m_pMyShell,
     381             :                                                             m_xTypeConverter,
     382           0 :                                                             m_aValueMap[ --columnIndex ],
     383           0 :                                                             Value );
     384           0 :     return Value;
     385             : }
     386             : 
     387             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11