fdo#80084 file driver PreparedStatement: close previous ResultSet on reexec

This partially reverts commit d87c2c59c9
"sdbc file driver (Prepared)Statement: created ResultSet owned by *caller*"

From that commit, we keep the part about not reusing the same
ResultSet on reexecution (client code may have disposed it or closed
it), but we revert the part about not closing / disposing the previous
ResultSet on reexecution.

Change-Id: I4946207f9740484b2f5fbc3575a5708fe39f357c
This commit is contained in:
Lionel Elie Mamane
2014-06-17 18:12:45 +02:00
parent 6ba2e7fba0
commit 2504ffccd0
3 changed files with 36 additions and 8 deletions

View File

@@ -101,15 +101,16 @@ void OPreparedStatement::construct(const OUString& sql) throw(SQLException, Run
Reference<XResultSet> OPreparedStatement::makeResultSet() Reference<XResultSet> OPreparedStatement::makeResultSet()
{ {
closeResultSet();
OResultSet *pResultSet = createResultSet(); OResultSet *pResultSet = createResultSet();
Reference<XResultSet> xRS(pResultSet); Reference<XResultSet> xRS(pResultSet);
initializeResultSet(pResultSet); initializeResultSet(pResultSet);
initResultSet(pResultSet); initResultSet(pResultSet);
m_xResultSet = xRS;
return xRS; 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)
{ {
Any aRet = OStatement_BASE2::queryInterface(rType); Any aRet = OStatement_BASE2::queryInterface(rType);
@@ -145,6 +146,8 @@ void SAL_CALL OPreparedStatement::close( ) throw(SQLException, RuntimeException
{ {
::osl::MutexGuard aGuard( m_aMutex ); ::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(OStatement_BASE::rBHelper.bDisposed); checkDisposed(OStatement_BASE::rBHelper.bDisposed);
closeResultSet();
} }
@@ -157,6 +160,7 @@ sal_Bool SAL_CALL OPreparedStatement::execute( ) throw(SQLException, RuntimeExc
// 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); Reference< XComponent > xComp(xRS, UNO_QUERY);
assert(xComp.is() || !xRS.is());
if (xComp.is()) if (xComp.is())
xComp->dispose(); xComp->dispose();
@@ -512,7 +516,6 @@ void OPreparedStatement::describeParameter()
} }
} }
} }
void OPreparedStatement::initializeResultSet(OResultSet* pRS) void OPreparedStatement::initializeResultSet(OResultSet* pRS)
{ {
OStatement_Base::initializeResultSet(pRS); OStatement_Base::initializeResultSet(pRS);

View File

@@ -95,10 +95,23 @@ OStatement_Base::~OStatement_Base()
delete m_pSQLAnalyzer; delete m_pSQLAnalyzer;
} }
void OStatement_Base::disposeResultSet()
{
SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::disposeResultSet" );
// free the cursor if alive
Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY);
assert(xComp.is() || !m_xResultSet.get().is());
if (xComp.is())
xComp->dispose();
m_xResultSet.clear();
}
void OStatement_BASE2::disposing() void OStatement_BASE2::disposing()
{ {
::osl::MutexGuard aGuard(m_aMutex); ::osl::MutexGuard aGuard(m_aMutex);
disposeResultSet();
if(m_pSQLAnalyzer) if(m_pSQLAnalyzer)
m_pSQLAnalyzer->dispose(); m_pSQLAnalyzer->dispose();
@@ -173,17 +186,26 @@ void SAL_CALL OStatement_Base::close( ) throw(SQLException, RuntimeException, s
dispose(); dispose();
} }
void OStatement_Base::closeResultSet () throw (SQLException)
void OStatement_Base::reset() throw (SQLException)
{ {
SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OStatement_Base::clearMyResultSet " );
::osl::MutexGuard aGuard( m_aMutex ); ::osl::MutexGuard aGuard( m_aMutex );
checkDisposed(OStatement_BASE::rBHelper.bDisposed); checkDisposed(OStatement_BASE::rBHelper.bDisposed);
clearWarnings (); Reference< XCloseable > xCloseable(m_xResultSet.get(), UNO_QUERY);
assert(xCloseable.is() || !m_xResultSet.get().is());
if (xCloseable.is())
{
try
{
xCloseable->close();
}
catch( const DisposedException& ) { }
}
m_xResultSet.clear();
} }
Any SAL_CALL OStatement_Base::getWarnings( ) throw(SQLException, RuntimeException, std::exception) Any SAL_CALL OStatement_Base::getWarnings( ) throw(SQLException, RuntimeException, std::exception)
{ {
::osl::MutexGuard aGuard( m_aMutex ); ::osl::MutexGuard aGuard( m_aMutex );
@@ -252,6 +274,7 @@ Reference< XResultSet > SAL_CALL OStatement::executeQuery( const OUString& sql )
OResultSet* pResult = createResultSet(); OResultSet* pResult = createResultSet();
xRS = pResult; xRS = pResult;
initializeResultSet(pResult); initializeResultSet(pResult);
m_xResultSet = xRS;
pResult->OpenImpl(); pResult->OpenImpl();

View File

@@ -68,6 +68,7 @@ namespace connectivity
::std::vector<TAscendingOrder> m_aOrderbyAscending; ::std::vector<TAscendingOrder> m_aOrderbyAscending;
::com::sun::star::sdbc::SQLWarning m_aLastWarning; ::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::sdbc::XDatabaseMetaData> m_xDBMetaData;
::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xColNames; // table columns // for this Statement ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xColNames; // table columns // for this Statement
@@ -112,9 +113,10 @@ namespace connectivity
// create the analyzer // create the analyzer
virtual OSQLAnalyzer* createAnalyzer(); virtual OSQLAnalyzer* createAnalyzer();
void reset () throw( ::com::sun::star::sdbc::SQLException); void closeResultSet () throw( ::com::sun::star::sdbc::SQLException);
sal_Int32 getPrecision ( sal_Int32 sqlType); sal_Int32 getPrecision ( sal_Int32 sqlType);
void disposeResultSet();
void GetAssignValues(); void GetAssignValues();
void SetAssignValue(const OUString& aColumnName, void SetAssignValue(const OUString& aColumnName,
const OUString& aValue, const OUString& aValue,