summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2013-08-07 21:58:31 +0100
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2013-08-11 16:05:08 +0100
commit6044f52c5e34de55f1f07bf29519f0ed3b937516 (patch)
treeec8bdea9093fd73128617934b73e4edd9f3b3b08 /connectivity
parentaf0e281eed91238ddb2a77d51f9e7cb99b3a72d7 (diff)
Improve statement handle handling.
Change-Id: I81809634600c580bb50843e697071d62bc6802a4
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/drivers/firebird/PreparedStatement.cxx21
-rw-r--r--connectivity/source/drivers/firebird/PreparedStatement.hxx1
-rw-r--r--connectivity/source/drivers/firebird/ResultSet.cxx16
-rw-r--r--connectivity/source/drivers/firebird/Statement.cxx9
-rw-r--r--connectivity/source/drivers/firebird/StatementCommonBase.cxx46
-rw-r--r--connectivity/source/drivers/firebird/StatementCommonBase.hxx6
6 files changed, 51 insertions, 48 deletions
diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx
index f391618f3333..da53c7a4141a 100644
--- a/connectivity/source/drivers/firebird/PreparedStatement.cxx
+++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx
@@ -54,7 +54,6 @@ OPreparedStatement::OPreparedStatement( OConnection* _pConnection,
:OStatementCommonBase(_pConnection)
,m_aTypeInfo(_TypeInfo)
,m_sSqlStatement(sql)
- ,m_statementHandle(0)
,m_pOutSqlda(0)
,m_pInSqlda(0)
{
@@ -68,7 +67,7 @@ void OPreparedStatement::ensurePrepared()
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
- if (m_statementHandle)
+ if (m_aStatementHandle)
return;
ISC_STATUS aErr = 0;
@@ -81,17 +80,16 @@ void OPreparedStatement::ensurePrepared()
} // TODO: free this on closing
aErr = prepareAndDescribeStatement(m_sSqlStatement,
- m_statementHandle,
m_pOutSqlda,
m_pInSqlda);
if (aErr)
{
SAL_WARN("connectivity.firebird", "prepareAndDescribeStatement failed");
}
- else if (m_statementHandle)
+ else if (m_aStatementHandle)
{
isc_dsql_describe_bind(m_statusVector,
- &m_statementHandle,
+ &m_aStatementHandle,
1,
m_pInSqlda);
}
@@ -108,7 +106,7 @@ void OPreparedStatement::ensurePrepared()
m_pInSqlda->version = SQLDA_VERSION1;
m_pInSqlda->sqln = nItems;
isc_dsql_describe_bind(m_statusVector,
- &m_statementHandle,
+ &m_aStatementHandle,
1,
m_pInSqlda);
}
@@ -117,7 +115,7 @@ void OPreparedStatement::ensurePrepared()
// };
// char aResultBuffer[8];
// isc_dsql_sql_info(m_statusVector,
-// &m_statementHandle,
+// &m_aStatementHandle,
// sizeof(aItems),
// aItems,
// sizeof(aResultBuffer),
@@ -184,11 +182,6 @@ void SAL_CALL OPreparedStatement::close() throw(SQLException, RuntimeException)
MutexGuard aGuard( m_pConnection->getMutex() );
checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
- if (m_statementHandle)
- {
- // TODO: implement
- }
-
OStatementCommonBase::close();
}
@@ -265,7 +258,7 @@ sal_Bool SAL_CALL OPreparedStatement::execute()
aErr = isc_dsql_execute(m_statusVector,
&m_pConnection->getTransaction(),
- &m_statementHandle,
+ &m_aStatementHandle,
1,
m_pInSqlda);
if (aErr)
@@ -276,7 +269,7 @@ sal_Bool SAL_CALL OPreparedStatement::execute()
m_xResultSet = new OResultSet(m_pConnection,
uno::Reference< XInterface >(*this),
- m_statementHandle,
+ m_aStatementHandle,
m_pOutSqlda);
return m_xResultSet.is();
diff --git a/connectivity/source/drivers/firebird/PreparedStatement.hxx b/connectivity/source/drivers/firebird/PreparedStatement.hxx
index 60d5c662a827..afb73d74cd4b 100644
--- a/connectivity/source/drivers/firebird/PreparedStatement.hxx
+++ b/connectivity/source/drivers/firebird/PreparedStatement.hxx
@@ -69,7 +69,6 @@ namespace connectivity
::rtl::OUString m_sSqlStatement;
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > m_xMetaData;
- isc_stmt_handle m_statementHandle;
XSQLDA* m_pOutSqlda;
XSQLDA* m_pInSqlda;
void checkParameterIndex(sal_Int32 nParameterIndex)
diff --git a/connectivity/source/drivers/firebird/ResultSet.cxx b/connectivity/source/drivers/firebird/ResultSet.cxx
index ad7fe815862f..921305f03810 100644
--- a/connectivity/source/drivers/firebird/ResultSet.cxx
+++ b/connectivity/source/drivers/firebird/ResultSet.cxx
@@ -265,21 +265,7 @@ void OResultSet::disposing(void)
MutexGuard aGuard(m_pConnection->getMutex());
- if (m_statementHandle)
- {
- isc_dsql_free_statement(m_statusVector,
- &m_statementHandle,
- DSQL_drop);
- try {
- evaluateStatusVector(m_statusVector, "isc_dsql_free_statement", *this);
- }
- catch (SQLException e)
- {
- // we cannot throw any exceptions here anyway
- SAL_WARN("connectivity.firebird", "isc_dsql_free_statement failed\n" <<
- e.Message);
- }
- }
+ // TODO: free the sqlda
m_xMetaData = NULL;
}
diff --git a/connectivity/source/drivers/firebird/Statement.cxx b/connectivity/source/drivers/firebird/Statement.cxx
index 5317c43e0033..ed63ea69c893 100644
--- a/connectivity/source/drivers/firebird/Statement.cxx
+++ b/connectivity/source/drivers/firebird/Statement.cxx
@@ -110,12 +110,9 @@ uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& s
checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
XSQLDA* pOutSqlda = 0;
- isc_stmt_handle aStatementHandle = 0;
int aErr = 0;
-
aErr = prepareAndDescribeStatement(sql,
- aStatementHandle,
pOutSqlda);
if (aErr)
{
@@ -125,7 +122,7 @@ uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& s
{
aErr = isc_dsql_execute(m_statusVector,
&m_pConnection->getTransaction(),
- &aStatementHandle,
+ &m_aStatementHandle,
1,
NULL);
if (aErr)
@@ -134,7 +131,7 @@ uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& s
m_xResultSet = new OResultSet(m_pConnection,
uno::Reference< XInterface >(*this),
- aStatementHandle,
+ m_aStatementHandle,
pOutSqlda);
// TODO: deal with cleanup
@@ -142,7 +139,7 @@ uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& s
evaluateStatusVector(m_statusVector, sql, *this);
- if (isDDLStatement(aStatementHandle))
+ if (isDDLStatement(m_aStatementHandle))
{
m_pConnection->commit();
}
diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.cxx b/connectivity/source/drivers/firebird/StatementCommonBase.cxx
index baf53ca95676..ee294fe55533 100644
--- a/connectivity/source/drivers/firebird/StatementCommonBase.cxx
+++ b/connectivity/source/drivers/firebird/StatementCommonBase.cxx
@@ -48,6 +48,7 @@ OStatementCommonBase::OStatementCommonBase(OConnection* _pConnection)
: OStatementCommonBase_Base(_pConnection->getMutex()),
OPropertySetHelper(OStatementCommonBase_Base::rBHelper),
m_pConnection(_pConnection),
+ m_aStatementHandle( 0 ),
rBHelper(OStatementCommonBase_Base::rBHelper)
{
m_pConnection->acquire();
@@ -65,6 +66,28 @@ void OStatementCommonBase::disposeResultSet()
m_xResultSet = uno::Reference< XResultSet>();
}
+void OStatementCommonBase::freeStatementHandle()
+ throw (SQLException)
+{
+ if (m_aStatementHandle)
+ {
+ isc_dsql_free_statement(m_statusVector,
+ &m_aStatementHandle,
+ DSQL_drop);
+ try {
+ evaluateStatusVector(m_statusVector,
+ "isc_dsql_free_statement",
+ *this);
+ }
+ catch (SQLException e)
+ {
+ // we cannot throw any exceptions here anyway
+ SAL_WARN("connectivity.firebird",
+ "isc_dsql_free_statement failed\n" << e.Message);
+ }
+ }
+}
+
//-----------------------------------------------------------------------------
Any SAL_CALL OStatementCommonBase::queryInterface( const Type & rType ) throw(RuntimeException)
{
@@ -91,27 +114,30 @@ void SAL_CALL OStatementCommonBase::cancel( ) throw(RuntimeException)
checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
// cancel the current sql statement
}
-// -------------------------------------------------------------------------
-void SAL_CALL OStatementCommonBase::close( ) throw(SQLException, RuntimeException)
+void SAL_CALL OStatementCommonBase::close()
+ throw(SQLException, RuntimeException)
{
- SAL_INFO("connectivity.firebird", "close().");
+ SAL_INFO("connectivity.firebird", "close");
{
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
disposeResultSet();
+ freeStatementHandle();
}
+
dispose();
}
int OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql,
- isc_stmt_handle& aStatementHandle,
- XSQLDA*& pOutSqlda,
- XSQLDA* pInSqlda)
+ XSQLDA*& pOutSqlda,
+ XSQLDA* pInSqlda)
{
MutexGuard aGuard(m_pConnection->getMutex());
+ freeStatementHandle();
+
if (!pOutSqlda)
{
pOutSqlda = (XSQLDA*) malloc(XSQLDA_LENGTH(10));
@@ -123,7 +149,7 @@ int OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql,
aErr = isc_dsql_allocate_statement(m_statusVector,
&m_pConnection->getDBHandle(),
- &aStatementHandle);
+ &m_aStatementHandle);
if (aErr)
{
@@ -134,7 +160,7 @@ int OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql,
{
aErr = isc_dsql_prepare(m_statusVector,
&m_pConnection->getTransaction(),
- &aStatementHandle,
+ &m_aStatementHandle,
0,
OUStringToOString(sql, RTL_TEXTENCODING_UTF8).getStr(),
FIREBIRD_SQL_DIALECT,
@@ -149,7 +175,7 @@ int OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql,
else
{
aErr = isc_dsql_describe(m_statusVector,
- &aStatementHandle,
+ &m_aStatementHandle,
1,
pOutSqlda);
}
@@ -167,7 +193,7 @@ int OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql,
pOutSqlda = (XSQLDA*) malloc(XSQLDA_LENGTH(n));
pOutSqlda->version = SQLDA_VERSION1;
aErr = isc_dsql_describe(m_statusVector,
- &aStatementHandle,
+ &m_aStatementHandle,
1,
pOutSqlda);
}
diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.hxx b/connectivity/source/drivers/firebird/StatementCommonBase.hxx
index 0496b11c2457..a64026e8bc2b 100644
--- a/connectivity/source/drivers/firebird/StatementCommonBase.hxx
+++ b/connectivity/source/drivers/firebird/StatementCommonBase.hxx
@@ -61,9 +61,12 @@ namespace connectivity
OConnection* m_pConnection;
ISC_STATUS_ARRAY m_statusVector;
- protected:
+ isc_stmt_handle m_aStatementHandle;
+ protected:
void disposeResultSet();
+ void freeStatementHandle()
+ throw (::com::sun::star::sdbc::SQLException);
// OPropertyArrayUsageHelper
virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
@@ -84,7 +87,6 @@ namespace connectivity
sal_Int32 nHandle) const;
virtual ~OStatementCommonBase();
int prepareAndDescribeStatement(const OUString& sqlIn,
- isc_stmt_handle& aStatementHandle,
XSQLDA*& pOutSqlda,
XSQLDA* pInSqlda=0);
bool isDDLStatement(isc_stmt_handle& aStatementHandle)