LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/connectivity - FValue.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 43 137 31.4 %
Date: 2012-12-27 Functions: 21 75 28.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef _CONNECTIVITY_FILE_VALUE_HXX_
      21             : #define _CONNECTIVITY_FILE_VALUE_HXX_
      22             : 
      23             : #include <com/sun/star/sdbc/DataType.hpp>
      24             : #include <com/sun/star/uno/Any.hxx>
      25             : #include <rtl/ustring.hxx>
      26             : #include <osl/diagnose.h>
      27             : #include <comphelper/stl_types.hxx>
      28             : #include <rtl/ref.hxx>
      29             : #include "connectivity/dbtoolsdllapi.hxx"
      30             : #include "connectivity/CommonTools.hxx"
      31             : #include <com/sun/star/util/DateTime.hpp>
      32             : #include <com/sun/star/util/Date.hpp>
      33             : #include <com/sun/star/util/Time.hpp>
      34             : #include <com/sun/star/uno/Sequence.hxx>
      35             : #include <com/sun/star/sdbc/XRow.hpp>
      36             : #include <com/sun/star/sdb/XColumn.hpp>
      37             : 
      38             : namespace connectivity
      39             : {
      40             :     namespace detail
      41             :     {
      42             :         class IValueSource;
      43             :     }
      44             : 
      45             :     class OOO_DLLPUBLIC_DBTOOLS ORowSetValue
      46             :     {
      47             :         union
      48             :         {
      49             :             sal_Bool        m_bBool;
      50             :             sal_Int8        m_nInt8;
      51             :             sal_Int16       m_nInt16;
      52             :             sal_Int32       m_nInt32;
      53             :             rtl_uString*    m_pString;
      54             : 
      55             :             void*           m_pValue;           // can contains double, etc
      56             :         } m_aValue;
      57             : 
      58             :         sal_Int32           m_eTypeKind;        // the database type
      59             :         sal_Bool            m_bNull     : 1;    // value is null
      60             :         sal_Bool            m_bBound    : 1;    // is bound
      61             :         sal_Bool            m_bModified : 1;    // value was changed
      62             :         sal_Bool            m_bSigned   : 1;    // value is signed
      63             : 
      64             :         void free();
      65             : 
      66             :     public:
      67         170 :         ORowSetValue()
      68             :             :m_eTypeKind(::com::sun::star::sdbc::DataType::VARCHAR)
      69             :             ,m_bNull(sal_True)
      70             :             ,m_bBound(sal_True)
      71             :             ,m_bModified(sal_False)
      72         170 :             ,m_bSigned(sal_True)
      73             :         {
      74         170 :             m_aValue.m_pString = NULL;
      75         170 :         }
      76             : 
      77        1164 :         ORowSetValue(const ORowSetValue& _rRH)
      78             :             :m_eTypeKind(::com::sun::star::sdbc::DataType::VARCHAR)
      79             :             ,m_bNull(sal_True)
      80             :             ,m_bBound(sal_True)
      81             :             ,m_bModified(sal_False)
      82        1164 :             ,m_bSigned(sal_True)
      83             :         {
      84        1164 :             m_aValue.m_pString = NULL;
      85        1164 :             operator=(_rRH);
      86        1164 :         }
      87             : 
      88         550 :         ORowSetValue(const ::rtl::OUString& _rRH)
      89             :             :m_eTypeKind(::com::sun::star::sdbc::DataType::VARCHAR)
      90             :             ,m_bNull(sal_True)
      91             :             ,m_bBound(sal_True)
      92             :             ,m_bModified(sal_False)
      93         550 :             ,m_bSigned(sal_True)
      94             :         {
      95         550 :             m_aValue.m_pString = NULL;
      96         550 :             operator=(_rRH);
      97         550 :         }
      98             : 
      99           0 :         ORowSetValue(const double& _rRH)
     100             :             :m_eTypeKind(::com::sun::star::sdbc::DataType::DOUBLE)
     101             :             ,m_bNull(sal_True)
     102             :             ,m_bBound(sal_True)
     103             :             ,m_bModified(sal_False)
     104           0 :             ,m_bSigned(sal_True)
     105             :         {
     106           0 :             m_aValue.m_pString = NULL;
     107           0 :             operator=(_rRH);
     108           0 :         }
     109             : 
     110           0 :         ORowSetValue(const float& _rRH)
     111             :             :m_eTypeKind(::com::sun::star::sdbc::DataType::FLOAT)
     112             :             ,m_bNull(sal_True)
     113             :             ,m_bBound(sal_True)
     114             :             ,m_bModified(sal_False)
     115           0 :             ,m_bSigned(sal_True)
     116             :         {
     117           0 :             m_aValue.m_pString = NULL;
     118           0 :             operator=(_rRH);
     119           0 :         }
     120             : 
     121           0 :         ORowSetValue(const sal_Int8& _rRH)
     122             :             :m_eTypeKind(::com::sun::star::sdbc::DataType::TINYINT)
     123             :             ,m_bNull(sal_True)
     124             :             ,m_bBound(sal_True)
     125             :             ,m_bModified(sal_False)
     126           0 :             ,m_bSigned(sal_True)
     127             :         {
     128           0 :             m_aValue.m_pString = NULL;
     129           0 :             operator=(_rRH);
     130           0 :         }
     131          76 :         ORowSetValue(const sal_Int16& _rRH)
     132             :             :m_eTypeKind(::com::sun::star::sdbc::DataType::SMALLINT)
     133             :             ,m_bNull(sal_True)
     134             :             ,m_bBound(sal_True)
     135             :             ,m_bModified(sal_False)
     136          76 :             ,m_bSigned(sal_True)
     137             :         {
     138          76 :             m_aValue.m_pString = NULL;
     139          76 :             operator=(_rRH);
     140          76 :         }
     141         528 :         ORowSetValue(const sal_Int32& _rRH)
     142             :             :m_eTypeKind(::com::sun::star::sdbc::DataType::INTEGER)
     143             :             ,m_bNull(sal_True)
     144             :             ,m_bBound(sal_True)
     145             :             ,m_bModified(sal_False)
     146         528 :             ,m_bSigned(sal_True)
     147             :         {
     148         528 :             m_aValue.m_pString = NULL;
     149         528 :             operator=(_rRH);
     150         528 :         }
     151           0 :         ORowSetValue(const sal_Int64& _rRH)
     152             :             :m_eTypeKind(::com::sun::star::sdbc::DataType::BIGINT)
     153             :             ,m_bNull(sal_True)
     154             :             ,m_bBound(sal_True)
     155             :             ,m_bModified(sal_False)
     156           0 :             ,m_bSigned(sal_True)
     157             :         {
     158           0 :             m_aValue.m_pString = NULL;
     159           0 :             operator=(_rRH);
     160           0 :         }
     161             : 
     162           0 :         ORowSetValue(const sal_Bool& _rRH)
     163             :             :m_eTypeKind(::com::sun::star::sdbc::DataType::BIT)
     164             :             ,m_bNull(sal_True)
     165             :             ,m_bBound(sal_True)
     166             :             ,m_bModified(sal_False)
     167           0 :             ,m_bSigned(sal_True)
     168             :         {
     169           0 :             m_aValue.m_pString = NULL;
     170           0 :             operator=(_rRH);
     171           0 :         }
     172             : 
     173           0 :         ORowSetValue(const ::com::sun::star::util::Date& _rRH)
     174             :             :m_eTypeKind(::com::sun::star::sdbc::DataType::DATE)
     175             :             ,m_bNull(sal_True)
     176             :             ,m_bBound(sal_True)
     177             :             ,m_bModified(sal_False)
     178           0 :             ,m_bSigned(sal_True)
     179             :         {
     180           0 :             m_aValue.m_pString = NULL;
     181           0 :             operator=(_rRH);
     182           0 :         }
     183             : 
     184           0 :         ORowSetValue(const ::com::sun::star::util::Time& _rRH)
     185             :             :m_eTypeKind(::com::sun::star::sdbc::DataType::TIME)
     186             :             ,m_bNull(sal_True)
     187             :             ,m_bBound(sal_True)
     188             :             ,m_bModified(sal_False)
     189           0 :             ,m_bSigned(sal_True)
     190             :         {
     191           0 :             m_aValue.m_pString = NULL;
     192           0 :             operator=(_rRH);
     193           0 :         }
     194             : 
     195           0 :         ORowSetValue(const ::com::sun::star::util::DateTime& _rRH)
     196             :             :m_eTypeKind(::com::sun::star::sdbc::DataType::TIMESTAMP)
     197             :             ,m_bNull(sal_True)
     198             :             ,m_bBound(sal_True)
     199             :             ,m_bModified(sal_False)
     200           0 :             ,m_bSigned(sal_True)
     201             :         {
     202           0 :             m_aValue.m_pString = NULL;
     203           0 :             operator=(_rRH);
     204           0 :         }
     205             : 
     206           0 :         ORowSetValue(const ::com::sun::star::uno::Sequence<sal_Int8>& _rRH)
     207             :             :m_eTypeKind(::com::sun::star::sdbc::DataType::LONGVARBINARY)
     208             :             ,m_bNull(sal_True)
     209             :             ,m_bBound(sal_True)
     210             :             ,m_bModified(sal_False)
     211           0 :             ,m_bSigned(sal_True)
     212             :         {
     213           0 :             m_aValue.m_pString = NULL;
     214           0 :             operator=(_rRH);
     215           0 :         }
     216             : 
     217        2408 :         ~ORowSetValue()
     218             :         {
     219        2408 :             free();
     220        2408 :         }
     221             : 
     222             :         inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW(())
     223             :             { return ::rtl_allocateMemory( nSize ); }
     224             :         inline static void * SAL_CALL operator new( size_t,void* _pHint ) SAL_THROW(())
     225             :             { return _pHint; }
     226             :         inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW(())
     227             :             { ::rtl_freeMemory( pMem ); }
     228             :         inline static void SAL_CALL operator delete( void *,void* ) SAL_THROW(())
     229             :             {  }
     230             : 
     231             :         ORowSetValue& operator=(const ORowSetValue& _rRH);
     232             : 
     233             :         // simple types
     234             :         ORowSetValue& operator=(const sal_Bool _rRH);
     235             :         ORowSetValue& operator=(const sal_Int8& _rRH);
     236             :         ORowSetValue& operator=(const sal_Int16& _rRH);
     237             :         ORowSetValue& operator=(const sal_Int32& _rRH);
     238             :         ORowSetValue& operator=(const sal_Int64& _rRH);
     239             :         ORowSetValue& operator=(const double& _rRH);
     240             :         ORowSetValue& operator=(const float& _rRH);
     241             : 
     242             :         // ADT's
     243             :         ORowSetValue& operator=(const ::com::sun::star::util::Date& _rRH);
     244             :         ORowSetValue& operator=(const ::com::sun::star::util::Time& _rRH);
     245             :         ORowSetValue& operator=(const ::com::sun::star::util::DateTime& _rRH);
     246             : 
     247             :         ORowSetValue& operator=(const ::rtl::OUString& _rRH);
     248             :         // the type isn't set it will be set to VARCHAR if the type is different change it
     249             :         ORowSetValue& operator=(const ::com::sun::star::uno::Sequence<sal_Int8>& _rRH);
     250             :         // we the possiblity to save a any for bookmarks
     251             :         ORowSetValue& operator=(const ::com::sun::star::uno::Any& _rAny);
     252             : 
     253           0 :         operator sal_Bool() const   {   return isNull() ? sal_False : getBool();    }
     254           0 :         operator sal_Int8() const   {   return isNull() ? static_cast<sal_Int8>(0) : getInt8(); }
     255           0 :         operator sal_Int16() const  {   return isNull() ? static_cast<sal_Int16>(0) : getInt16();   }
     256         683 :         operator sal_Int32() const  {   return isNull() ? 0         : getInt32();   }
     257           0 :         operator sal_Int64() const  {   return isNull() ? 0         : getLong();    }
     258           0 :         operator float() const      {   return isNull() ? (float)0.0: getFloat();   }
     259           0 :         operator double() const     {   return isNull() ? 0.0       : getDouble();  }
     260             : 
     261         658 :         operator ::rtl::OUString() const
     262             :         {
     263         658 :             return isNull() ? ::rtl::OUString() : getString();
     264             :         }
     265             : 
     266           0 :         operator ::com::sun::star::util::Date() const
     267             :         {
     268           0 :             return isNull() ? ::com::sun::star::util::Date() : getDate();
     269             :         }
     270             : 
     271           0 :         operator ::com::sun::star::util::Time() const
     272             :         {
     273           0 :             return isNull() ? ::com::sun::star::util::Time() : getTime();
     274             :         }
     275             : 
     276           0 :         operator ::com::sun::star::util::DateTime() const
     277             :         {
     278           0 :             return isNull() ? ::com::sun::star::util::DateTime() : getDateTime();
     279             :         }
     280             : 
     281           0 :         operator ::com::sun::star::uno::Sequence<sal_Int8>() const
     282             :         {
     283           0 :             return isNull() ? ::com::sun::star::uno::Sequence<sal_Int8>() : getSequence();
     284             :         }
     285             : 
     286             :         bool operator==(const ORowSetValue& _rRH) const;
     287           0 :         bool operator!=(const ORowSetValue& _rRH) const
     288             :         {
     289           0 :             return !( *this == _rRH );
     290             :         }
     291             : 
     292        1374 :         sal_Bool    isNull() const
     293             :         {
     294        1374 :             return m_bNull;
     295             :         }
     296           0 :         void        setNull()
     297             :         {
     298           0 :             free();
     299           0 :             m_bNull = sal_True;
     300           0 :             m_aValue.m_pString = NULL;
     301           0 :         }
     302             : 
     303         518 :         sal_Bool    isBound() const                     { return m_bBound;      }
     304        1243 :         void        setBound(sal_Bool _bBound)          { m_bBound = _bBound ? 1 : 0; }
     305             : 
     306           0 :         sal_Bool    isModified() const                  { return m_bModified;   }
     307           0 :         void        setModified(sal_Bool _bMod=sal_True){ m_bModified = _bMod ? 1 : 0;  }
     308             : 
     309           0 :         sal_Bool    isSigned() const                    { return m_bSigned; }
     310             :         void        setSigned(sal_Bool _bMod=sal_True);
     311             : 
     312        1044 :         sal_Int32   getTypeKind() const                 { return m_eTypeKind;   }
     313             :         void        setTypeKind(sal_Int32 _eType);
     314             : 
     315             :         // before calling one of this methods, be sure that the value is not null
     316             :         void*           getValue()  const               { OSL_ENSURE(m_bBound,"Value is not bound!");return m_aValue.m_pValue;              }
     317             :         sal_Bool        getBool()   const;
     318             :         sal_Int8        getInt8()   const;
     319             :         sal_Int16       getInt16()  const;
     320             :         sal_Int32       getInt32()  const;
     321             :         sal_Int64       getLong()   const;
     322             :         double          getDouble() const;
     323             :         float           getFloat() const;
     324             : 
     325             :         ::rtl::OUString getString() const;      // makes a automatic conversion if type isn't a string
     326             :         ::com::sun::star::util::Date                getDate()       const;
     327             :         ::com::sun::star::util::Time                getTime()       const;
     328             :         ::com::sun::star::util::DateTime            getDateTime()   const;
     329             :         ::com::sun::star::uno::Sequence<sal_Int8>   getSequence()   const;
     330             :         // only use for anys
     331           0 :         ::com::sun::star::uno::Any                  getAny()        const { return *(::com::sun::star::uno::Any*)m_aValue.m_pValue; }
     332             :         ::com::sun::star::uno::Any                  makeAny()       const;
     333             : 
     334             :         /**
     335             :             fetches a single value out of the row
     336             :             @param _nPos    the current column position
     337             :             @param _nType   the type of the current column
     338             :             @param _xRow    the row where to fetch the data from
     339             :         */
     340             :         void fill(sal_Int32 _nPos,
     341             :                   sal_Int32 _nType,
     342             :                   const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow>& _xRow);
     343             : 
     344             :         /**
     345             :             fetches a single value out of the row
     346             :             @param _nPos    the current column position
     347             :             @param _nType   the type of the current column
     348             :             @param _bNullable   if true then it will be checked if the result could be NULL, otherwise not.
     349             :             @param _xRow    the row where to fetch the data from
     350             :         */
     351             :         void fill(sal_Int32 _nPos,
     352             :                   sal_Int32 _nType,
     353             :                   sal_Bool  _bNullable,
     354             :                   const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow>& _xRow);
     355             : 
     356             :         void fill(const ::com::sun::star::uno::Any& _rValue);
     357             : 
     358             :         void fill( const sal_Int32 _nType,
     359             :                    const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumn >& _rxColumn );
     360             : 
     361             :     private:
     362             :         void impl_fill( const sal_Int32 _nType, sal_Bool _bNullable, const detail::IValueSource& _rValueSource );
     363             :     };
     364             : 
     365             :     /// ORowSetValueDecorator decorates a ORowSetValue so the value is "refcounted"
     366        2330 :     class OOO_DLLPUBLIC_DBTOOLS ORowSetValueDecorator : public ::salhelper::SimpleReferenceObject
     367             :     {
     368             :         ORowSetValue    m_aValue;   // my own value
     369             :     public:
     370           1 :         ORowSetValueDecorator(){m_aValue.setBound(sal_True);}
     371        1164 :         ORowSetValueDecorator(const ORowSetValue& _aValue) : m_aValue(_aValue){m_aValue.setBound(sal_True);}
     372             :         ORowSetValueDecorator& operator=(const ORowSetValue& _aValue);
     373             : 
     374        1268 :         inline operator const ORowSetValue&()   const               { return m_aValue; }
     375           0 :         inline bool operator ==( const ORowSetValue & _rRH )        { return m_aValue == _rRH; }
     376          52 :         inline const ORowSetValue& getValue()   const               { return m_aValue; }
     377           0 :         inline ORowSetValue& get()                                  { return m_aValue; }
     378           0 :         inline void setValue(const ORowSetValue& _aValue)           { m_aValue = _aValue; }
     379           0 :         inline void setNull()                                       { m_aValue.setNull(); }
     380           0 :         inline void setBound(sal_Bool _bBound )                     { m_aValue.setBound(_bBound);}
     381           0 :         inline sal_Bool isBound( ) const                            { return m_aValue.isBound();}
     382           0 :         inline void setTypeKind(sal_Int32 _nType)                   { m_aValue.setTypeKind(_nType); }
     383           0 :         inline void setModified(sal_Bool _bModified)                { m_aValue.setModified(_bModified); }
     384             : 
     385             :     };
     386             :     typedef ::rtl::Reference<ORowSetValueDecorator> ORowSetValueDecoratorRef;
     387             : 
     388             :     // -------------------------------------------------------------------------
     389             :     /// TSetBound is a unary_function to set the bound value with e.q. for_each call
     390             :     struct OOO_DLLPUBLIC_DBTOOLS TSetBound : ::std::unary_function<ORowSetValue,void>
     391             :     {
     392             :         sal_Bool m_bBound;
     393           2 :         TSetBound(sal_Bool _bBound) : m_bBound(_bBound){}
     394          74 :         void operator()(ORowSetValue& _rValue) const { _rValue.setBound(m_bBound); }
     395             : 
     396             :     };
     397             : 
     398             :     // -------------------------------------------------------------------------
     399             :     /// TSetBound is a unary_function to set the bound value with e.q. for_each call
     400             :     struct OOO_DLLPUBLIC_DBTOOLS TSetRefBound : ::std::unary_function<ORowSetValueDecoratorRef,void>
     401             :     {
     402             :         sal_Bool m_bBound;
     403           0 :         TSetRefBound(sal_Bool _bBound) : m_bBound(_bBound){}
     404           0 :         void operator()(ORowSetValueDecoratorRef& _rValue) const { _rValue->setBound(m_bBound); }
     405             : 
     406             :     };
     407             : 
     408             :     // ----------------------------------------------------------------------------
     409             :     // Vector for file based rows
     410             :     // ----------------------------------------------------------------------------
     411           0 :     template< class VectorVal > class  ODeleteVector : public connectivity::ORowVector< VectorVal >
     412             :     {
     413             :         sal_Bool    m_bDeleted;
     414             :     public:
     415           0 :         ODeleteVector()             : connectivity::ORowVector< VectorVal >()       ,m_bDeleted(sal_False)  {}
     416           2 :         ODeleteVector(size_t _st)   : connectivity::ORowVector< VectorVal >(_st)    ,m_bDeleted(sal_False)  {}
     417             : 
     418           0 :         sal_Bool    isDeleted() const               { return m_bDeleted;        }
     419           0 :         void        setDeleted(sal_Bool _bDeleted)  { m_bDeleted = _bDeleted;   }
     420             :     };
     421             : 
     422             :     typedef ODeleteVector< ORowSetValue >               OValueVector;
     423             : 
     424           0 :     class OOO_DLLPUBLIC_DBTOOLS OValueRefVector : public ODeleteVector< ORowSetValueDecoratorRef >
     425             :     {
     426             :     public:
     427           0 :         OValueRefVector(){}
     428           0 :         OValueRefVector(size_t _st) : ODeleteVector< ORowSetValueDecoratorRef >(_st)
     429             :         {
     430           0 :             for(OValueRefVector::Vector::iterator aIter = get().begin() ; aIter != get().end() ;++aIter)
     431           0 :                 *aIter = new ORowSetValueDecorator;
     432           0 :         }
     433             :     };
     434             : 
     435             : #define SQL_NO_PARAMETER (SAL_MAX_UINT32)
     436           0 :     class OAssignValues : public OValueRefVector
     437             :     {
     438             :         ::std::vector<sal_Int32> m_nParameterIndexes;
     439             :     public:
     440             :         OAssignValues() : m_nParameterIndexes(1,SQL_NO_PARAMETER){}
     441           0 :         OAssignValues(Vector::size_type n) : OValueRefVector(n),m_nParameterIndexes(n+1,SQL_NO_PARAMETER){}
     442             : 
     443           0 :         void setParameterIndex(sal_Int32 _nId,sal_Int32 _nParameterIndex) { m_nParameterIndexes[_nId] = _nParameterIndex;}
     444           0 :         sal_Int32 getParameterIndex(sal_Int32 _nId) const { return m_nParameterIndexes[_nId]; }
     445             :     };
     446             : 
     447             :     typedef ::rtl::Reference< OAssignValues > ORefAssignValues;
     448             : 
     449             : 
     450             : 
     451             :     typedef ::rtl::Reference< OValueVector >                    OValueRow;
     452             :     typedef ::rtl::Reference< OValueRefVector >             OValueRefRow;
     453             : }
     454             : 
     455             : #endif // #ifndef _CONNECTIVITY_FILE_VALUE_HXX_
     456             : 
     457             : 
     458             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10