Free SQLVAR as appropriate. (firebird-sdbc)

Change-Id: I5742e178baa85f3faf80d95f57fed248f7984793
This commit is contained in:
Andrzej J.R. Hunt
2013-08-15 15:32:17 +01:00
parent c68aedab31
commit aca3d35a3b
8 changed files with 102 additions and 10 deletions

View File

@@ -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()

View File

@@ -265,8 +265,6 @@ void OResultSet::disposing(void)
MutexGuard aGuard(m_pConnection->getMutex());
// TODO: free the sqlda
m_xMetaData = NULL;
}
// -------------------------------------------------------------------------

View File

@@ -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>

View File

@@ -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: */

View File

@@ -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();

View File

@@ -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();

View File

@@ -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: */

View File

@@ -55,7 +55,7 @@ namespace connectivity
void mallocSQLVAR(XSQLDA* pSqlda);
// void freeSQLVAR(XSQLDA* pSqlda);
void freeSQLVAR(XSQLDA* pSqlda);
}
}
#endif //CONNECTIVITY_FIREBIRD_UTIL_HXX