LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/connectivity - dbconversion.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 1 0.0 %
Date: 2013-07-09 Functions: 0 1 0.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 _DBHELPER_DBCONVERSION_HXX_
      21             : #define _DBHELPER_DBCONVERSION_HXX_
      22             : 
      23             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      24             : #include <com/sun/star/util/Date.hpp>
      25             : #include <com/sun/star/uno/Reference.hxx>
      26             : #include "connectivity/dbtoolsdllapi.hxx"
      27             : 
      28             : // forward declarations
      29             : namespace com
      30             : {
      31             :     namespace sun
      32             :     {
      33             :         namespace star
      34             :         {
      35             :             namespace lang
      36             :             {
      37             :                 struct Locale;
      38             :             }
      39             :             namespace sdb
      40             :             {
      41             :                 class XColumn;
      42             :                 class XColumnUpdate;
      43             :             }
      44             :             namespace sdbc
      45             :             {
      46             :                 class SQLException;
      47             :             }
      48             :             namespace beans
      49             :             {
      50             :                 class XPropertySet;
      51             :             }
      52             :             namespace util
      53             :             {
      54             :                 class XNumberFormatter;
      55             :                 class XNumberFormatsSupplier;
      56             :                 struct Time;
      57             :                 struct DateTime;
      58             :             }
      59             :             namespace script
      60             :             {
      61             :                 class XTypeConverter;
      62             :             }
      63             :         }
      64             :     }
      65             : }
      66             : 
      67             : //.........................................................................
      68             : namespace dbtools
      69             : {
      70             : //.........................................................................
      71             : 
      72             :     class OOO_DLLPUBLIC_DBTOOLS DBTypeConversion
      73             :     {
      74             :     public:
      75             :         static ::com::sun::star::util::Date getStandardDate();
      76             :         static void setValue(const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumnUpdate>& xVariant,
      77             :                                     const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter>& xFormatter,
      78             :                                     const ::com::sun::star::util::Date& rNullDate,
      79             :                                     const OUString& rString,
      80             :                                     sal_Int32 nKey,
      81             :                                     sal_Int16 nFieldType,
      82             :                                     sal_Int16 nKeyType) throw(::com::sun::star::lang::IllegalArgumentException);
      83             : 
      84             :         static void setValue(const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumnUpdate>& xVariant,
      85             :                              const ::com::sun::star::util::Date& rNullDate,
      86             :                              const double& rValue,
      87             :                              sal_Int16 nKeyType) throw(::com::sun::star::lang::IllegalArgumentException);
      88             : 
      89             :         static double getValue( const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumn>& xVariant, const ::com::sun::star::util::Date& rNullDate );
      90             : 
      91             :         // get the columnvalue as string with a default format given by the column or a default format
      92             :         // for the type
      93             :         static OUString getFormattedValue(
      94             :                                         const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xColumn,
      95             :                                         const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter>& xFormatter,
      96             :                                         const ::com::sun::star::lang::Locale& _rLocale,
      97             :                                         const ::com::sun::star::util::Date& rNullDate);
      98             : 
      99             :         static OUString getFormattedValue(
     100             :                                         const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XColumn>& _xColumn,
     101             :                                         const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter>& xFormatter,
     102             :                                         const ::com::sun::star::util::Date& rNullDate,
     103             :                                         sal_Int32 nKey,
     104             :                                         sal_Int16 nKeyType);
     105             : 
     106             :         static ::com::sun::star::util::Date     toDate(double dVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate());
     107             :         static ::com::sun::star::util::Date     toDate(const OUString& _sSQLDate);
     108             :         static ::com::sun::star::util::Time     toTime(double dVal);
     109             :         static ::com::sun::star::util::Time     toTime(const OUString& _sSQLDate);
     110             :         static ::com::sun::star::util::DateTime toDateTime(double dVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate());
     111             :         static ::com::sun::star::util::DateTime toDateTime(const OUString& _sSQLDate);
     112             : 
     113             : 
     114             :         // TODO: consider removing getMsFromTime
     115             :         static sal_Int32 getMsFromTime(const ::com::sun::star::util::Time& rVal);
     116             :         static sal_Int64 getNsFromTime(const ::com::sun::star::util::Time& rVal);
     117             : 
     118             :         static sal_Int32 toDays(const ::com::sun::star::util::Date& _rVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate());
     119             : 
     120             :         static double   toDouble(const ::com::sun::star::util::Date& rVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate());
     121             :         static double   toDouble(const ::com::sun::star::util::Time& rVal);
     122             :         static double   toDouble(const ::com::sun::star::util::DateTime& rVal, const ::com::sun::star::util::Date& _rNullDate = getStandardDate());
     123             : 
     124             :         static sal_Int32    toINT32(const ::com::sun::star::util::Date& rVal);
     125             :         static sal_Int64    toINT64(const ::com::sun::star::util::Time& rVal);
     126             : 
     127             :         static ::com::sun::star::util::Date toDate(sal_Int32 _nVal);
     128             :         static ::com::sun::star::util::Time toTime(sal_Int64 _nVal);
     129             : 
     130             :         /** convert a double which is a date value relative to a given fixed date into a date value relative
     131             :             to the standard db null date.
     132             :         */
     133             :         static double toStandardDbDate(const ::com::sun::star::util::Date& _rNullDate, double _rVal) { return _rVal + toDays(_rNullDate); }
     134             :         /** convert a double which is a date value relative to the standard db null date into a date value relative
     135             :             to a given fixed date.
     136             :         */
     137           0 :         static double toNullDate(const ::com::sun::star::util::Date& _rNullDate, double _rVal) { return _rVal - toDays(_rNullDate); }
     138             : 
     139             :         // return the date from the numberformatsupplier or the STANDARD_DATE (1900,1,1)
     140             :         static ::com::sun::star::util::Date getNULLDate(const ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > &xSupplier);
     141             : 
     142             :         // return the date in the format %04d-%02d-%02d
     143             :         static OUString toDateString(const ::com::sun::star::util::Date& rDate);
     144             :         // return the time in the format %02d:%02d:%02d
     145             :         static OUString toTimeStringS(const ::com::sun::star::util::Time& rTime);
     146             :         // return the time in the format %02d:%02d:%02d.%09d
     147             :         static OUString toTimeString(const ::com::sun::star::util::Time& rTime);
     148             :         // return the DateTime in the format %04d-%02d-%02d %02d:%02d:%02d.%09d
     149             :         static OUString toDateTimeString(const ::com::sun::star::util::DateTime& _rDateTime);
     150             :         // return the any in an sql standard format
     151             :         static OUString toSQLString(sal_Int32 eType, const ::com::sun::star::uno::Any& _rVal, sal_Bool bQuote,
     152             :             const ::com::sun::star::uno::Reference< ::com::sun::star::script::XTypeConverter >&  _rxTypeConverter);
     153             : 
     154             :         /** converts a Unicode string into a 8-bit string, using the given encoding
     155             : 
     156             :             @param _rSource
     157             :                 the source string to convert
     158             :             @param _rDest
     159             :                 the destination string
     160             :             @param _eEncoding
     161             :                 the encoding to use for the conversion
     162             : 
     163             :             @throws com::sun::star::sdbc::SQLException
     164             :                 if the given string contains characters which are not convertible using the given encoding
     165             :                 The SQLState of the exception will be set to 22018 ("Invalid character value for cast specification")
     166             : 
     167             :             @return
     168             :                 the length of the converted string
     169             :         */
     170             :         static sal_Int32 convertUnicodeString(
     171             :             const OUString& _rSource,
     172             :             OString&  _rDest,
     173             :             rtl_TextEncoding _eEncoding
     174             :         )
     175             :             SAL_THROW((::com::sun::star::sdbc::SQLException));
     176             : 
     177             :         /** converts a Unicode string into a 8-bit string, using the given encoding
     178             : 
     179             :             @param _rSource
     180             :                 the source string to convert
     181             : 
     182             :             @param _rDest
     183             :                 the destination string
     184             : 
     185             :             @param _nMaxLen
     186             :                 the maximum length of the destination string
     187             : 
     188             :             @param _eEncoding
     189             :                 the encoding to use for the conversion
     190             : 
     191             :             @throws com::sun::star::sdbc::SQLException
     192             :                 if convertUnicodeString, which is called internally, throws such an exception
     193             : 
     194             :             @throws com::sun::star::sdbc::SQLException
     195             :                 if the conversion results in a string which is longer than _nMaxLen
     196             : 
     197             :             @return
     198             :                 the length of the converted string
     199             :         */
     200             :         static sal_Int32 convertUnicodeStringToLength(
     201             :             const OUString& _rSource,
     202             :             OString&  _rDest,
     203             :             sal_Int32 _nMaxLen,
     204             :             rtl_TextEncoding _eEncoding
     205             :        )
     206             :             SAL_THROW((::com::sun::star::sdbc::SQLException));
     207             :     };
     208             : 
     209             : //.........................................................................
     210             : }   // namespace dbtools
     211             : //.........................................................................
     212             : 
     213             : #endif // _DBHELPER_DBCONVERSION_HXX_
     214             : 
     215             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10