dba34c: #i113405# remove row from rowset when it can not be accessed anymore and adjust rowcount

This commit is contained in:
Ocke Janssen [oj] 2011-01-06 12:32:17 +01:00
parent b68968b86c
commit 54b40663d2
5 changed files with 27 additions and 16 deletions

View file

@ -154,7 +154,8 @@ OKeySet::OKeySet(const connectivity::OSQLTable& _xTable,
const ::rtl::OUString& _rUpdateTableName, // this can be the alias or the full qualified name
const Reference< XSingleSelectQueryAnalyzer >& _xComposer,
const ORowSetValueVector& _aParameterValueForCache,
sal_Int32 i_nMaxRows)
sal_Int32 i_nMaxRows,
sal_Int32& o_nRowCount)
:OCacheSet(i_nMaxRows)
,m_aParameterValueForCache(_aParameterValueForCache)
,m_pKeyColumnNames(NULL)
@ -165,6 +166,7 @@ OKeySet::OKeySet(const connectivity::OSQLTable& _xTable,
,m_xTableKeys(_xTableKeys)
,m_xComposer(_xComposer)
,m_sUpdateTableName(_rUpdateTableName)
,m_rRowCount(o_nRowCount)
,m_bRowCountFinal(sal_False)
{
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OKeySet::OKeySet" );
@ -1239,7 +1241,7 @@ sal_Bool SAL_CALL OKeySet::first( ) throw(SQLException, RuntimeException)
++m_aKeyIter;
if(m_aKeyIter == m_aKeyMap.end() && !fetchRow())
m_aKeyIter = m_aKeyMap.end();
else
refreshRow();
return m_aKeyIter != m_aKeyMap.end() && m_aKeyIter != m_aKeyMap.begin();
}
@ -1403,10 +1405,19 @@ void SAL_CALL OKeySet::refreshRow() throw(SQLException, RuntimeException)
OSL_ENSURE(m_xSet.is(),"No resultset form statement!");
sal_Bool bOK = m_xSet->next();
if ( !bOK )
m_aKeyIter = m_aKeyMap.end();
{
OKeySetMatrix::iterator aTemp = m_aKeyIter;
++m_aKeyIter;
m_aKeyMap.erase(aTemp);
--m_rRowCount;
refreshRow();
}
else
{
m_xRow.set(m_xSet,UNO_QUERY);
OSL_ENSURE(m_xRow.is(),"No row form statement!");
}
}
// -----------------------------------------------------------------------------
sal_Bool OKeySet::fetchRow()
{

View file

@ -113,6 +113,7 @@ namespace dbaccess
::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer > m_xComposer;
::rtl::OUString m_sUpdateTableName;
::std::vector< ::rtl::OUString > m_aFilterColumns;
sal_Int32& m_rRowCount;
sal_Bool m_bRowCountFinal;
@ -160,7 +161,8 @@ namespace dbaccess
const ::rtl::OUString& _rUpdateTableName,
const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >& _xComposer,
const ORowSetValueVector& _aParameterValueForCache,
sal_Int32 i_nMaxRows);
sal_Int32 i_nMaxRows,
sal_Int32& o_nRowCount);
// late ctor which can throw exceptions
virtual void construct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter);

View file

@ -103,8 +103,9 @@ OptimisticSet::OptimisticSet(const ::comphelper::ComponentContext& _rContext,
const Reference< XConnection>& i_xConnection,
const Reference< XSingleSelectQueryAnalyzer >& _xComposer,
const ORowSetValueVector& _aParameterValueForCache,
sal_Int32 i_nMaxRows)
:OKeySet(NULL,NULL,::rtl::OUString(),_xComposer,_aParameterValueForCache,i_nMaxRows)
sal_Int32 i_nMaxRows,
sal_Int32& o_nRowCount)
:OKeySet(NULL,NULL,::rtl::OUString(),_xComposer,_aParameterValueForCache,i_nMaxRows,o_nRowCount)
,m_aSqlParser( _rContext.getLegacyServiceFactory() )
,m_aSqlIterator( i_xConnection, Reference<XTablesSupplier>(_xComposer,UNO_QUERY)->getTables(), m_aSqlParser, NULL )
,m_bResultSetChanged(false)

View file

@ -80,7 +80,8 @@ namespace dbaccess
const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& i_xConnection,
const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer >& _xComposer,
const ORowSetValueVector& _aParameterValueForCache,
sal_Int32 i_nMaxRows);
sal_Int32 i_nMaxRows,
sal_Int32& o_nRowCount);
// late ctor which can throw exceptions
virtual void construct(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter);

View file

@ -176,7 +176,7 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs,
if ( aTableNames.getLength() > 1 && !_rUpdateTableName.getLength() && bNeedKeySet )
{// here we have a join or union and nobody told us which table to update, so we update them all
m_nPrivileges = Privilege::SELECT|Privilege::DELETE|Privilege::INSERT|Privilege::UPDATE;
OptimisticSet* pCursor = new OptimisticSet(m_aContext,xConnection,_xAnalyzer,_aParameterValueForCache,i_nMaxRows);
OptimisticSet* pCursor = new OptimisticSet(m_aContext,xConnection,_xAnalyzer,_aParameterValueForCache,i_nMaxRows,m_nRowCount);
m_pCacheSet = pCursor;
m_xCacheSet = m_pCacheSet;
try
@ -309,7 +309,7 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs,
}
}
OKeySet* pKeySet = new OKeySet(m_aUpdateTable,xUpdateTableKeys,aUpdateTableName ,_xAnalyzer,_aParameterValueForCache,i_nMaxRows);
OKeySet* pKeySet = new OKeySet(m_aUpdateTable,xUpdateTableKeys,aUpdateTableName ,_xAnalyzer,_aParameterValueForCache,i_nMaxRows,m_nRowCount);
try
{
m_pCacheSet = pKeySet;
@ -825,7 +825,6 @@ sal_Bool ORowSetCache::moveWindow()
if ( nNewStartPos < 1 )
{
bCheck = m_pCacheSet->first();
// aEnd = m_pMatrix->begin() + (sal_Int32)(m_nFetchSize*0.5);
OSL_ENSURE((nNewEndPos - m_nStartPos - nNewStartPos) < (sal_Int32)m_pMatrix->size(),"Position is behind end()!");
aEnd = m_pMatrix->begin() + (nNewEndPos - m_nStartPos - nNewStartPos);
aIter = aEnd;
@ -958,9 +957,6 @@ sal_Bool ORowSetCache::moveWindow()
sal_Bool bCheck = m_pCacheSet->absolute(nPos);
bCheck = fill(aIter,aEnd,nPos,bCheck); // refill the region wew don't need anymore
// // we know that this is the current maximal rowcount here
// if ( !m_bRowCountFinal && bCheck )
// m_nRowCount = std::max(nPos,m_nRowCount);
// we have to read one row forward to enshure that we know when we are on last row
// but only when we don't know it already
sal_Bool bOk = sal_True;