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

Generated by: LCOV version 1.10