diff options
author | Kohei Yoshida <kyoshida@novell.com> | 2009-09-16 01:07:24 -0400 |
---|---|---|
committer | Kohei Yoshida <kyoshida@novell.com> | 2009-09-16 01:07:24 -0400 |
commit | 174c3c8921e6b7670e9be665c33a35e48fce690c (patch) | |
tree | 54782de8ba782c32b84ec721a93c8a61ecd7fe5f | |
parent | 273d64160792ffa17bfa2e13f305edba5d5e76c5 (diff) |
#i102750# fixed DCOUNT and DCOUNT2.
-rw-r--r-- | sc/inc/dociter.hxx | 14 | ||||
-rw-r--r-- | sc/source/core/data/dociter.cxx | 34 | ||||
-rw-r--r-- | sc/source/core/tool/interpr1.cxx | 18 |
3 files changed, 47 insertions, 19 deletions
diff --git a/sc/inc/dociter.hxx b/sc/inc/dociter.hxx index 1004c7cbd..14a4e8461 100644 --- a/sc/inc/dociter.hxx +++ b/sc/inc/dociter.hxx @@ -138,17 +138,19 @@ private: class DataAccess { public: - DataAccess(); + DataAccess(const ScDBQueryValueIterator* pParent); virtual ~DataAccess() = 0; virtual bool getCurrent(double& rValue, USHORT& rErr) = 0; virtual bool getFirst(double& rValue, USHORT& rErr) = 0; virtual bool getNext(double& rValue, USHORT& rErr) = 0; + protected: + const ScDBQueryValueIterator* mpParent; }; class DataAccessInternal : public DataAccess { public: - DataAccessInternal(const ScDBQueryParamInternal* pParam, ScDocument* pDoc); + DataAccessInternal(const ScDBQueryValueIterator* pParent, const ScDBQueryParamInternal* pParam, ScDocument* pDoc); virtual ~DataAccessInternal(); virtual bool getCurrent(double &rValue, USHORT &rErr); virtual bool getFirst(double &rValue, USHORT &rErr); @@ -172,7 +174,7 @@ private: class DataAccessMatrix : public DataAccess { public: - DataAccessMatrix(const ScDBQueryParamMatrix* pParam); + DataAccessMatrix(const ScDBQueryValueIterator* pParent, const ScDBQueryParamMatrix* pParam); virtual ~DataAccessMatrix(); virtual bool getCurrent(double &rValue, USHORT &rErr); virtual bool getFirst(double &rValue, USHORT &rErr); @@ -188,7 +190,9 @@ private: }; ::std::auto_ptr<ScDBQueryParamBase> mpParam; - ::std::auto_ptr<DataAccess> mpData; + ::std::auto_ptr<DataAccess> mpData; + + bool mbCountString; bool GetThis(double& rValue, USHORT& rErr); public: @@ -197,6 +201,8 @@ public: BOOL GetFirst(double& rValue, USHORT& rErr); /// Does NOT reset rValue if no value found! BOOL GetNext(double& rValue, USHORT& rErr); + + void SetCountString(bool b); }; // ============================================================================ diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx index 9c48f4252..4ab3016df 100644 --- a/sc/source/core/data/dociter.cxx +++ b/sc/source/core/data/dociter.cxx @@ -488,7 +488,8 @@ BOOL ScValueIterator::GetNext(double& rValue, USHORT& rErr) // ============================================================================ -ScDBQueryValueIterator::DataAccess::DataAccess() +ScDBQueryValueIterator::DataAccess::DataAccess(const ScDBQueryValueIterator* pParent) : + mpParent(pParent) { } @@ -498,7 +499,8 @@ ScDBQueryValueIterator::DataAccess::~DataAccess() // ---------------------------------------------------------------------------- -ScDBQueryValueIterator::DataAccessInternal::DataAccessInternal(const ScDBQueryParamInternal* pParam, ScDocument* pDoc) : +ScDBQueryValueIterator::DataAccessInternal::DataAccessInternal(const ScDBQueryValueIterator* pParent, const ScDBQueryParamInternal* pParam, ScDocument* pDoc) : + DataAccess(pParent), mpParam(pParam), mpDoc(pDoc) { @@ -594,6 +596,16 @@ bool ScDBQueryValueIterator::DataAccessInternal::getCurrent(double& rValue, USHO nRow++; } break; + case CELLTYPE_STRING: + if (mpParent->mbCountString) + { + rValue = 0.0; + rErr = 0; + return true; + } + else + ++nRow; + break; default: nRow++; break; @@ -626,7 +638,8 @@ bool ScDBQueryValueIterator::DataAccessInternal::getNext(double& rValue, USHORT& // ---------------------------------------------------------------------------- -ScDBQueryValueIterator::DataAccessMatrix::DataAccessMatrix(const ScDBQueryParamMatrix* pParam) : +ScDBQueryValueIterator::DataAccessMatrix::DataAccessMatrix(const ScDBQueryValueIterator* pParent, const ScDBQueryParamMatrix* pParam) : + DataAccess(pParent), mpParam(pParam) { SCSIZE nC, nR; @@ -652,6 +665,9 @@ bool ScDBQueryValueIterator::DataAccessMatrix::getCurrent(double& rValue, USHORT // Don't take empty values into account. continue; + if (rMat.IsString(mpParam->mnField, mnCurRow) && !mpParent->mbCountString) + continue; + if (isValidQuery(mnCurRow, rMat)) { rValue = rMat.GetDouble(mpParam->mnField, mnCurRow); @@ -855,20 +871,21 @@ bool ScDBQueryValueIterator::DataAccessMatrix::isValidQuery(SCROW nRow, const Sc // ---------------------------------------------------------------------------- ScDBQueryValueIterator::ScDBQueryValueIterator(ScDocument* pDocument, ScDBQueryParamBase* pParam) : - mpParam (pParam) + mpParam (pParam), + mbCountString(false) { switch (mpParam->GetType()) { case ScDBQueryParamBase::INTERNAL: { const ScDBQueryParamInternal* p = static_cast<const ScDBQueryParamInternal*>(pParam); - mpData.reset(new DataAccessInternal(p, pDocument)); + mpData.reset(new DataAccessInternal(this, p, pDocument)); } break; case ScDBQueryParamBase::MATRIX: { const ScDBQueryParamMatrix* p = static_cast<const ScDBQueryParamMatrix*>(pParam); - mpData.reset(new DataAccessMatrix(p)); + mpData.reset(new DataAccessMatrix(this, p)); } } } @@ -888,6 +905,11 @@ BOOL ScDBQueryValueIterator::GetNext(double& rValue, USHORT& rErr) return mpData->getNext(rValue, rErr); } +void ScDBQueryValueIterator::SetCountString(bool b) +{ + mbCountString = b; +} + // ============================================================================ ScCellIterator::ScCellIterator( ScDocument* pDocument, diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index 05eb14ada..7c6081fb2 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -5936,22 +5936,22 @@ void ScInterpreter::ScDBCount2() RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "sc", "Eike.Rathke@sun.com", "ScInterpreter::ScDBCount2" ); BOOL bMissingField = TRUE; auto_ptr<ScDBQueryParamBase> pQueryParam( GetDBParams(bMissingField) ); - if (pQueryParam.get() && pQueryParam->GetType() == ScDBQueryParamBase::INTERNAL) + if (pQueryParam.get()) { -#if 0 - ScDBQueryParamInternal* p = static_cast<ScDBQueryParamInternal*>(pQueryParam.get()); - SCTAB nTab = p->nTab; + double nVal; + USHORT nErr = 0; ULONG nCount = 0; - ScQueryCellIterator aCellIter(pDok, nTab, *p); - if ( aCellIter.GetFirst() ) + ScDBQueryValueIterator aValIter( pDok, pQueryParam.release()); + aValIter.SetCountString(true); + if ( aValIter.GetFirst( nVal, nErr) && !nErr ) { do { nCount++; - } while ( aCellIter.GetNext() ); + } while ( aValIter.GetNext( nVal, nErr) && !nErr ); } - PushDouble(nCount); -#endif + SetError( nErr ); + PushDouble( nCount ); } else PushIllegalParameter(); |