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 "dpsdbtab.hxx"
22 #include "globstr.hrc"
23 #include "dpfilteredcache.hxx"
24 #include "dptabres.hxx"
25 #include "document.hxx"
26 #include "dpobject.hxx"
28 #include <com/sun/star/sheet/DataImportMode.hpp>
29 #include <com/sun/star/sdb/CommandType.hpp>
31 using namespace com::sun::star
;
34 using ::com::sun::star::uno::Sequence
;
35 using ::com::sun::star::uno::Any
;
37 sal_Int32
ScImportSourceDesc::GetCommandType() const
39 sal_Int32 nSdbType
= -1;
43 case sheet::DataImportMode_SQL
: nSdbType
= sdb::CommandType::COMMAND
; break;
44 case sheet::DataImportMode_TABLE
: nSdbType
= sdb::CommandType::TABLE
; break;
45 case sheet::DataImportMode_QUERY
: nSdbType
= sdb::CommandType::QUERY
; break;
52 const ScDPCache
* ScImportSourceDesc::CreateCache(const ScDPDimensionSaveData
* pDimData
) const
57 sal_Int32 nSdbType
= GetCommandType();
61 ScDPCollection::DBCaches
& rCaches
= mpDoc
->GetDPCollection()->GetDBCaches();
62 return rCaches
.getCache(nSdbType
, aDBName
, aObject
, pDimData
);
65 ScDatabaseDPData::ScDatabaseDPData(
66 ScDocument
* pDoc
, const ScDPCache
& rCache
) :
72 ScDatabaseDPData::~ScDatabaseDPData()
76 void ScDatabaseDPData::DisposeData()
78 //TODO: use OpenDatabase here?
82 long ScDatabaseDPData::GetColumnCount()
85 return GetCacheTable().getColSize();
88 OUString
ScDatabaseDPData::getDimensionName(long nColumn
)
90 if (getIsDataLayoutDimension(nColumn
))
92 //TODO: different internal and display names?
94 return ScGlobal::GetRscString(STR_PIVOT_DATA
);
98 return aCacheTable
.getFieldName(static_cast<SCCOL
>(nColumn
));
101 bool ScDatabaseDPData::getIsDataLayoutDimension(long nColumn
)
103 return ( nColumn
== GetCacheTable().getColSize());
106 bool ScDatabaseDPData::IsDateDimension(long /* nDim */)
112 void ScDatabaseDPData::SetEmptyFlags( bool /* bIgnoreEmptyRows */, bool /* bRepeatIfEmpty */ )
114 // not used for database data
115 //TODO: disable flags
118 void ScDatabaseDPData::CreateCacheTable()
120 if (!aCacheTable
.empty())
121 // cache table already created.
124 aCacheTable
.fillTable();
127 void ScDatabaseDPData::FilterCacheTable(const vector
<ScDPFilteredCache::Criterion
>& rCriteria
, const std::unordered_set
<sal_Int32
>& rCatDims
)
130 aCacheTable
.filterByPageDimension(
131 rCriteria
, (IsRepeatIfEmpty() ? rCatDims
: std::unordered_set
<sal_Int32
>()));
134 void ScDatabaseDPData::GetDrillDownData(const vector
<ScDPFilteredCache::Criterion
>& rCriteria
, const std::unordered_set
<sal_Int32
>& rCatDims
, Sequence
< Sequence
<Any
> >& rData
)
137 sal_Int32 nRowSize
= aCacheTable
.getRowSize();
141 aCacheTable
.filterTable(
142 rCriteria
, rData
, IsRepeatIfEmpty() ? rCatDims
: std::unordered_set
<sal_Int32
>());
145 void ScDatabaseDPData::CalcResults(CalcInfo
& rInfo
, bool bAutoShow
)
148 CalcResultsFromCacheTable( aCacheTable
, rInfo
, bAutoShow
);
151 const ScDPFilteredCache
& ScDatabaseDPData::GetCacheTable() const
156 void ScDatabaseDPData::ReloadCacheTable()
162 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */