Kaydet (Commit) 4c6a27aa authored tarafından Lionel Elie Mamane's avatar Lionel Elie Mamane

Use rtl::Reference to make code clearer & exception-safe

Change-Id: I8cfdf792541b351a19e16f95d4e6f7127e3d33b2
üst b800ba09
...@@ -99,16 +99,15 @@ void OPreparedStatement::construct(const OUString& sql) throw(SQLException, Run ...@@ -99,16 +99,15 @@ void OPreparedStatement::construct(const OUString& sql) throw(SQLException, Run
OResultSet::setBoundedColumns(m_aEvaluateRow,aTemp,m_xParamColumns,xNames,false,m_xDBMetaData,m_aColMapping); OResultSet::setBoundedColumns(m_aEvaluateRow,aTemp,m_xParamColumns,xNames,false,m_xDBMetaData,m_aColMapping);
} }
Reference<XResultSet> OPreparedStatement::makeResultSet() rtl::Reference<OResultSet> OPreparedStatement::makeResultSet()
{ {
closeResultSet(); closeResultSet();
OResultSet *pResultSet = createResultSet(); rtl::Reference<OResultSet> xResultSet(createResultSet());
Reference<XResultSet> xRS(pResultSet); m_xResultSet = xResultSet.get();
initializeResultSet(pResultSet); initializeResultSet(xResultSet.get());
initResultSet(pResultSet); initResultSet(xResultSet.get());
m_xResultSet = xRS; return xResultSet;
return xRS;
} }
Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException, std::exception) Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
...@@ -156,13 +155,10 @@ sal_Bool SAL_CALL OPreparedStatement::execute( ) throw(SQLException, RuntimeExc ...@@ -156,13 +155,10 @@ sal_Bool SAL_CALL OPreparedStatement::execute( ) throw(SQLException, RuntimeExc
::osl::MutexGuard aGuard( m_aMutex ); ::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(OStatement_BASE::rBHelper.bDisposed); checkDisposed(OStatement_BASE::rBHelper.bDisposed);
Reference<XResultSet> xRS(makeResultSet()); rtl::Reference<OResultSet> xRS(makeResultSet());
// since we don't support the XMultipleResults interface, nobody will ever get that ResultSet... // since we don't support the XMultipleResults interface, nobody will ever get that ResultSet...
Reference< XComponent > xComp(xRS, UNO_QUERY); if(xRS.is())
assert(xComp.is() || !xRS.is()); xRS->dispose();
if (xComp.is())
xComp->dispose();
return m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT; return m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT;
} }
...@@ -173,16 +169,12 @@ sal_Int32 SAL_CALL OPreparedStatement::executeUpdate( ) throw(SQLException, Run ...@@ -173,16 +169,12 @@ sal_Int32 SAL_CALL OPreparedStatement::executeUpdate( ) throw(SQLException, Run
::osl::MutexGuard aGuard( m_aMutex ); ::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(OStatement_BASE::rBHelper.bDisposed); checkDisposed(OStatement_BASE::rBHelper.bDisposed);
Reference<XResultSet> xRS(makeResultSet()); rtl::Reference<OResultSet> xRS(makeResultSet());
if(xRS.is()) if(xRS.is())
{ {
assert(dynamic_cast<OResultSet*>(xRS.get())); const sal_Int32 res(xRS->getRowCountResult());
const sal_Int32 res(static_cast<OResultSet*>(xRS.get())->getRowCountResult());
// nobody will ever get that ResultSet... // nobody will ever get that ResultSet...
Reference< XComponent > xComp(xRS, UNO_QUERY); xRS->dispose();
assert(xComp.is());
if (xComp.is())
xComp->dispose();
return res; return res;
} }
else else
...@@ -210,7 +202,7 @@ Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) throw(SQLE ...@@ -210,7 +202,7 @@ Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) throw(SQLE
::osl::MutexGuard aGuard( m_aMutex ); ::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(OStatement_BASE::rBHelper.bDisposed); checkDisposed(OStatement_BASE::rBHelper.bDisposed);
return makeResultSet(); return makeResultSet().get();
} }
......
...@@ -53,7 +53,7 @@ namespace connectivity ...@@ -53,7 +53,7 @@ namespace connectivity
// factory method for resultset's // factory method for resultset's
virtual OResultSet* createResultSet() SAL_OVERRIDE; virtual OResultSet* createResultSet() SAL_OVERRIDE;
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > makeResultSet(); ::rtl::Reference< OResultSet > makeResultSet();
void initResultSet(OResultSet*); void initResultSet(OResultSet*);
void checkAndResizeParameters(sal_Int32 parameterIndex); void checkAndResizeParameters(sal_Int32 parameterIndex);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment