connectivity/source/drivers/firebird/PreparedStatement.cxx | 17 +++ connectivity/source/drivers/firebird/ResultSet.cxx | 2 connectivity/source/drivers/firebird/ResultSet.hxx | 6 + connectivity/source/drivers/firebird/Statement.cxx | 23 +++- connectivity/source/drivers/firebird/Statement.hxx | 8 + connectivity/source/drivers/firebird/StatementCommonBase.hxx | 7 - connectivity/source/drivers/firebird/Table.cxx | 11 ++ connectivity/source/drivers/firebird/Table.hxx | 3 connectivity/source/drivers/firebird/Tables.cxx | 56 ++++++++--- connectivity/source/drivers/firebird/Tables.hxx | 25 ++-- connectivity/source/drivers/firebird/Util.cxx | 47 +++++++++ connectivity/source/drivers/firebird/Util.hxx | 2 12 files changed, 170 insertions(+), 37 deletions(-)
New commits: commit aca3d35a3b950bd6bc7681787cc4fa10c2e01683 Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Thu Aug 15 15:32:17 2013 +0100 Free SQLVAR as appropriate. (firebird-sdbc) Change-Id: I5742e178baa85f3faf80d95f57fed248f7984793 diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx index 9a9f988..70d6d36 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 921305f..aac6622 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 a741295..6cfec8d 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 db44f51..5a6d85f 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 bfac534..1818802 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 db172fa..bb4fc3c 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 cc8f5d7..bdf673e 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 9818482..589337f 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 commit c68aedab311f6a85857113bcd92fdfe51f089507 Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Thu Aug 15 11:33:54 2013 +0100 Implement dropping tables. (firebird-sdbc) Change-Id: I68ef5bdfb3007709444b838f3c7c3925acc9dd32 diff --git a/connectivity/source/drivers/firebird/Tables.cxx b/connectivity/source/drivers/firebird/Tables.cxx index 5265703..fc55d2a 100644 --- a/connectivity/source/drivers/firebird/Tables.cxx +++ b/connectivity/source/drivers/firebird/Tables.cxx @@ -96,18 +96,25 @@ ObjectType Tables::appendObject(const OUString& rName, return createObject(rName); } -// //----- XDrop ---------------------------------------------------------------- -// void SAL_CALL Tables::dropByName(const OUString& rName) -// throw (SQLException, NoSuchElementException, RuntimeException) -// { -// (void) rName; -// // TODO: IMPLEMENT ME -// } -// -// void SAL_CALL Tables::dropByIndex(const sal_Int32 nIndex) -// throw (SQLException, IndexOutOfBoundsException, RuntimeException) -// { -// (void) nIndex; -// // TODO: IMPLEMENT ME -// } + +//----- XDrop ----------------------------------------------------------------- +void Tables::dropObject(sal_Int32 nPosition, const OUString sName) +{ + uno::Reference< XPropertySet > xTable(getObject(nPosition)); + + if (!ODescriptor::isNew(xTable)) + { + OUStringBuffer sSql("DROP "); + + OUString sType; + xTable->getPropertyValue("Type") >>= sType; + sSql.append(sType); + + const OUString sQuoteString = m_xMetaData->getIdentifierQuoteString(); + sSql.append(::dbtools::quoteName(sQuoteString,sName)); + + m_xMetaData->getConnection()->createStatement()->execute(sSql.makeStringAndClear()); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file diff --git a/connectivity/source/drivers/firebird/Tables.hxx b/connectivity/source/drivers/firebird/Tables.hxx index 173d957..b2e570f 100644 --- a/connectivity/source/drivers/firebird/Tables.hxx +++ b/connectivity/source/drivers/firebird/Tables.hxx @@ -52,15 +52,9 @@ namespace connectivity // TODO: we should also implement XDataDescriptorFactory, XRefreshable, // XAppend, etc., but all are optional. -// // XDrop -// virtual void SAL_CALL dropByName(const ::rtl::OUString& rName) -// throw (::com::sun::star::sdbc::SQLException, -// ::com::sun::star::container::NoSuchElementException, -// ::com::sun::star::uno::RuntimeException); -// virtual void SAL_CALL dropByIndex(const sal_Int32 nIndex) -// throw (::com::sun::star::sdbc::SQLException, -// com::sun::star::lang::IndexOutOfBoundsException, -// ::com::sun::star::uno::RuntimeException); + // XDrop + virtual void dropObject(sal_Int32 nPosition, const ::rtl::OUString rName); + }; } // namespace firebird commit 6cb1f56fced634e0692c82cd9b2c7d240a32c14b Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Thu Aug 15 10:51:57 2013 +0100 Implement sdbcx table creation. (firebird-sdbc) Change-Id: I3d0de21a5fe10b64e21955f3384b95a96ac7561e diff --git a/connectivity/source/drivers/firebird/Table.cxx b/connectivity/source/drivers/firebird/Table.cxx index 38b0bcb..d32066f 100644 --- a/connectivity/source/drivers/firebird/Table.cxx +++ b/connectivity/source/drivers/firebird/Table.cxx @@ -29,6 +29,17 @@ using namespace ::com::sun::star::uno; Table::Table(Tables* pTables, Mutex& rMutex, + const uno::Reference< XConnection >& rConnection): + OTableHelper(pTables, + rConnection, + sal_True), + m_rMutex(rMutex) +{ + OTableHelper::construct(); +} + +Table::Table(Tables* pTables, + Mutex& rMutex, const uno::Reference< XConnection >& rConnection, const OUString& rName, const OUString& rType, diff --git a/connectivity/source/drivers/firebird/Table.hxx b/connectivity/source/drivers/firebird/Table.hxx index ff9d183..41f12c3 100644 --- a/connectivity/source/drivers/firebird/Table.hxx +++ b/connectivity/source/drivers/firebird/Table.hxx @@ -37,6 +37,9 @@ namespace connectivity public: Table(Tables* pTables, ::osl::Mutex& rMutex, + const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection); + Table(Tables* pTables, + ::osl::Mutex& rMutex, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _xConnection, const ::rtl::OUString& rName, const ::rtl::OUString& rType, diff --git a/connectivity/source/drivers/firebird/Tables.cxx b/connectivity/source/drivers/firebird/Tables.cxx index 0dbca85..5265703 100644 --- a/connectivity/source/drivers/firebird/Tables.cxx +++ b/connectivity/source/drivers/firebird/Tables.cxx @@ -10,6 +10,8 @@ #include "Table.hxx" #include "Tables.hxx" +#include <connectivity/dbtools.hxx> + #include <com/sun/star/sdbc/XRow.hpp> using namespace ::connectivity; @@ -20,6 +22,7 @@ using namespace ::osl; using namespace ::rtl; using namespace ::com::sun::star; +using namespace ::com::sun::star::beans; using namespace ::com::sun::star::container; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::sdbc; @@ -75,6 +78,24 @@ ObjectType Tables::createObject(const OUString& rName) return xRet; } +uno::Reference< XPropertySet > Tables::createDescriptor() +{ + // There is some internal magic so that the same class can be used as either + // a descriptor or as a normal table. See VTable.cxx for the details. In our + // case we just need to ensure we use the correct constructor. + return new Table(this, m_rMutex, m_xMetaData->getConnection()); +} + +//----- XAppend --------------------------------------------------------------- +ObjectType Tables::appendObject(const OUString& rName, + const uno::Reference< XPropertySet >& rDescriptor) +{ + OUString sSql(::dbtools::createSqlCreateTableStatement(rDescriptor, + m_xMetaData->getConnection())); + m_xMetaData->getConnection()->createStatement()->execute(sSql); + + return createObject(rName); +} // //----- XDrop ---------------------------------------------------------------- // void SAL_CALL Tables::dropByName(const OUString& rName) // throw (SQLException, NoSuchElementException, RuntimeException) diff --git a/connectivity/source/drivers/firebird/Tables.hxx b/connectivity/source/drivers/firebird/Tables.hxx index c025e1b..173d957 100644 --- a/connectivity/source/drivers/firebird/Tables.hxx +++ b/connectivity/source/drivers/firebird/Tables.hxx @@ -29,14 +29,19 @@ namespace connectivity ::osl::Mutex& m_rMutex; protected: - // OCollection: pure virtual functions requiring implementation + ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > + m_xMetaData; + + // OCollection virtual void impl_refresh() throw(::com::sun::star::uno::RuntimeException); virtual ::connectivity::sdbcx::ObjectType createObject( const ::rtl::OUString& rName); - - ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData > - m_xMetaData; + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > + createDescriptor(); + virtual ::connectivity::sdbcx::ObjectType appendObject( + const OUString& rName, + const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& rDescriptor); public: Tables(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData >& rMetaData, _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits