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

Generated by: LCOV version 1.11