Tag: cws_src680_dba202a User: fs Date: 05/11/23 07:43:34 Modified: /dba/connectivity/source/drivers/mozab/ MResultSet.cxx, MResultSet.hxx
Log: #121589# some more safety against an m_pKeySet which is NULL File Changes: Directory: /dba/connectivity/source/drivers/mozab/ ================================================== File [changed]: MResultSet.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/mozab/MResultSet.cxx?r1=1.22&r2=1.22.36.1 Delta lines: +66 -63 --------------------- --- MResultSet.cxx 8 Sep 2005 06:19:38 -0000 1.22 +++ MResultSet.cxx 23 Nov 2005 15:43:31 -0000 1.22.36.1 @@ -4,9 +4,9 @@ * * $RCSfile: MResultSet.cxx,v $ * - * $Revision: 1.22 $ + * $Revision: 1.22.36.1 $ * - * last change: $Author: rt $ $Date: 2005/09/08 06:19:38 $ + * last change: $Author: fs $ $Date: 2005/11/23 15:43:31 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -206,16 +206,25 @@ return ::comphelper::concatSequences(aTypes.getTypes(),OResultSet_BASE::getTypes()); } // ------------------------------------------------------------------------- +void OResultSet::checkDisposed() +{ + ::checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + if ( !m_pKeySet.isValid() || !m_pTable ) + { + OSL_ENSURE( false, "OResultSet::checkDisposed: looks like we're disposed, but how is this possible?" ); + // if this assertion fires, we might have an explanation for a number of crash reports, + // which tell us that it *is* possible to have a m_pKeySet which is NULL, though we're not + // yet disposed + throw DisposedException( ::rtl::OUString(), *this ) + } +} +// ------------------------------------------------------------------------- sal_Int32 SAL_CALL OResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException) { - - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + ResultSetEntryGuard aGuard( *this ); // find the first column with the name columnName - - ::osl::MutexGuard aGuard( m_aMutex ); - Reference< XResultSetMetaData > xMeta = getMetaData(); sal_Int32 nLen = xMeta->getColumnCount(); sal_Int32 i = 1; @@ -239,9 +248,7 @@ // ------------------------------------------------------------------------- sal_Bool SAL_CALL OResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - + ResultSetEntryGuard aGuard( *this ); m_bWasNull = sal_True; return sal_False; } @@ -249,42 +256,50 @@ sal_Int8 SAL_CALL OResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); return 0; } // ------------------------------------------------------------------------- Sequence< sal_Int8 > SAL_CALL OResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); return Sequence< sal_Int8 >(); } // ------------------------------------------------------------------------- Date SAL_CALL OResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); return Date(); } // ------------------------------------------------------------------------- double SAL_CALL OResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); return 0.0; } // ------------------------------------------------------------------------- float SAL_CALL OResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); return 0; } // ------------------------------------------------------------------------- sal_Int32 SAL_CALL OResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); return 0; } // ------------------------------------------------------------------------- sal_Int32 SAL_CALL OResultSet::getRow( ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); + OSL_TRACE("In/Out: OResultSet::getRow, return = %u", m_nRowPos ); return m_nRowPos; } @@ -292,15 +307,14 @@ sal_Int64 SAL_CALL OResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); return sal_Int64(); } // ------------------------------------------------------------------------- Reference< XResultSetMetaData > SAL_CALL OResultSet::getMetaData( ) throw(SQLException, RuntimeException) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - + ResultSetEntryGuard aGuard( *this ); if(!m_xMetaData.is()) m_xMetaData = new OResultSetMetaData( @@ -451,11 +465,10 @@ ::rtl::OUString SAL_CALL OResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); + OSL_ENSURE(m_xColumns.isValid(), "Need the Columns!!"); OSL_ENSURE(columnIndex <= (sal_Int32)m_xColumns->size(), "Trying to access invalid columns number"); - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - checkIndex( columnIndex ); // If this query was sorted then we should have a valid KeySet, so use it @@ -466,6 +479,7 @@ Time SAL_CALL OResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); return Time(); } // ------------------------------------------------------------------------- @@ -473,15 +487,14 @@ DateTime SAL_CALL OResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); return DateTime(); } // ------------------------------------------------------------------------- sal_Bool SAL_CALL OResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - + ResultSetEntryGuard aGuard( *this ); // here you have to implement your movements // return true means there is no data @@ -491,8 +504,7 @@ // ------------------------------------------------------------------------- sal_Bool SAL_CALL OResultSet::isAfterLast( ) throw(SQLException, RuntimeException) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("In/Out: OResultSet::isAfterLast" ); return m_nRowPos > currentRowCount() && m_aQuery.queryComplete(); @@ -500,9 +512,7 @@ // ------------------------------------------------------------------------- sal_Bool SAL_CALL OResultSet::isFirst( ) throw(SQLException, RuntimeException) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("In/Out: OResultSet::isFirst" ); return m_nRowPos == 1; @@ -510,9 +520,7 @@ // ------------------------------------------------------------------------- sal_Bool SAL_CALL OResultSet::isLast( ) throw(SQLException, RuntimeException) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("In/Out: OResultSet::isLast" ); return m_nRowPos == currentRowCount() && m_aQuery.queryComplete(); @@ -520,8 +528,7 @@ // ------------------------------------------------------------------------- void SAL_CALL OResultSet::beforeFirst( ) throw(SQLException, RuntimeException) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + ResultSetEntryGuard aGuard( *this ); // move before the first row so that isBeforeFirst returns false OSL_TRACE("In/Out: OResultSet::beforeFirst" ); @@ -531,9 +538,8 @@ // ------------------------------------------------------------------------- void SAL_CALL OResultSet::afterLast( ) throw(SQLException, RuntimeException) { - ::osl::MutexGuard aGuard( m_aMutex ); + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("In/Out: OResultSet::afterLast" ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); if(last()) next(); @@ -542,11 +548,7 @@ void SAL_CALL OResultSet::close( ) throw(SQLException, RuntimeException) { - { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - - } + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("In/Out: OResultSet::close" ); // dispose(); } @@ -579,15 +581,14 @@ // ------------------------------------------------------------------------- sal_Bool SAL_CALL OResultSet::previous( ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("In/Out: OResultSet::previous" ); return seekRow( PRIOR_POS ); } // ------------------------------------------------------------------------- Reference< XInterface > SAL_CALL OResultSet::getStatement( ) throw(SQLException, RuntimeException) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); - + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("In/Out: OResultSet::getStatement" ); return m_xStatement; @@ -596,18 +597,21 @@ sal_Bool SAL_CALL OResultSet::rowDeleted( ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("In/Out: OResultSet::rowDeleted, m_RowStates=%u",m_RowStates ); return ((m_RowStates & RowStates_Deleted) == RowStates_Deleted) ; } // ------------------------------------------------------------------------- sal_Bool SAL_CALL OResultSet::rowInserted( ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("In/Out: OResultSet::rowInserted,m_RowStates=%u",m_RowStates ); return ((m_RowStates & RowStates_Inserted) == RowStates_Inserted); } // ------------------------------------------------------------------------- sal_Bool SAL_CALL OResultSet::rowUpdated( ) throw(SQLException, RuntimeException) { + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("In/Out: OResultSet::rowUpdated,m_RowStates=%u",m_RowStates ); return ((m_RowStates & RowStates_Updated) == RowStates_Updated) ; } @@ -621,8 +625,7 @@ sal_Bool SAL_CALL OResultSet::wasNull( ) throw(SQLException, RuntimeException) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + ResultSetEntryGuard aGuard( *this ); return m_bWasNull; } @@ -630,8 +633,7 @@ void SAL_CALL OResultSet::cancel( ) throw(RuntimeException) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("In/Out: OResultSet::cancel" ); } @@ -1224,7 +1226,7 @@ void SAL_CALL OResultSet::executeQuery() throw( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) { - ::osl::MutexGuard aGuard(m_aMutex); + ResultSetEntryGuard aGuard( *this ); OSL_ENSURE( m_pTable, "Need a Table object"); if(!m_pTable) @@ -1563,8 +1565,7 @@ // ----------------------------------------------------------------------------- sal_Bool OResultSet::seekRow( eRowPosition pos, sal_Int32 nOffset ) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + ResultSetEntryGuard aGuard( *this ); sal_Int32 nNumberOfRecords = m_aQuery.getRealRowCount(); sal_Int32 nRetrivedRows = currentRowCount(); @@ -1649,8 +1650,7 @@ ::com::sun::star::uno::Any OResultSet::getBookmark( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) { OSL_TRACE("getBookmark, m_nRowPos = %u", m_nRowPos ); - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + ResultSetEntryGuard aGuard( *this ); if ( fetchCurrentRow() == sal_False ) ::dbtools::throwGenericSQLException(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can't get current row")),NULL); @@ -1659,6 +1659,7 @@ } sal_Bool OResultSet::moveToBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) { + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("moveToBookmark, bookmark = %u", comphelper::getINT32(bookmark) ); sal_Int32 nCardNum = comphelper::getINT32(bookmark); m_nRowPos = getRowForCardNumber(nCardNum); @@ -1667,6 +1668,7 @@ } sal_Bool OResultSet::moveRelativeToBookmark( const ::com::sun::star::uno::Any& bookmark, sal_Int32 rows ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) { + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("moveRelativeToBookmark, bookmark = %u rows= %u", comphelper::getINT32(bookmark),rows ); sal_Int32 nCardNum = comphelper::getINT32(bookmark); m_nRowPos = getRowForCardNumber(nCardNum); @@ -1674,6 +1676,7 @@ } sal_Int32 OResultSet::compareBookmarks( const ::com::sun::star::uno::Any& first, const ::com::sun::star::uno::Any& second ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) { + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("compareBookmarks, m_nRowPos = %u", m_nRowPos ); sal_Int32 nFirst=0; sal_Int32 nSecond=0; @@ -1693,11 +1696,13 @@ } sal_Bool OResultSet::hasOrderedBookmarks( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) { + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("hasOrderedBookmarks, m_nRowPos = %u", m_nRowPos ); return sal_True; } sal_Int32 OResultSet::hashBookmark( const ::com::sun::star::uno::Any& bookmark ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) { + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("hashBookmark, m_nRowPos = %u", m_nRowPos ); return comphelper::getINT32(bookmark); } @@ -1730,8 +1735,7 @@ void OResultSet::updateValue(sal_Int32 columnIndex ,const ORowSetValue& x) throw(SQLException, RuntimeException) { OSL_TRACE("updateValue, m_nRowPos = %u", m_nRowPos ); - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + ResultSetEntryGuard aGuard( *this ); if ( fetchCurrentRow() == sal_False ) ::dbtools::throwGenericSQLException(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can't get current row")),NULL); @@ -1751,8 +1755,7 @@ void SAL_CALL OResultSet::updateNull( sal_Int32 columnIndex ) throw(SQLException, RuntimeException) { OSL_TRACE("updateNull, m_nRowPos = %u", m_nRowPos ); - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + ResultSetEntryGuard aGuard( *this ); if ( fetchCurrentRow() == sal_False ) ::dbtools::throwGenericSQLException(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can't get current row")),NULL); @@ -1834,8 +1837,7 @@ void SAL_CALL OResultSet::updateBinaryStream( sal_Int32 columnIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException) { - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + ResultSetEntryGuard aGuard( *this ); if(!x.is()) ::dbtools::throwGenericSQLException(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Invalid use of null pointer")),*this); @@ -1866,6 +1868,7 @@ // ------------------------------------------------------------------------- void SAL_CALL OResultSet::insertRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) { + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("insertRow in, m_nRowPos = %u", m_nRowPos ); m_RowStates = RowStates_Inserted; updateRow(); @@ -1878,8 +1881,7 @@ void SAL_CALL OResultSet::updateRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) { OSL_TRACE("updateRow in, m_nRowPos = %u", m_nRowPos ); - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + ResultSetEntryGuard aGuard( *this ); if (!m_nRowPos || m_pKeySet->size() < m_nRowPos ) ::dbtools::throwGenericSQLException(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Call update on invalid row")),NULL); @@ -1907,8 +1909,7 @@ void SAL_CALL OResultSet::deleteRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) { OSL_TRACE("deleteRow, m_nRowPos = %u", m_nRowPos ); - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + ResultSetEntryGuard aGuard( *this ); if (rowDeleted()) throw SQLException(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Row Already deleted")) ,*this ,OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_HY0000) @@ -1932,6 +1933,7 @@ // ------------------------------------------------------------------------- void SAL_CALL OResultSet::cancelRowUpdates( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) { + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("cancelRowUpdates, m_nRowPos = %u", m_nRowPos ); if (fetchRow(getCurrentCardNumber(),sal_True)) //force fetch current row will cause we lose all change to the current row ::dbtools::throwGenericSQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Can't cancel row updates")), NULL ); @@ -1940,7 +1942,7 @@ void SAL_CALL OResultSet::moveToInsertRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) { OSL_TRACE("moveToInsertRow in, m_nRowPos = %u", m_nRowPos ); - ::osl::MutexGuard aGuard( m_aMutex ); + ResultSetEntryGuard aGuard( *this ); m_nOldRowPos = m_nRowPos; if (!m_nNewRow) //no new row now, insert one @@ -1968,6 +1970,7 @@ // ------------------------------------------------------------------------- void SAL_CALL OResultSet::moveToCurrentRow( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) { + ResultSetEntryGuard aGuard( *this ); OSL_TRACE("moveToCurrentRow, m_nRowPos = %u", m_nRowPos ); if (rowInserted()) { File [changed]: MResultSet.hxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/mozab/MResultSet.hxx?r1=1.9&r2=1.9.36.1 Delta lines: +15 -3 -------------------- --- MResultSet.hxx 8 Sep 2005 06:19:52 -0000 1.9 +++ MResultSet.hxx 23 Nov 2005 15:43:31 -0000 1.9.36.1 @@ -4,9 +4,9 @@ * * $RCSfile: MResultSet.hxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.9.36.1 $ * - * last change: $Author: rt $ $Date: 2005/09/08 06:19:52 $ + * last change: $Author: fs $ $Date: 2005/11/23 15:43:31 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -369,6 +369,9 @@ sal_Bool _bSetColumnMapping, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData>& _xMetaData, ::std::vector<sal_Int32>& _rColMapping); + + ::osl::Mutex& getMutex() { return m_aMutex; } + void checkDisposed(); }; inline sal_Int32 OResultSet::mapColumn(sal_Int32 column) @@ -383,6 +386,15 @@ return map; } + + class ResultSetEntryGuard : public ::osl::MutexGuard + { + public: + ResultSetEntryGuard( OResultSet& _rRS ) : ::osl::MutexGuard( _rRS.getMutex() ) + { + _rRS.checkDisposed(); + } + }; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
