summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2013-08-15 15:32:17 +0100
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2013-08-15 20:31:14 +0100
commitaca3d35a3b950bd6bc7681787cc4fa10c2e01683 (patch)
tree42838383e50a74f2f3f969de22bd9e75169323f2 /connectivity
parentc68aedab311f6a85857113bcd92fdfe51f089507 (diff)
Free SQLVAR as appropriate. (firebird-sdbc)
Change-Id: I5742e178baa85f3faf80d95f57fed248f7984793
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/drivers/firebird/PreparedStatement.cxx17
-rw-r--r--connectivity/source/drivers/firebird/ResultSet.cxx2
-rw-r--r--connectivity/source/drivers/firebird/ResultSet.hxx6
-rw-r--r--connectivity/source/drivers/firebird/Statement.cxx23
-rw-r--r--connectivity/source/drivers/firebird/Statement.hxx8
-rw-r--r--connectivity/source/drivers/firebird/StatementCommonBase.hxx7
-rw-r--r--connectivity/source/drivers/firebird/Util.cxx47
-rw-r--r--connectivity/source/drivers/firebird/Util.hxx2
8 files changed, 102 insertions, 10 deletions
diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx
index 9a9f9888a4de..70d6d360216b 100644
--- a/connectivity/source/drivers/firebird/PreparedStatement.cxx
+++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx
@@ -77,7 +77,7 @@ void OPreparedStatement::ensurePrepared()
m_pInSqlda = (XSQLDA*) malloc(XSQLDA_LENGTH(10));
m_pInSqlda->version = SQLDA_VERSION1;
m_pInSqlda->sqln = 10;
- } // TODO: free this on closing
+ }
prepareAndDescribeStatement(m_sSqlStatement,
m_pOutSqlda,
@@ -172,7 +172,22 @@ Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData()
void SAL_CALL OPreparedStatement::close() throw(SQLException, RuntimeException)
{
+ MutexGuard aGuard( m_pConnection->getMutex() );
+ checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
+
OStatementCommonBase::close();
+ if (m_pInSqlda)
+ {
+ freeSQLVAR(m_pInSqlda);
+ free(m_pInSqlda);
+ m_pInSqlda = 0;
+ }
+ if (m_pOutSqlda)
+ {
+ freeSQLVAR(m_pOutSqlda);
+ free(m_pOutSqlda);
+ m_pOutSqlda = 0;
+ }
}
void SAL_CALL OPreparedStatement::disposing()
diff --git a/connectivity/source/drivers/firebird/ResultSet.cxx b/connectivity/source/drivers/firebird/ResultSet.cxx
index 921305f03810..aac66220ed22 100644
--- a/connectivity/source/drivers/firebird/ResultSet.cxx
+++ b/connectivity/source/drivers/firebird/ResultSet.cxx
@@ -265,8 +265,6 @@ void OResultSet::disposing(void)
MutexGuard aGuard(m_pConnection->getMutex());
- // TODO: free the sqlda
-
m_xMetaData = NULL;
}
// -------------------------------------------------------------------------
diff --git a/connectivity/source/drivers/firebird/ResultSet.hxx b/connectivity/source/drivers/firebird/ResultSet.hxx
index a741295ed8cf..6cfec8d7606a 100644
--- a/connectivity/source/drivers/firebird/ResultSet.hxx
+++ b/connectivity/source/drivers/firebird/ResultSet.hxx
@@ -60,6 +60,12 @@ namespace connectivity
::com::sun::star::sdbc::XColumnLocate,
::com::sun::star::lang::XServiceInfo> OResultSet_BASE;
+ /**
+ * This ResultSet does not deal with the management of the SQLDA
+ * it is supplied with. The owner must mange its SQLDA appropriately
+ * and ensure that the ResultSet is destroyed before disposing of the
+ * SQLDA.
+ */
class OResultSet : public OResultSet_BASE,
public ::cppu::OPropertySetHelper,
public OPropertyArrayUsageHelper<OResultSet>
diff --git a/connectivity/source/drivers/firebird/Statement.cxx b/connectivity/source/drivers/firebird/Statement.cxx
index db44f51e7323..5a6d85fd8930 100644
--- a/connectivity/source/drivers/firebird/Statement.cxx
+++ b/connectivity/source/drivers/firebird/Statement.cxx
@@ -78,6 +78,21 @@ void SAL_CALL OStatement::release() throw()
OStatementCommonBase::release();
}
+void OStatement::disposeResultSet()
+{
+ MutexGuard aGuard(m_pConnection->getMutex());
+ checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
+
+ OStatementCommonBase::disposeResultSet();
+
+ if (m_pSqlda)
+ {
+ freeSQLVAR(m_pSqlda);
+ free(m_pSqlda);
+ m_pSqlda = 0;
+ }
+}
+
// ---- XStatement -----------------------------------------------------------
sal_Int32 SAL_CALL OStatement::executeUpdate(const OUString& sql)
throw(SQLException, RuntimeException)
@@ -109,11 +124,12 @@ uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& s
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
- XSQLDA* pOutSqlda = 0;
ISC_STATUS aErr = 0;
+ disposeResultSet();
+
prepareAndDescribeStatement(sql,
- pOutSqlda);
+ m_pSqlda);
aErr = isc_dsql_execute(m_statusVector,
&m_pConnection->getTransaction(),
@@ -126,7 +142,7 @@ uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& s
m_xResultSet = new OResultSet(m_pConnection,
uno::Reference< XInterface >(*this),
m_aStatementHandle,
- pOutSqlda);
+ m_pSqlda);
// TODO: deal with cleanup
@@ -179,6 +195,7 @@ void SAL_CALL OStatement::close() throw(SQLException, RuntimeException)
void SAL_CALL OStatement::disposing()
{
+ disposeResultSet();
close();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/firebird/Statement.hxx b/connectivity/source/drivers/firebird/Statement.hxx
index bfac534c74c0..18188020c17b 100644
--- a/connectivity/source/drivers/firebird/Statement.hxx
+++ b/connectivity/source/drivers/firebird/Statement.hxx
@@ -39,12 +39,18 @@ namespace connectivity
{
protected:
virtual ~OStatement(){}
+
+ XSQLDA* m_pSqlda;
+
public:
// a constructor, which is required for returning objects:
OStatement( OConnection* _pConnection)
- : OStatementCommonBase( _pConnection)
+ : OStatementCommonBase( _pConnection),
+ m_pSqlda(0)
{}
+ virtual void disposeResultSet();
+
DECLARE_SERVICE_INFO();
virtual void SAL_CALL acquire() throw();
diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.hxx b/connectivity/source/drivers/firebird/StatementCommonBase.hxx
index db172fa1e04e..bb4fc3c14910 100644
--- a/connectivity/source/drivers/firebird/StatementCommonBase.hxx
+++ b/connectivity/source/drivers/firebird/StatementCommonBase.hxx
@@ -64,7 +64,7 @@ namespace connectivity
isc_stmt_handle m_aStatementHandle;
protected:
- void disposeResultSet();
+ virtual void disposeResultSet();
void freeStatementHandle()
throw (::com::sun::star::sdbc::SQLException);
@@ -102,7 +102,10 @@ namespace connectivity
using OStatementCommonBase_Base::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
// OComponentHelper
- virtual void SAL_CALL disposing(void){OStatementCommonBase_Base::disposing();}
+ virtual void SAL_CALL disposing(void){
+ disposeResultSet();
+ OStatementCommonBase_Base::disposing();
+ }
// XInterface
virtual void SAL_CALL release() throw();
virtual void SAL_CALL acquire() throw();
diff --git a/connectivity/source/drivers/firebird/Util.cxx b/connectivity/source/drivers/firebird/Util.cxx
index cc8f5d72ed17..bdf673e3b862 100644
--- a/connectivity/source/drivers/firebird/Util.cxx
+++ b/connectivity/source/drivers/firebird/Util.cxx
@@ -251,4 +251,51 @@ void firebird::mallocSQLVAR(XSQLDA* pSqlda)
}
}
}
+
+void firebird::freeSQLVAR(XSQLDA* pSqlda)
+{
+ XSQLVAR* pVar = pSqlda->sqlvar;
+ for (int i=0; i < pSqlda->sqld; i++, pVar++)
+ {
+ int dtype = (pVar->sqltype & ~1); /* drop flag bit for now */
+ switch(dtype) {
+ case SQL_TEXT:
+ case SQL_VARYING:
+ case SQL_SHORT:
+ case SQL_LONG:
+ case SQL_FLOAT:
+ case SQL_DOUBLE:
+ case SQL_D_FLOAT:
+ case SQL_TIMESTAMP:
+ case SQL_BLOB:
+ case SQL_INT64:
+ free(pVar->sqldata);
+ break;
+ case SQL_ARRAY:
+ assert(false); // TODO: implement
+ break;
+ case SQL_TYPE_TIME:
+ assert(false); // TODO: implement
+ break;
+ case SQL_TYPE_DATE:
+ assert(false); // TODO: implement
+ break;
+ case SQL_NULL:
+ assert(false); // TODO: implement
+ break;
+ case SQL_QUAD:
+ assert(false); // TODO: implement
+ break;
+ default:
+ SAL_WARN("connectivity.firebird", "Unknown type: " << dtype);
+ assert(false);
+ break;
+ }
+
+ if (pVar->sqltype & 1)
+ {
+ free(pVar->sqlind);
+ }
+ }
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file
diff --git a/connectivity/source/drivers/firebird/Util.hxx b/connectivity/source/drivers/firebird/Util.hxx
index 9818482b6f39..589337fc737a 100644
--- a/connectivity/source/drivers/firebird/Util.hxx
+++ b/connectivity/source/drivers/firebird/Util.hxx
@@ -55,7 +55,7 @@ namespace connectivity
void mallocSQLVAR(XSQLDA* pSqlda);
-// void freeSQLVAR(XSQLDA* pSqlda);
+ void freeSQLVAR(XSQLDA* pSqlda);
}
}
#endif //CONNECTIVITY_FIREBIRD_UTIL_HXX