connectivity/source/drivers/file/FPreparedStatement.cxx | 70 ++++++++-------- connectivity/source/drivers/file/FResultSet.cxx | 7 - connectivity/source/drivers/file/FStatement.cxx | 37 -------- connectivity/source/inc/file/FPreparedStatement.hxx | 4 connectivity/source/inc/file/FResultSet.hxx | 2 connectivity/source/inc/file/FStatement.hxx | 3 6 files changed, 40 insertions(+), 83 deletions(-)
New commits: commit d87c2c59c9c1d5f5825f355c9eb941fdf95b42f6 Author: Lionel Elie Mamane <lio...@mamane.lu> Date: Fri Dec 13 13:10:49 2013 +0100 sdbc file driver (Prepared)Statement: created ResultSet owned by *caller* That is the only choice that makes sense, since the (Prepared)Statement could die (go out of scope) before the ResultSet. User code could do that, if it does not "need" the (Prepared)Statement anymore. Also, it is only natural for user code to dispose a ResultSet that it does not need anymore. So we need to create a fresh ResultSet each time. The "luck" here is that the sdbc file driver does not implement the XMultipleResults interface; things get more hairy then. Change-Id: Ibf2cb5e5b7ca90432a289c185a6b4fe32d1ba565 diff --git a/connectivity/source/drivers/file/FPreparedStatement.cxx b/connectivity/source/drivers/file/FPreparedStatement.cxx index d34c526..f247483 100644 --- a/connectivity/source/drivers/file/FPreparedStatement.cxx +++ b/connectivity/source/drivers/file/FPreparedStatement.cxx @@ -55,7 +55,6 @@ DBG_NAME( file_OPreparedStatement ) // ------------------------------------------------------------------------- OPreparedStatement::OPreparedStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection ) - ,m_pResultSet(NULL) { SAL_INFO( "connectivity.drivers", "file ocke.jans...@sun.com OPreparedStatement::OPreparedStatement" ); DBG_CTOR( file_OPreparedStatement, NULL ); @@ -74,15 +73,8 @@ void OPreparedStatement::disposing() SAL_INFO( "connectivity.drivers", "file ocke.jans...@sun.com OPreparedStatement::disposing" ); ::osl::MutexGuard aGuard(m_aMutex); - clearMyResultSet(); OStatement_BASE2::disposing(); - if(m_pResultSet) - { - m_pResultSet->release(); - m_pResultSet = NULL; - } - m_xParamColumns = NULL; m_xMetaData.clear(); if(m_aParameterRow.is()) @@ -90,8 +82,6 @@ void OPreparedStatement::disposing() m_aParameterRow->get().clear(); m_aParameterRow = NULL; } - - } // ------------------------------------------------------------------------- void OPreparedStatement::construct(const OUString& sql) throw(SQLException, RuntimeException) @@ -115,12 +105,17 @@ void OPreparedStatement::construct(const OUString& sql) throw(SQLException, Run OValueRefRow aTemp; OResultSet::setBoundedColumns(m_aEvaluateRow,aTemp,m_xParamColumns,xNames,sal_False,m_xDBMetaData,m_aColMapping); +} - m_pResultSet = createResultSet(); - m_pResultSet->acquire(); - m_xResultSet = Reference<XResultSet>(m_pResultSet); - initializeResultSet(m_pResultSet); +Reference<XResultSet> OPreparedStatement::makeResultSet() +{ + OResultSet *pResultSet = createResultSet(); + Reference<XResultSet> xRS(pResultSet); + initializeResultSet(pResultSet); + initResultSet(pResultSet); + return xRS; } + // ------------------------------------------------------------------------- Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException) @@ -160,9 +155,6 @@ void SAL_CALL OPreparedStatement::close( ) throw(SQLException, RuntimeException SAL_INFO( "connectivity.drivers", "file ocke.jans...@sun.com OPreparedStatement::close" ); ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OStatement_BASE::rBHelper.bDisposed); - - - clearMyResultSet(); } // ------------------------------------------------------------------------- @@ -172,7 +164,12 @@ sal_Bool SAL_CALL OPreparedStatement::execute( ) throw(SQLException, RuntimeExc ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OStatement_BASE::rBHelper.bDisposed); - initResultSet(); + Reference<XResultSet> xRS(makeResultSet()); + + // since we don't support the XMultipleResults interface, nobody will ever get that ResultSet... + Reference< XComponent > xComp(xRS, UNO_QUERY); + if (xComp.is()) + xComp->dispose(); return m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT; } @@ -184,9 +181,20 @@ sal_Int32 SAL_CALL OPreparedStatement::executeUpdate( ) throw(SQLException, Run ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OStatement_BASE::rBHelper.bDisposed); - initResultSet(); - - return m_pResultSet ? m_pResultSet->getRowCountResult() : sal_Int32(0); + Reference<XResultSet> xRS(makeResultSet()); + if(xRS.is()) + { + assert(dynamic_cast<OResultSet*>(xRS.get())); + const sal_Int32 res(static_cast<OResultSet*>(xRS.get())->getRowCountResult()); + // nobody will ever get that ResultSet... + Reference< XComponent > xComp(xRS, UNO_QUERY); + assert(xComp.is()); + if (xComp.is()) + xComp->dispose(); + return res; + } + else + return 0; } // ------------------------------------------------------------------------- @@ -213,7 +221,7 @@ Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) throw(SQLE ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OStatement_BASE::rBHelper.bDisposed); - return initResultSet(); + return makeResultSet(); } // ------------------------------------------------------------------------- @@ -408,21 +416,17 @@ OResultSet* OPreparedStatement::createResultSet() return new OResultSet(this,m_aSQLIterator); } // ----------------------------------------------------------------------------- -Reference<XResultSet> OPreparedStatement::initResultSet() +void OPreparedStatement::initResultSet(OResultSet *pResultSet) { SAL_INFO( "connectivity.drivers", "file ocke.jans...@sun.com OPreparedStatement::initResultSet" ); - m_pResultSet->clear(); - Reference<XResultSet> xRs(m_pResultSet); // check if we got enough parameters if ( (m_aParameterRow.is() && ( m_aParameterRow->get().size() -1 ) < m_xParamColumns->get().size()) || (m_xParamColumns.is() && !m_aParameterRow.is() && !m_aParameterRow->get().empty()) ) m_pConnection->throwGenericSQLException(STR_INVALID_PARA_COUNT,*this); - m_pResultSet->OpenImpl(); - m_pResultSet->setMetaData(getMetaData()); - - return xRs; + pResultSet->OpenImpl(); + pResultSet->setMetaData(getMetaData()); } // ----------------------------------------------------------------------------- void SAL_CALL OPreparedStatement::acquire() throw() @@ -554,13 +558,13 @@ void OPreparedStatement::describeParameter() } } // ----------------------------------------------------------------------------- -void OPreparedStatement::initializeResultSet(OResultSet* _pResult) +void OPreparedStatement::initializeResultSet(OResultSet* pRS) { SAL_INFO( "connectivity.drivers", "file ocke.jans...@sun.com OPreparedStatement::initializeResultSet" ); - OStatement_Base::initializeResultSet(_pResult); + OStatement_Base::initializeResultSet(pRS); - m_pResultSet->setParameterColumns(m_xParamColumns); - m_pResultSet->setParameterRow(m_aParameterRow); + pRS->setParameterColumns(m_xParamColumns); + pRS->setParameterRow(m_aParameterRow); // Substitute parameter (AssignValues and criteria): if (!m_xParamColumns->get().empty()) diff --git a/connectivity/source/drivers/file/FResultSet.cxx b/connectivity/source/drivers/file/FResultSet.cxx index 63c77c7..d8fbde1 100644 --- a/connectivity/source/drivers/file/FResultSet.cxx +++ b/connectivity/source/drivers/file/FResultSet.cxx @@ -166,12 +166,7 @@ void OResultSet::disposing(void) m_pTable->release(); m_pTable = NULL; } - clear(); -} -// ----------------------------------------------------------------------------- -void OResultSet::clear() -{ - SAL_INFO( "connectivity.drivers", "file ocke.jans...@sun.com OResultSet::clear" ); + m_pFileSet = NULL; DELETEZ(m_pSortIndex); diff --git a/connectivity/source/drivers/file/FStatement.cxx b/connectivity/source/drivers/file/FStatement.cxx index 02bfe24..44e6b2f 100644 --- a/connectivity/source/drivers/file/FStatement.cxx +++ b/connectivity/source/drivers/file/FStatement.cxx @@ -102,22 +102,10 @@ OStatement_Base::~OStatement_Base() DBG_DTOR( file_OStatement_Base, NULL ); } //------------------------------------------------------------------------------ -void OStatement_Base::disposeResultSet() -{ - SAL_INFO( "connectivity.drivers", "file ocke.jans...@sun.com OStatement_Base::disposeResultSet" ); - // free the cursor if alive - Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY); - if (xComp.is()) - xComp->dispose(); - m_xResultSet.clear(); -} -//------------------------------------------------------------------------------ void OStatement_BASE2::disposing() { ::osl::MutexGuard aGuard(m_aMutex); - disposeResultSet(); - if(m_pSQLAnalyzer) m_pSQLAnalyzer->dispose(); @@ -203,32 +191,8 @@ void OStatement_Base::reset() throw (SQLException) ::osl::MutexGuard aGuard( m_aMutex ); checkDisposed(OStatement_BASE::rBHelper.bDisposed); - clearWarnings (); - if (m_xResultSet.get().is()) - clearMyResultSet(); -} -//-------------------------------------------------------------------- -// clearMyResultSet -// If a ResultSet was created for this Statement, close it -//-------------------------------------------------------------------- - -void OStatement_Base::clearMyResultSet () throw (SQLException) -{ - SAL_INFO( "connectivity.drivers", "file ocke.jans...@sun.com OStatement_Base::clearMyResultSet " ); - ::osl::MutexGuard aGuard( m_aMutex ); - checkDisposed(OStatement_BASE::rBHelper.bDisposed); - - try - { - Reference<XCloseable> xCloseable; - if ( ::comphelper::query_interface( m_xResultSet.get(), xCloseable ) ) - xCloseable->close(); - } - catch( const DisposedException& ) { } - - m_xResultSet.clear(); } // ------------------------------------------------------------------------- @@ -304,7 +268,6 @@ Reference< XResultSet > SAL_CALL OStatement::executeQuery( const OUString& sql ) OResultSet* pResult = createResultSet(); xRS = pResult; initializeResultSet(pResult); - m_xResultSet = Reference<XResultSet>(pResult); pResult->OpenImpl(); diff --git a/connectivity/source/inc/file/FPreparedStatement.hxx b/connectivity/source/inc/file/FPreparedStatement.hxx index cfe59c8..1682ba3 100644 --- a/connectivity/source/inc/file/FPreparedStatement.hxx +++ b/connectivity/source/inc/file/FPreparedStatement.hxx @@ -49,12 +49,12 @@ namespace connectivity OValueRefRow m_aParameterRow; ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData> m_xMetaData; - OResultSet* m_pResultSet; ::rtl::Reference<connectivity::OSQLColumns> m_xParamColumns; // the parameter columns // factory method for resultset's virtual OResultSet* createResultSet(); - ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet> initResultSet(); + ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > makeResultSet(); + void initResultSet(OResultSet*); void checkAndResizeParameters(sal_Int32 parameterIndex); void setParameter(sal_Int32 parameterIndex, const ORowSetValue& x); diff --git a/connectivity/source/inc/file/FResultSet.hxx b/connectivity/source/inc/file/FResultSet.hxx index 7bf87f6..342e91d 100644 --- a/connectivity/source/inc/file/FResultSet.hxx +++ b/connectivity/source/inc/file/FResultSet.hxx @@ -292,8 +292,6 @@ namespace connectivity inline void setEvaluationKeySet(TIntVector* _pEvaluationKeySet) { m_pEvaluationKeySet = _pEvaluationKeySet; } inline void setMetaData(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData>& _xMetaData) { m_xMetaData = _xMetaData;} - // clears the resultset so it can be reused by a preparedstatement - void clear(); static void setBoundedColumns(const OValueRefRow& _rRow, const OValueRefRow& _rSelectRow, const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns, diff --git a/connectivity/source/inc/file/FStatement.hxx b/connectivity/source/inc/file/FStatement.hxx index b4cad7c..4977591 100644 --- a/connectivity/source/inc/file/FStatement.hxx +++ b/connectivity/source/inc/file/FStatement.hxx @@ -69,7 +69,6 @@ namespace connectivity ::std::vector<TAscendingOrder> m_aOrderbyAscending; ::com::sun::star::sdbc::SQLWarning m_aLastWarning; - ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet> m_xResultSet; // The last ResultSet created ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> m_xDBMetaData; ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xColNames; // table columns // for this Statement @@ -115,10 +114,8 @@ namespace connectivity virtual OSQLAnalyzer* createAnalyzer(); void reset () throw( ::com::sun::star::sdbc::SQLException); - void clearMyResultSet () throw( ::com::sun::star::sdbc::SQLException); sal_Int32 getPrecision ( sal_Int32 sqlType); - void disposeResultSet(); void GetAssignValues(); void SetAssignValue(const OUString& aColumnName, const OUString& aValue, _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits