LCOV - code coverage report
Current view: top level - sc/source/core/data - dbdocutl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 27 84 32.1 %
Date: 2014-11-03 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        1360 : 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        1360 :     OUString aString;
      43        1360 :     double nVal = 0.0;
      44        1360 :     bool bValue = false;
      45        1360 :     bool bEmptyFlag = false;
      46        1360 :     bool bError = false;
      47        1360 :     sal_uLong nFormatIndex = 0;
      48             : 
      49             :     //! wasNull calls only if null value was found?
      50             : 
      51             :     try
      52             :     {
      53        1360 :         switch ( nType )
      54             :         {
      55             :             case sdbc::DataType::BIT:
      56             :             case sdbc::DataType::BOOLEAN:
      57             :                 //! use language from doc (here, date/time and currency)?
      58             :                 nFormatIndex = pDoc->GetFormatTable()->GetStandardFormat(
      59           0 :                                     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             :                 //! 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        1360 :                 aString = xRow->getString(nRowPos);
      84        1360 :                 bEmptyFlag = ( aString.isEmpty() ) && xRow->wasNull();
      85        1360 :                 break;
      86             : 
      87             :             case sdbc::DataType::DATE:
      88             :                 {
      89           0 :                     SvNumberFormatter* pFormTable = pDoc->GetFormatTable();
      90             :                     nFormatIndex = pFormTable->GetStandardFormat(
      91           0 :                                         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 :                                         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 :                                         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        1360 :     if ( bValue && bCurrency )
     152             :         nFormatIndex = pDoc->GetFormatTable()->GetStandardFormat(
     153           0 :                             NUMBERFORMAT_CURRENCY, ScGlobal::eLnge );
     154             : 
     155        1360 :     ScAddress aPos(nCol, nRow, nTab);
     156        1360 :     if (bEmptyFlag)
     157         874 :         pDoc->SetEmptyCell(aPos);
     158         486 :     else if (bError)
     159             :     {
     160           0 :         pDoc->SetError( nCol, nRow, nTab, NOTAVAILABLE );
     161             :     }
     162         486 :     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         486 :         if (!aString.isEmpty())
     171             :         {
     172         460 :             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         460 :                 ScSetStringParam aParam;
     181         460 :                 aParam.setTextInput();
     182         460 :                 pDoc->SetString(aPos, aString, &aParam);
     183         460 :                 if (pStrData)
     184           0 :                     pStrData->mbSimpleText = true;
     185             :             }
     186             : 
     187         460 :             if (pStrData)
     188           0 :                 pStrData->mnStrLength = aString.getLength();
     189             :         }
     190             :         else
     191          26 :             pDoc->SetEmptyCell(aPos);
     192        1360 :     }
     193        1588 : }
     194             : 
     195             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10