LCOV - code coverage report
Current view: top level - libreoffice/sc/source/core/data - dbdocutl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 71 0.0 %
Date: 2012-12-27 Functions: 0 2 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             : #include <com/sun/star/sdbc/DataType.hpp>
      21             : #include <com/sun/star/sdbc/XRow.hpp>
      22             : 
      23             : #include <svl/zforlist.hxx>
      24             : 
      25             : #include "dbdocutl.hxx"
      26             : #include "document.hxx"
      27             : #include "cell.hxx"
      28             : #include "formula/errorcodes.hxx"
      29             : 
      30             : using namespace ::com::sun::star;
      31             : 
      32             : #define D_TIMEFACTOR              86400.0
      33             : 
      34             : // ----------------------------------------------------------------------------
      35             : 
      36           0 : ScDatabaseDocUtil::StrData::StrData() :
      37           0 :     mbSimpleText(true), mnStrLength(0)
      38             : {
      39           0 : }
      40             : 
      41             : // ----------------------------------------------------------------------------
      42             : 
      43           0 : void ScDatabaseDocUtil::PutData( ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab,
      44             :                                 const uno::Reference<sdbc::XRow>& xRow, long nRowPos,
      45             :                                 long nType, sal_Bool bCurrency, StrData* pStrData )
      46             : {
      47           0 :     String aString;
      48           0 :     double nVal = 0.0;
      49           0 :     sal_Bool bValue = false;
      50           0 :     sal_Bool bEmptyFlag = false;
      51           0 :     sal_Bool bError = false;
      52           0 :     sal_uLong nFormatIndex = 0;
      53             : 
      54             :     //! wasNull calls only if null value was found?
      55             : 
      56             :     try
      57             :     {
      58           0 :         switch ( nType )
      59             :         {
      60             :             case sdbc::DataType::BIT:
      61             :             case sdbc::DataType::BOOLEAN:
      62             :                 //! use language from doc (here, date/time and currency)?
      63             :                 nFormatIndex = pDoc->GetFormatTable()->GetStandardFormat(
      64           0 :                                     NUMBERFORMAT_LOGICAL, ScGlobal::eLnge );
      65           0 :                 nVal = (xRow->getBoolean(nRowPos) ? 1 : 0);
      66           0 :                 bEmptyFlag = ( nVal == 0.0 ) && xRow->wasNull();
      67           0 :                 bValue = sal_True;
      68           0 :                 break;
      69             : 
      70             :             case sdbc::DataType::TINYINT:
      71             :             case sdbc::DataType::SMALLINT:
      72             :             case sdbc::DataType::INTEGER:
      73             :             case sdbc::DataType::BIGINT:
      74             :             case sdbc::DataType::FLOAT:
      75             :             case sdbc::DataType::REAL:
      76             :             case sdbc::DataType::DOUBLE:
      77             :             case sdbc::DataType::NUMERIC:
      78             :             case sdbc::DataType::DECIMAL:
      79             :                 //! do the conversion here?
      80           0 :                 nVal = xRow->getDouble(nRowPos);
      81           0 :                 bEmptyFlag = ( nVal == 0.0 ) && xRow->wasNull();
      82           0 :                 bValue = sal_True;
      83           0 :                 break;
      84             : 
      85             :             case sdbc::DataType::CHAR:
      86             :             case sdbc::DataType::VARCHAR:
      87             :             case sdbc::DataType::LONGVARCHAR:
      88           0 :                 aString = xRow->getString(nRowPos);
      89           0 :                 bEmptyFlag = ( aString.Len() == 0 ) && xRow->wasNull();
      90           0 :                 break;
      91             : 
      92             :             case sdbc::DataType::DATE:
      93             :                 {
      94           0 :                     SvNumberFormatter* pFormTable = pDoc->GetFormatTable();
      95             :                     nFormatIndex = pFormTable->GetStandardFormat(
      96           0 :                                         NUMBERFORMAT_DATE, ScGlobal::eLnge );
      97             : 
      98           0 :                     util::Date aDate = xRow->getDate(nRowPos);
      99             :                     nVal = Date( aDate.Day, aDate.Month, aDate.Year ) -
     100           0 :                                                 *pFormTable->GetNullDate();
     101           0 :                     bEmptyFlag = xRow->wasNull();
     102           0 :                     bValue = sal_True;
     103             :                 }
     104           0 :                 break;
     105             : 
     106             :             case sdbc::DataType::TIME:
     107             :                 {
     108           0 :                     SvNumberFormatter* pFormTable = pDoc->GetFormatTable();
     109             :                     nFormatIndex = pFormTable->GetStandardFormat(
     110           0 :                                         NUMBERFORMAT_TIME, ScGlobal::eLnge );
     111             : 
     112           0 :                     util::Time aTime = xRow->getTime(nRowPos);
     113             :                     nVal = ( aTime.Hours * 3600 + aTime.Minutes * 60 +
     114           0 :                              aTime.Seconds + aTime.HundredthSeconds / 100.0 ) / D_TIMEFACTOR;
     115           0 :                     bEmptyFlag = xRow->wasNull();
     116           0 :                     bValue = sal_True;
     117             :                 }
     118           0 :                 break;
     119             : 
     120             :             case sdbc::DataType::TIMESTAMP:
     121             :                 {
     122           0 :                     SvNumberFormatter* pFormTable = pDoc->GetFormatTable();
     123             :                     nFormatIndex = pFormTable->GetStandardFormat(
     124           0 :                                         NUMBERFORMAT_DATETIME, ScGlobal::eLnge );
     125             : 
     126           0 :                     util::DateTime aStamp = xRow->getTimestamp(nRowPos);
     127             :                     nVal = ( Date( aStamp.Day, aStamp.Month, aStamp.Year ) -
     128           0 :                                                 *pFormTable->GetNullDate() ) +
     129             :                            ( aStamp.Hours * 3600 + aStamp.Minutes * 60 +
     130           0 :                              aStamp.Seconds + aStamp.HundredthSeconds / 100.0 ) / D_TIMEFACTOR;
     131           0 :                     bEmptyFlag = xRow->wasNull();
     132           0 :                     bValue = sal_True;
     133             :                 }
     134           0 :                 break;
     135             : 
     136             :             case sdbc::DataType::SQLNULL:
     137           0 :                 bEmptyFlag = sal_True;
     138           0 :                 break;
     139             : 
     140             :             case sdbc::DataType::BINARY:
     141             :             case sdbc::DataType::VARBINARY:
     142             :             case sdbc::DataType::LONGVARBINARY:
     143             :             default:
     144           0 :                 bError = sal_True;      // unknown type
     145             :         }
     146             :     }
     147           0 :     catch ( uno::Exception& )
     148             :     {
     149           0 :         bError = sal_True;
     150             :     }
     151             : 
     152           0 :     if ( bValue && bCurrency )
     153             :         nFormatIndex = pDoc->GetFormatTable()->GetStandardFormat(
     154           0 :                             NUMBERFORMAT_CURRENCY, ScGlobal::eLnge );
     155             : 
     156             :     ScBaseCell* pCell;
     157           0 :     if (bEmptyFlag)
     158             :     {
     159           0 :         pCell = NULL;
     160           0 :         pDoc->PutCell( nCol, nRow, nTab, pCell );
     161             :     }
     162           0 :     else if (bError)
     163             :     {
     164           0 :         pDoc->SetError( nCol, nRow, nTab, NOTAVAILABLE );
     165             :     }
     166           0 :     else if (bValue)
     167             :     {
     168           0 :         pCell = new ScValueCell( nVal );
     169           0 :         if (nFormatIndex == 0)
     170           0 :             pDoc->PutCell( nCol, nRow, nTab, pCell );
     171             :         else
     172           0 :             pDoc->PutCell( nCol, nRow, nTab, pCell, nFormatIndex );
     173             :     }
     174             :     else
     175             :     {
     176           0 :         if (aString.Len())
     177             :         {
     178           0 :             pCell = ScBaseCell::CreateTextCell( aString, pDoc );
     179           0 :             if (pStrData)
     180             :             {
     181           0 :                 pStrData->mbSimpleText = pCell->GetCellType() != CELLTYPE_EDIT;
     182           0 :                 pStrData->mnStrLength = aString.Len();
     183             :             }
     184             :         }
     185             :         else
     186           0 :             pCell = NULL;
     187           0 :         pDoc->PutCell( nCol, nRow, nTab, pCell );
     188           0 :     }
     189           0 : }
     190             : 
     191             : 
     192             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10