diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2016-01-20 10:48:37 +0100 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2016-03-24 22:40:48 +0100 |
commit | bdb0c4e128ffb7b0d30fd90153762802de514cda (patch) | |
tree | 72a39145475f857ba279eed4c3472218df4e9ceb /sw/source | |
parent | e817940a83ba7f2768acc245e005ca096d34776a (diff) |
tdf#95292 MM: cleanup bEndOfDB handling
bEndOfDB was handled inconsistently in ToNextRecord for record
selections and normal record iteration. The new unified semantics
are defined to set bEndOfDB for the first failing record fetch.
This includes a rename of the function ExistsNextRecord, which
did never check for a next record, but just verified the current
record set to be valid.
This way we can also drop the bAfterSelection selection, which
was just needed for the inconsistent bEndOfDB handling.
Change-Id: Ibbd7ae95e5969b51e32f44b442e5dc778655e8a9
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/uibase/dbui/dbmgr.cxx | 72 |
1 files changed, 27 insertions, 45 deletions
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index a032b8c0b2d7..ab46a5ecda0f 100644 --- a/sw/source/uibase/dbui/dbmgr.cxx +++ b/sw/source/uibase/dbui/dbmgr.cxx @@ -353,7 +353,6 @@ static bool lcl_MoveAbsolute(SwDSParam* pParam, long nAbsPos) sal_Int32 nPos = 0; pParam->aSelection.getConstArray()[ pParam->nSelectionIndex ] >>= nPos; pParam->bEndOfDB = !pParam->xResultSet->absolute( nPos ); - pParam->CheckEndOfDB(); bRet = !pParam->bEndOfDB; } } @@ -1429,7 +1428,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, bFreezedLayouts = true; } } while( IsMergeOk() && - (bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord())); + ((bSynchronizedDoc && (nStartRow != nEndRow)) ? IsValidMergeRecord() : ToNextMergeRecord())); if ( xWorkDocSh.Is() && pWorkView->GetWrtShell().IsExpFieldsLocked() ) { @@ -1958,7 +1957,7 @@ bool SwDBManager::GetColumnCnt(const OUString& rSourceName, const OUString& rTab if(!bFound) return false; } - if(pFound->xResultSet.is() && !pFound->bAfterSelection) + if( pFound->HasValidRecord() ) { sal_Int32 nOldRow = 0; try @@ -1985,7 +1984,7 @@ bool SwDBManager::GetColumnCnt(const OUString& rSourceName, const OUString& rTab bool SwDBManager::GetMergeColumnCnt(const OUString& rColumnName, sal_uInt16 nLanguage, OUString &rResult, double *pNumber) { - if(!pImpl->pMergeData || !pImpl->pMergeData->xResultSet.is() || pImpl->pMergeData->bAfterSelection ) + if( !IsValidMergeRecord() ) { rResult.clear(); return false; @@ -2004,30 +2003,21 @@ bool SwDBManager::ToNextMergeRecord() bool SwDBManager::FillCalcWithMergeData( SvNumberFormatter *pDocFormatter, sal_uInt16 nLanguage, SwCalc &rCalc ) { - if (!(pImpl->pMergeData && pImpl->pMergeData->xResultSet.is())) + if( !IsValidMergeRecord() ) return false; uno::Reference< sdbcx::XColumnsSupplier > xColsSupp( pImpl->pMergeData->xResultSet, uno::UNO_QUERY ); - if(xColsSupp.is()) + if( !xColsSupp.is() ) + return false; + { uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns(); const uno::Sequence<OUString> aColNames = xCols->getElementNames(); const OUString* pColNames = aColNames.getConstArray(); OUString aString; - const bool bExistsNextRecord = ExistsNextRecord(); - for( int nCol = 0; nCol < aColNames.getLength(); nCol++ ) { - const OUString &rColName = pColNames[nCol]; - - // empty variables, if no more records; - if( !bExistsNextRecord ) - { - rCalc.VarChange( rColName, 0 ); - continue; - } - // get the column type sal_Int32 nColumnType = sdbc::DataType::SQLNULL; uno::Any aCol = xCols->getByName( pColNames[nCol] ); @@ -2064,9 +2054,9 @@ bool SwDBManager::FillCalcWithMergeData( SvNumberFormatter *pDocFormatter, rCalc.VarChange( pColNames[nCol], aValue ); } } - return bExistsNextRecord; } - return false; + + return true; } bool SwDBManager::ToNextRecord( @@ -2094,40 +2084,36 @@ static bool lcl_ToNextRecord( SwDSParam* pParam, const SwDBNextRecord action ) { bool bRet = true; - assert( action == SwDBNextRecord::NEXT || action == SwDBNextRecord::FIRST ); + assert( SwDBNextRecord::NEXT == action || + (SwDBNextRecord::FIRST == action && pParam) ); + if( nullptr == pParam ) + return false; if( action == SwDBNextRecord::FIRST ) { pParam->nSelectionIndex = 0; - pParam->bEndOfDB = - pParam->bAfterSelection = false; + pParam->bEndOfDB = false; } - if( !pParam || !pParam->xResultSet.is() || pParam->bEndOfDB || - (pParam->aSelection.getLength() && - pParam->aSelection.getLength() <= pParam->nSelectionIndex) ) - { - if( pParam ) - pParam->CheckEndOfDB(); + if( !pParam->HasValidRecord() ) return false; - } + try { if( pParam->aSelection.getLength() ) { - sal_Int32 nPos = 0; - pParam->aSelection.getConstArray()[ pParam->nSelectionIndex++ ] >>= nPos; - pParam->bEndOfDB = !pParam->xResultSet->absolute( nPos ); - pParam->CheckEndOfDB(); - bRet = !pParam->bEndOfDB; if( pParam->nSelectionIndex >= pParam->aSelection.getLength() ) pParam->bEndOfDB = true; + else + { + sal_Int32 nPos = 0; + pParam->aSelection.getConstArray()[ pParam->nSelectionIndex++ ] >>= nPos; + pParam->bEndOfDB = !pParam->xResultSet->absolute( nPos ); + } } else if( action == SwDBNextRecord::FIRST ) { pParam->bEndOfDB = !pParam->xResultSet->first(); - pParam->CheckEndOfDB(); - bRet = !pParam->bEndOfDB; } else { @@ -2138,15 +2124,15 @@ static bool lcl_ToNextRecord( SwDSParam* pParam, const SwDBNextRecord action ) // next returned true but it didn't move pParam->bEndOfDB = true; } - pParam->CheckEndOfDB(); - bRet = !pParam->bEndOfDB; ++pParam->nSelectionIndex; } + + bRet = !pParam->bEndOfDB; } catch( const uno::Exception &e ) { pParam->bEndOfDB = true; - pParam->CheckEndOfDB(); + bRet = false; // we allow merging with empty databases, so don't warn on init SAL_WARN_IF(action == SwDBNextRecord::NEXT, "sw.mailmerge", "exception in ToNextRecord(): " << e.Message); @@ -2157,9 +2143,9 @@ static bool lcl_ToNextRecord( SwDSParam* pParam, const SwDBNextRecord action ) // synchronized labels contain a next record field at their end // to assure that the next page can be created in mail merge // the cursor position must be validated -bool SwDBManager::ExistsNextRecord() const +bool SwDBManager::IsValidMergeRecord() const { - return pImpl->pMergeData && !pImpl->pMergeData->bEndOfDB; + return( pImpl->pMergeData && pImpl->pMergeData->HasValidRecord() ); } sal_uInt32 SwDBManager::GetSelectedRecordId() @@ -2192,7 +2178,6 @@ bool SwDBManager::ToRecordId(sal_Int32 nSet) { bRet = lcl_MoveAbsolute(pImpl->pMergeData, nAbsPos); pImpl->pMergeData->bEndOfDB = !bRet; - pImpl->pMergeData->CheckEndOfDB(); } return bRet; } @@ -2238,8 +2223,6 @@ bool SwDBManager::OpenDataSource(const OUString& rDataSource, const OUString& rT //after executeQuery the cursor must be positioned pFound->bEndOfDB = !pFound->xResultSet->next(); - pFound->bAfterSelection = false; - pFound->CheckEndOfDB(); ++pFound->nSelectionIndex; } catch (const uno::Exception&) @@ -2322,7 +2305,6 @@ void SwDBManager::CloseAll(bool bIncludingMerge) if(bIncludingMerge || pParam.get() != pImpl->pMergeData) { pParam->nSelectionIndex = 0; - pParam->bAfterSelection = false; pParam->bEndOfDB = false; try { |