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
This commit is contained in:
@@ -55,7 +55,6 @@ DBG_NAME( file_OPreparedStatement )
|
|||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
OPreparedStatement::OPreparedStatement( OConnection* _pConnection)
|
OPreparedStatement::OPreparedStatement( OConnection* _pConnection)
|
||||||
: OStatement_BASE2( _pConnection )
|
: OStatement_BASE2( _pConnection )
|
||||||
,m_pResultSet(NULL)
|
|
||||||
{
|
{
|
||||||
SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OPreparedStatement::OPreparedStatement" );
|
SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OPreparedStatement::OPreparedStatement" );
|
||||||
DBG_CTOR( file_OPreparedStatement, NULL );
|
DBG_CTOR( file_OPreparedStatement, NULL );
|
||||||
@@ -74,15 +73,8 @@ void OPreparedStatement::disposing()
|
|||||||
SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OPreparedStatement::disposing" );
|
SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OPreparedStatement::disposing" );
|
||||||
::osl::MutexGuard aGuard(m_aMutex);
|
::osl::MutexGuard aGuard(m_aMutex);
|
||||||
|
|
||||||
clearMyResultSet();
|
|
||||||
OStatement_BASE2::disposing();
|
OStatement_BASE2::disposing();
|
||||||
|
|
||||||
if(m_pResultSet)
|
|
||||||
{
|
|
||||||
m_pResultSet->release();
|
|
||||||
m_pResultSet = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_xParamColumns = NULL;
|
m_xParamColumns = NULL;
|
||||||
m_xMetaData.clear();
|
m_xMetaData.clear();
|
||||||
if(m_aParameterRow.is())
|
if(m_aParameterRow.is())
|
||||||
@@ -90,8 +82,6 @@ void OPreparedStatement::disposing()
|
|||||||
m_aParameterRow->get().clear();
|
m_aParameterRow->get().clear();
|
||||||
m_aParameterRow = NULL;
|
m_aParameterRow = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
void OPreparedStatement::construct(const OUString& sql) throw(SQLException, RuntimeException)
|
void OPreparedStatement::construct(const OUString& sql) throw(SQLException, RuntimeException)
|
||||||
@@ -115,12 +105,17 @@ void OPreparedStatement::construct(const OUString& sql) throw(SQLException, Run
|
|||||||
|
|
||||||
OValueRefRow aTemp;
|
OValueRefRow aTemp;
|
||||||
OResultSet::setBoundedColumns(m_aEvaluateRow,aTemp,m_xParamColumns,xNames,sal_False,m_xDBMetaData,m_aColMapping);
|
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)
|
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.Janssen@sun.com OPreparedStatement::close" );
|
SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OPreparedStatement::close" );
|
||||||
::osl::MutexGuard aGuard( m_aMutex );
|
::osl::MutexGuard aGuard( m_aMutex );
|
||||||
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
||||||
|
|
||||||
|
|
||||||
clearMyResultSet();
|
|
||||||
}
|
}
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -172,7 +164,12 @@ 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);
|
||||||
|
|
||||||
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;
|
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 );
|
::osl::MutexGuard aGuard( m_aMutex );
|
||||||
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
||||||
|
|
||||||
initResultSet();
|
Reference<XResultSet> xRS(makeResultSet());
|
||||||
|
if(xRS.is())
|
||||||
return m_pResultSet ? m_pResultSet->getRowCountResult() : sal_Int32(0);
|
{
|
||||||
|
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 );
|
::osl::MutexGuard aGuard( m_aMutex );
|
||||||
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
||||||
|
|
||||||
return initResultSet();
|
return makeResultSet();
|
||||||
}
|
}
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -408,21 +416,17 @@ OResultSet* OPreparedStatement::createResultSet()
|
|||||||
return new OResultSet(this,m_aSQLIterator);
|
return new OResultSet(this,m_aSQLIterator);
|
||||||
}
|
}
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
Reference<XResultSet> OPreparedStatement::initResultSet()
|
void OPreparedStatement::initResultSet(OResultSet *pResultSet)
|
||||||
{
|
{
|
||||||
SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OPreparedStatement::initResultSet" );
|
SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OPreparedStatement::initResultSet" );
|
||||||
m_pResultSet->clear();
|
|
||||||
Reference<XResultSet> xRs(m_pResultSet);
|
|
||||||
|
|
||||||
// check if we got enough parameters
|
// check if we got enough parameters
|
||||||
if ( (m_aParameterRow.is() && ( m_aParameterRow->get().size() -1 ) < m_xParamColumns->get().size()) ||
|
if ( (m_aParameterRow.is() && ( m_aParameterRow->get().size() -1 ) < m_xParamColumns->get().size()) ||
|
||||||
(m_xParamColumns.is() && !m_aParameterRow.is() && !m_aParameterRow->get().empty()) )
|
(m_xParamColumns.is() && !m_aParameterRow.is() && !m_aParameterRow->get().empty()) )
|
||||||
m_pConnection->throwGenericSQLException(STR_INVALID_PARA_COUNT,*this);
|
m_pConnection->throwGenericSQLException(STR_INVALID_PARA_COUNT,*this);
|
||||||
|
|
||||||
m_pResultSet->OpenImpl();
|
pResultSet->OpenImpl();
|
||||||
m_pResultSet->setMetaData(getMetaData());
|
pResultSet->setMetaData(getMetaData());
|
||||||
|
|
||||||
return xRs;
|
|
||||||
}
|
}
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
void SAL_CALL OPreparedStatement::acquire() throw()
|
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.Janssen@sun.com OPreparedStatement::initializeResultSet" );
|
SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OPreparedStatement::initializeResultSet" );
|
||||||
OStatement_Base::initializeResultSet(_pResult);
|
OStatement_Base::initializeResultSet(pRS);
|
||||||
|
|
||||||
m_pResultSet->setParameterColumns(m_xParamColumns);
|
pRS->setParameterColumns(m_xParamColumns);
|
||||||
m_pResultSet->setParameterRow(m_aParameterRow);
|
pRS->setParameterRow(m_aParameterRow);
|
||||||
|
|
||||||
// Substitute parameter (AssignValues and criteria):
|
// Substitute parameter (AssignValues and criteria):
|
||||||
if (!m_xParamColumns->get().empty())
|
if (!m_xParamColumns->get().empty())
|
||||||
|
@@ -166,12 +166,7 @@ void OResultSet::disposing(void)
|
|||||||
m_pTable->release();
|
m_pTable->release();
|
||||||
m_pTable = NULL;
|
m_pTable = NULL;
|
||||||
}
|
}
|
||||||
clear();
|
|
||||||
}
|
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
void OResultSet::clear()
|
|
||||||
{
|
|
||||||
SAL_INFO( "connectivity.drivers", "file Ocke.Janssen@sun.com OResultSet::clear" );
|
|
||||||
m_pFileSet = NULL;
|
m_pFileSet = NULL;
|
||||||
DELETEZ(m_pSortIndex);
|
DELETEZ(m_pSortIndex);
|
||||||
|
|
||||||
|
@@ -102,22 +102,10 @@ OStatement_Base::~OStatement_Base()
|
|||||||
DBG_DTOR( file_OStatement_Base, NULL );
|
DBG_DTOR( file_OStatement_Base, NULL );
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
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);
|
|
||||||
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();
|
||||||
|
|
||||||
@@ -203,32 +191,8 @@ void OStatement_Base::reset() throw (SQLException)
|
|||||||
::osl::MutexGuard aGuard( m_aMutex );
|
::osl::MutexGuard aGuard( m_aMutex );
|
||||||
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
|
||||||
|
|
||||||
|
|
||||||
clearWarnings ();
|
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.Janssen@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();
|
OResultSet* pResult = createResultSet();
|
||||||
xRS = pResult;
|
xRS = pResult;
|
||||||
initializeResultSet(pResult);
|
initializeResultSet(pResult);
|
||||||
m_xResultSet = Reference<XResultSet>(pResult);
|
|
||||||
|
|
||||||
pResult->OpenImpl();
|
pResult->OpenImpl();
|
||||||
|
|
||||||
|
@@ -49,12 +49,12 @@ namespace connectivity
|
|||||||
OValueRefRow m_aParameterRow;
|
OValueRefRow m_aParameterRow;
|
||||||
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData> m_xMetaData;
|
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData> m_xMetaData;
|
||||||
|
|
||||||
OResultSet* m_pResultSet;
|
|
||||||
::rtl::Reference<connectivity::OSQLColumns> m_xParamColumns; // the parameter columns
|
::rtl::Reference<connectivity::OSQLColumns> m_xParamColumns; // the parameter columns
|
||||||
|
|
||||||
// factory method for resultset's
|
// factory method for resultset's
|
||||||
virtual OResultSet* createResultSet();
|
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 checkAndResizeParameters(sal_Int32 parameterIndex);
|
||||||
void setParameter(sal_Int32 parameterIndex, const ORowSetValue& x);
|
void setParameter(sal_Int32 parameterIndex, const ORowSetValue& x);
|
||||||
|
@@ -292,8 +292,6 @@ namespace connectivity
|
|||||||
inline void setEvaluationKeySet(TIntVector* _pEvaluationKeySet) { m_pEvaluationKeySet = _pEvaluationKeySet; }
|
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;}
|
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,
|
static void setBoundedColumns(const OValueRefRow& _rRow,
|
||||||
const OValueRefRow& _rSelectRow,
|
const OValueRefRow& _rSelectRow,
|
||||||
const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns,
|
const ::rtl::Reference<connectivity::OSQLColumns>& _rxColumns,
|
||||||
|
@@ -69,7 +69,6 @@ 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
|
||||||
|
|
||||||
@@ -115,10 +114,8 @@ namespace connectivity
|
|||||||
virtual OSQLAnalyzer* createAnalyzer();
|
virtual OSQLAnalyzer* createAnalyzer();
|
||||||
|
|
||||||
void reset () throw( ::com::sun::star::sdbc::SQLException);
|
void reset () throw( ::com::sun::star::sdbc::SQLException);
|
||||||
void clearMyResultSet () 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,
|
||||||
|
Reference in New Issue
Block a user