1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
)
45 bool bEmptyFlag
= false;
47 sal_uLong nFormatIndex
= 0;
49 // wasNull calls only if null value was found?
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();
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();
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();
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();
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();
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();
135 case sdbc::DataType::SQLNULL
:
139 case sdbc::DataType::BINARY
:
140 case sdbc::DataType::VARBINARY
:
141 case sdbc::DataType::LONGVARBINARY
:
143 bError
= true; // unknown type
146 catch ( uno::Exception
& )
151 if ( bValue
&& bCurrency
)
152 nFormatIndex
= pDoc
->GetFormatTable()->GetStandardFormat(
153 css::util::NumberFormat::CURRENCY
, ScGlobal::eLnge
);
155 ScAddress
aPos(nCol
, nRow
, nTab
);
157 pDoc
->SetEmptyCell(aPos
);
160 pDoc
->SetError( nCol
, nRow
, nTab
, NOTAVAILABLE
);
164 pDoc
->SetValue(aPos
, nVal
);
166 pDoc
->SetNumberFormat(aPos
, nFormatIndex
);
170 if (!aString
.isEmpty())
172 if (ScStringUtil::isMultiline(aString
))
174 pDoc
->SetEditText(aPos
, aString
);
176 pStrData
->mbSimpleText
= false;
180 ScSetStringParam aParam
;
181 aParam
.setTextInput();
182 pDoc
->SetString(aPos
, aString
, &aParam
);
184 pStrData
->mbSimpleText
= true;
188 pStrData
->mnStrLength
= aString
.getLength();
191 pDoc
->SetEmptyCell(aPos
);
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */