LCOV - code coverage report
Current view: top level - sc/source/core/data - dbdocutl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 24 71 33.8 %
Date: 2012-08-25 Functions: 1 2 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 24 142 16.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <com/sun/star/sdbc/DataType.hpp>
      30                 :            : #include <com/sun/star/sdbc/XRow.hpp>
      31                 :            : 
      32                 :            : #include <svl/zforlist.hxx>
      33                 :            : 
      34                 :            : #include "dbdocutl.hxx"
      35                 :            : #include "document.hxx"
      36                 :            : #include "cell.hxx"
      37                 :            : #include "formula/errorcodes.hxx"
      38                 :            : 
      39                 :            : using namespace ::com::sun::star;
      40                 :            : 
      41                 :            : #define D_TIMEFACTOR              86400.0
      42                 :            : 
      43                 :            : // ----------------------------------------------------------------------------
      44                 :            : 
      45                 :          0 : ScDatabaseDocUtil::StrData::StrData() :
      46                 :          0 :     mbSimpleText(true), mnStrLength(0)
      47                 :            : {
      48                 :          0 : }
      49                 :            : 
      50                 :            : // ----------------------------------------------------------------------------
      51                 :            : 
      52                 :       1320 : void ScDatabaseDocUtil::PutData( ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab,
      53                 :            :                                 const uno::Reference<sdbc::XRow>& xRow, long nRowPos,
      54                 :            :                                 long nType, sal_Bool bCurrency, StrData* pStrData )
      55                 :            : {
      56         [ +  - ]:       1320 :     String aString;
      57                 :       1320 :     double nVal = 0.0;
      58                 :       1320 :     sal_Bool bValue = false;
      59                 :       1320 :     sal_Bool bEmptyFlag = false;
      60                 :       1320 :     sal_Bool bError = false;
      61                 :       1320 :     sal_uLong nFormatIndex = 0;
      62                 :            : 
      63                 :            :     //! wasNull calls only if null value was found?
      64                 :            : 
      65                 :            :     try
      66                 :            :     {
      67   [ -  -  +  -  :       1320 :         switch ( nType )
             -  -  -  - ]
      68                 :            :         {
      69                 :            :             case sdbc::DataType::BIT:
      70                 :            :             case sdbc::DataType::BOOLEAN:
      71                 :            :                 //! use language from doc (here, date/time and currency)?
      72                 :            :                 nFormatIndex = pDoc->GetFormatTable()->GetStandardFormat(
      73 [ #  # ][ #  # ]:          0 :                                     NUMBERFORMAT_LOGICAL, ScGlobal::eLnge );
      74 [ #  # ][ #  # ]:          0 :                 nVal = (xRow->getBoolean(nRowPos) ? 1 : 0);
                 [ #  # ]
      75 [ #  # ][ #  # ]:          0 :                 bEmptyFlag = ( nVal == 0.0 ) && xRow->wasNull();
         [ #  # ][ #  # ]
      76                 :          0 :                 bValue = sal_True;
      77                 :          0 :                 break;
      78                 :            : 
      79                 :            :             case sdbc::DataType::TINYINT:
      80                 :            :             case sdbc::DataType::SMALLINT:
      81                 :            :             case sdbc::DataType::INTEGER:
      82                 :            :             case sdbc::DataType::BIGINT:
      83                 :            :             case sdbc::DataType::FLOAT:
      84                 :            :             case sdbc::DataType::REAL:
      85                 :            :             case sdbc::DataType::DOUBLE:
      86                 :            :             case sdbc::DataType::NUMERIC:
      87                 :            :             case sdbc::DataType::DECIMAL:
      88                 :            :                 //! do the conversion here?
      89 [ #  # ][ #  # ]:          0 :                 nVal = xRow->getDouble(nRowPos);
      90 [ #  # ][ #  # ]:          0 :                 bEmptyFlag = ( nVal == 0.0 ) && xRow->wasNull();
         [ #  # ][ #  # ]
      91                 :          0 :                 bValue = sal_True;
      92                 :          0 :                 break;
      93                 :            : 
      94                 :            :             case sdbc::DataType::CHAR:
      95                 :            :             case sdbc::DataType::VARCHAR:
      96                 :            :             case sdbc::DataType::LONGVARCHAR:
      97 [ +  - ][ +  - ]:       1320 :                 aString = xRow->getString(nRowPos);
                 [ +  - ]
      98 [ +  - ][ +  - ]:       1320 :                 bEmptyFlag = ( aString.Len() == 0 ) && xRow->wasNull();
         [ +  + ][ +  + ]
      99                 :       1320 :                 break;
     100                 :            : 
     101                 :            :             case sdbc::DataType::DATE:
     102                 :            :                 {
     103         [ #  # ]:          0 :                     SvNumberFormatter* pFormTable = pDoc->GetFormatTable();
     104                 :            :                     nFormatIndex = pFormTable->GetStandardFormat(
     105         [ #  # ]:          0 :                                         NUMBERFORMAT_DATE, ScGlobal::eLnge );
     106                 :            : 
     107 [ #  # ][ #  # ]:          0 :                     util::Date aDate = xRow->getDate(nRowPos);
     108                 :            :                     nVal = Date( aDate.Day, aDate.Month, aDate.Year ) -
     109 [ #  # ][ #  # ]:          0 :                                                 *pFormTable->GetNullDate();
     110 [ #  # ][ #  # ]:          0 :                     bEmptyFlag = xRow->wasNull();
     111                 :          0 :                     bValue = sal_True;
     112                 :            :                 }
     113                 :          0 :                 break;
     114                 :            : 
     115                 :            :             case sdbc::DataType::TIME:
     116                 :            :                 {
     117         [ #  # ]:          0 :                     SvNumberFormatter* pFormTable = pDoc->GetFormatTable();
     118                 :            :                     nFormatIndex = pFormTable->GetStandardFormat(
     119         [ #  # ]:          0 :                                         NUMBERFORMAT_TIME, ScGlobal::eLnge );
     120                 :            : 
     121 [ #  # ][ #  # ]:          0 :                     util::Time aTime = xRow->getTime(nRowPos);
     122                 :            :                     nVal = ( aTime.Hours * 3600 + aTime.Minutes * 60 +
     123                 :          0 :                              aTime.Seconds + aTime.HundredthSeconds / 100.0 ) / D_TIMEFACTOR;
     124 [ #  # ][ #  # ]:          0 :                     bEmptyFlag = xRow->wasNull();
     125                 :          0 :                     bValue = sal_True;
     126                 :            :                 }
     127                 :          0 :                 break;
     128                 :            : 
     129                 :            :             case sdbc::DataType::TIMESTAMP:
     130                 :            :                 {
     131         [ #  # ]:          0 :                     SvNumberFormatter* pFormTable = pDoc->GetFormatTable();
     132                 :            :                     nFormatIndex = pFormTable->GetStandardFormat(
     133         [ #  # ]:          0 :                                         NUMBERFORMAT_DATETIME, ScGlobal::eLnge );
     134                 :            : 
     135 [ #  # ][ #  # ]:          0 :                     util::DateTime aStamp = xRow->getTimestamp(nRowPos);
     136                 :            :                     nVal = ( Date( aStamp.Day, aStamp.Month, aStamp.Year ) -
     137         [ #  # ]:          0 :                                                 *pFormTable->GetNullDate() ) +
           [ #  #  #  # ]
     138                 :            :                            ( aStamp.Hours * 3600 + aStamp.Minutes * 60 +
     139                 :          0 :                              aStamp.Seconds + aStamp.HundredthSeconds / 100.0 ) / D_TIMEFACTOR;
     140 [ #  # ][ #  # ]:          0 :                     bEmptyFlag = xRow->wasNull();
     141                 :          0 :                     bValue = sal_True;
     142                 :            :                 }
     143                 :          0 :                 break;
     144                 :            : 
     145                 :            :             case sdbc::DataType::SQLNULL:
     146                 :          0 :                 bEmptyFlag = sal_True;
     147                 :          0 :                 break;
     148                 :            : 
     149                 :            :             case sdbc::DataType::BINARY:
     150                 :            :             case sdbc::DataType::VARBINARY:
     151                 :            :             case sdbc::DataType::LONGVARBINARY:
     152                 :            :             default:
     153                 :          0 :                 bError = sal_True;      // unknown type
     154                 :            :         }
     155                 :            :     }
     156         [ #  # ]:          0 :     catch ( uno::Exception& )
     157                 :            :     {
     158                 :          0 :         bError = sal_True;
     159                 :            :     }
     160                 :            : 
     161 [ -  + ][ #  # ]:       1320 :     if ( bValue && bCurrency )
     162                 :            :         nFormatIndex = pDoc->GetFormatTable()->GetStandardFormat(
     163 [ #  # ][ #  # ]:          0 :                             NUMBERFORMAT_CURRENCY, ScGlobal::eLnge );
     164                 :            : 
     165                 :            :     ScBaseCell* pCell;
     166         [ +  + ]:       1320 :     if (bEmptyFlag)
     167                 :            :     {
     168                 :        874 :         pCell = NULL;
     169         [ +  - ]:        874 :         pDoc->PutCell( nCol, nRow, nTab, pCell );
     170                 :            :     }
     171         [ -  + ]:        446 :     else if (bError)
     172                 :            :     {
     173         [ #  # ]:          0 :         pDoc->SetError( nCol, nRow, nTab, NOTAVAILABLE );
     174                 :            :     }
     175         [ -  + ]:        446 :     else if (bValue)
     176                 :            :     {
     177 [ #  # ][ #  # ]:          0 :         pCell = new ScValueCell( nVal );
     178         [ #  # ]:          0 :         if (nFormatIndex == 0)
     179         [ #  # ]:          0 :             pDoc->PutCell( nCol, nRow, nTab, pCell );
     180                 :            :         else
     181         [ #  # ]:          0 :             pDoc->PutCell( nCol, nRow, nTab, pCell, nFormatIndex );
     182                 :            :     }
     183                 :            :     else
     184                 :            :     {
     185         [ +  + ]:        446 :         if (aString.Len())
     186                 :            :         {
     187 [ +  - ][ +  - ]:        420 :             pCell = ScBaseCell::CreateTextCell( aString, pDoc );
     188         [ -  + ]:        420 :             if (pStrData)
     189                 :            :             {
     190                 :          0 :                 pStrData->mbSimpleText = pCell->GetCellType() != CELLTYPE_EDIT;
     191                 :          0 :                 pStrData->mnStrLength = aString.Len();
     192                 :            :             }
     193                 :            :         }
     194                 :            :         else
     195                 :         26 :             pCell = NULL;
     196         [ +  - ]:        446 :         pDoc->PutCell( nCol, nRow, nTab, pCell );
     197         [ +  - ]:       1320 :     }
     198                 :       1320 : }
     199                 :            : 
     200                 :            : 
     201                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10