fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / data / dbdocutl.cxx
blobcaf30c8446f8c8f2642ae46509042154ded0b8a2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/sdbc/DataType.hpp>
21 #include <com/sun/star/sdbc/XRow.hpp>
23 #include <svl/zforlist.hxx>
25 #include "dbdocutl.hxx"
26 #include "document.hxx"
27 #include <formula/errorcodes.hxx>
28 #include "stringutil.hxx"
29 #include "globalnames.hxx"
31 using namespace ::com::sun::star;
33 ScDatabaseDocUtil::StrData::StrData() :
34 mbSimpleText(true), mnStrLength(0)
38 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 )
42 OUString aString;
43 double nVal = 0.0;
44 bool bValue = false;
45 bool bEmptyFlag = false;
46 bool bError = false;
47 sal_uLong nFormatIndex = 0;
49 // wasNull calls only if null value was found?
51 try
53 switch ( nType )
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 css::util::NumberFormat::LOGICAL, ScGlobal::eLnge );
60 nVal = (xRow->getBoolean(nRowPos) ? 1 : 0);
61 bEmptyFlag = ( nVal == 0.0 ) && xRow->wasNull();
62 bValue = true;
63 break;
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 nVal = xRow->getDouble(nRowPos);
76 bEmptyFlag = ( nVal == 0.0 ) && xRow->wasNull();
77 bValue = true;
78 break;
80 case sdbc::DataType::CHAR:
81 case sdbc::DataType::VARCHAR:
82 case sdbc::DataType::LONGVARCHAR:
83 aString = xRow->getString(nRowPos);
84 bEmptyFlag = ( aString.isEmpty() ) && xRow->wasNull();
85 break;
87 case sdbc::DataType::DATE:
89 SvNumberFormatter* pFormTable = pDoc->GetFormatTable();
90 nFormatIndex = pFormTable->GetStandardFormat(
91 css::util::NumberFormat::DATE, ScGlobal::eLnge );
93 util::Date aDate = xRow->getDate(nRowPos);
94 nVal = Date( aDate.Day, aDate.Month, aDate.Year ) -
95 *pFormTable->GetNullDate();
96 bEmptyFlag = xRow->wasNull();
97 bValue = true;
99 break;
101 case sdbc::DataType::TIME:
103 SvNumberFormatter* pFormTable = pDoc->GetFormatTable();
104 nFormatIndex = pFormTable->GetStandardFormat(
105 css::util::NumberFormat::TIME, ScGlobal::eLnge );
107 util::Time aTime = xRow->getTime(nRowPos);
108 nVal = aTime.Hours / static_cast<double>(::tools::Time::hourPerDay) +
109 aTime.Minutes / static_cast<double>(::tools::Time::minutePerDay) +
110 aTime.Seconds / static_cast<double>(::tools::Time::secondPerDay) +
111 aTime.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerDay);
112 bEmptyFlag = xRow->wasNull();
113 bValue = true;
115 break;
117 case sdbc::DataType::TIMESTAMP:
119 SvNumberFormatter* pFormTable = pDoc->GetFormatTable();
120 nFormatIndex = pFormTable->GetStandardFormat(
121 css::util::NumberFormat::DATETIME, ScGlobal::eLnge );
123 util::DateTime aStamp = xRow->getTimestamp(nRowPos);
124 nVal = ( Date( aStamp.Day, aStamp.Month, aStamp.Year ) -
125 *pFormTable->GetNullDate() ) +
126 aStamp.Hours / static_cast<double>(::tools::Time::hourPerDay) +
127 aStamp.Minutes / static_cast<double>(::tools::Time::minutePerDay) +
128 aStamp.Seconds / static_cast<double>(::tools::Time::secondPerDay) +
129 aStamp.NanoSeconds / static_cast<double>(::tools::Time::nanoSecPerDay);
130 bEmptyFlag = xRow->wasNull();
131 bValue = true;
133 break;
135 case sdbc::DataType::SQLNULL:
136 bEmptyFlag = true;
137 break;
139 case sdbc::DataType::BINARY:
140 case sdbc::DataType::VARBINARY:
141 case sdbc::DataType::LONGVARBINARY:
142 default:
143 bError = true; // unknown type
146 catch ( uno::Exception& )
148 bError = true;
151 if ( bValue && bCurrency )
152 nFormatIndex = pDoc->GetFormatTable()->GetStandardFormat(
153 css::util::NumberFormat::CURRENCY, ScGlobal::eLnge );
155 ScAddress aPos(nCol, nRow, nTab);
156 if (bEmptyFlag)
157 pDoc->SetEmptyCell(aPos);
158 else if (bError)
160 pDoc->SetError( nCol, nRow, nTab, NOTAVAILABLE );
162 else if (bValue)
164 pDoc->SetValue(aPos, nVal);
165 if (nFormatIndex)
166 pDoc->SetNumberFormat(aPos, nFormatIndex);
168 else
170 if (!aString.isEmpty())
172 if (ScStringUtil::isMultiline(aString))
174 pDoc->SetEditText(aPos, aString);
175 if (pStrData)
176 pStrData->mbSimpleText = false;
178 else
180 ScSetStringParam aParam;
181 aParam.setTextInput();
182 pDoc->SetString(aPos, aString, &aParam);
183 if (pStrData)
184 pStrData->mbSimpleText = true;
187 if (pStrData)
188 pStrData->mnStrLength = aString.getLength();
190 else
191 pDoc->SetEmptyCell(aPos);
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */