Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / sc / source / core / data / dpsdbtab.cxx
blobb56217c27f43e6115e86cddafce0ce8b7ea8fb47
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 <dpsdbtab.hxx>
21 #include <globstr.hrc>
22 #include <scresid.hxx>
23 #include <dpfilteredcache.hxx>
24 #include <document.hxx>
25 #include <dpobject.hxx>
27 #include <com/sun/star/sdb/CommandType.hpp>
29 using namespace com::sun::star;
31 using ::std::vector;
32 using ::com::sun::star::uno::Sequence;
33 using ::com::sun::star::uno::Any;
35 sal_Int32 ScImportSourceDesc::GetCommandType() const
37 sal_Int32 nSdbType = -1;
39 switch ( nType )
41 case sheet::DataImportMode_SQL: nSdbType = sdb::CommandType::COMMAND; break;
42 case sheet::DataImportMode_TABLE: nSdbType = sdb::CommandType::TABLE; break;
43 case sheet::DataImportMode_QUERY: nSdbType = sdb::CommandType::QUERY; break;
44 default:
47 return nSdbType;
50 const ScDPCache* ScImportSourceDesc::CreateCache(const ScDPDimensionSaveData* pDimData) const
52 if (!mpDoc)
53 return nullptr;
55 sal_Int32 nSdbType = GetCommandType();
56 if (nSdbType < 0)
57 return nullptr;
59 ScDPCollection::DBCaches& rCaches = mpDoc->GetDPCollection()->GetDBCaches();
60 return rCaches.getCache(nSdbType, aDBName, aObject, pDimData);
63 ScDatabaseDPData::ScDatabaseDPData(
64 const ScDocument* pDoc, const ScDPCache& rCache) :
65 ScDPTableData(pDoc),
66 aCacheTable(rCache)
70 ScDatabaseDPData::~ScDatabaseDPData()
74 void ScDatabaseDPData::DisposeData()
76 //TODO: use OpenDatabase here?
77 aCacheTable.clear();
80 sal_Int32 ScDatabaseDPData::GetColumnCount()
82 CreateCacheTable();
83 return GetCacheTable().getColSize();
86 OUString ScDatabaseDPData::getDimensionName(sal_Int32 nColumn)
88 if (getIsDataLayoutDimension(nColumn))
90 //TODO: different internal and display names?
91 //return "Data";
92 return ScResId(STR_PIVOT_DATA);
95 CreateCacheTable();
96 return aCacheTable.getFieldName(static_cast<SCCOL>(nColumn));
99 bool ScDatabaseDPData::getIsDataLayoutDimension(sal_Int32 nColumn)
101 return ( nColumn == GetCacheTable().getColSize());
104 bool ScDatabaseDPData::IsDateDimension(sal_Int32 /* nDim */)
106 //TODO: later...
107 return false;
110 void ScDatabaseDPData::SetEmptyFlags( bool /* bIgnoreEmptyRows */, bool /* bRepeatIfEmpty */ )
112 // not used for database data
113 //TODO: disable flags
116 void ScDatabaseDPData::CreateCacheTable()
118 if (!aCacheTable.empty())
119 // cache table already created.
120 return;
122 aCacheTable.fillTable();
125 void ScDatabaseDPData::FilterCacheTable(std::vector<ScDPFilteredCache::Criterion>&& rCriteria, std::unordered_set<sal_Int32>&& rCatDims)
127 CreateCacheTable();
128 aCacheTable.filterByPageDimension(
129 rCriteria, (IsRepeatIfEmpty() ? std::move(rCatDims) : std::unordered_set<sal_Int32>()));
132 void ScDatabaseDPData::GetDrillDownData(std::vector<ScDPFilteredCache::Criterion>&& rCriteria, std::unordered_set<sal_Int32>&& rCatDims, Sequence< Sequence<Any> >& rData)
134 CreateCacheTable();
135 sal_Int32 nRowSize = aCacheTable.getRowSize();
136 if (!nRowSize)
137 return;
139 aCacheTable.filterTable(
140 rCriteria, rData, IsRepeatIfEmpty() ? std::move(rCatDims) : std::unordered_set<sal_Int32>());
143 void ScDatabaseDPData::CalcResults(CalcInfo& rInfo, bool bAutoShow)
145 CreateCacheTable();
146 CalcResultsFromCacheTable( aCacheTable, rInfo, bAutoShow);
149 const ScDPFilteredCache& ScDatabaseDPData::GetCacheTable() const
151 return aCacheTable;
154 void ScDatabaseDPData::ReloadCacheTable()
156 aCacheTable.clear();
157 CreateCacheTable();
160 #if DUMP_PIVOT_TABLE
162 void ScDatabaseDPData::Dump() const
164 // TODO : Implement this.
167 #endif
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */