connectivity/source/drivers/firebird/Connection.cxx | 37 +++++-- connectivity/source/drivers/firebird/Connection.hxx | 4 connectivity/source/drivers/firebird/DatabaseMetaData.cxx | 6 - connectivity/source/drivers/firebird/PreparedStatement.cxx | 14 +- connectivity/source/drivers/firebird/ResultSet.cxx | 12 ++ connectivity/source/drivers/firebird/Statement.cxx | 54 ++--------- connectivity/source/drivers/firebird/StatementCommonBase.cxx | 47 +++++++-- connectivity/source/drivers/firebird/StatementCommonBase.hxx | 5 - 8 files changed, 104 insertions(+), 75 deletions(-)
New commits: commit 54a138db910554e8bf2868facc85e47b1776bac2 Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Wed Aug 7 18:18:09 2013 +0100 Commit after DDL statement. (firebird-sdbc) Changes made in a DDL statement are only usable after a commit in firebird, e.g. a created table won't appear etc. Change-Id: I3b537f495b6bc96fa48ebc1a3e46205da60bb2d4 diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx index cc19be6..177d041 100644 --- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx +++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx @@ -393,20 +393,20 @@ sal_Bool SAL_CALL ODatabaseMetaData::dataDefinitionIgnoredInTransactions() sal_Bool SAL_CALL ODatabaseMetaData::dataDefinitionCausesTransactionCommit() throw(SQLException, RuntimeException) { - return sal_False; + return sal_True; } sal_Bool SAL_CALL ODatabaseMetaData::supportsDataManipulationTransactionsOnly() throw(SQLException, RuntimeException) { - return sal_False; + return sal_True; } sal_Bool SAL_CALL ODatabaseMetaData:: supportsDataDefinitionAndDataManipulationTransactions() throw(SQLException, RuntimeException) { - return sal_True; + return sal_False; } //----- Transaction Support -------------------------------------------------- sal_Bool SAL_CALL ODatabaseMetaData::supportsTransactions() diff --git a/connectivity/source/drivers/firebird/Statement.cxx b/connectivity/source/drivers/firebird/Statement.cxx index 6f2ee58..5317c43 100644 --- a/connectivity/source/drivers/firebird/Statement.cxx +++ b/connectivity/source/drivers/firebird/Statement.cxx @@ -139,7 +139,14 @@ uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& s // TODO: deal with cleanup // close(); + evaluateStatusVector(m_statusVector, sql, *this); + + if (isDDLStatement(aStatementHandle)) + { + m_pConnection->commit(); + } + return m_xResultSet; } diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.cxx b/connectivity/source/drivers/firebird/StatementCommonBase.cxx index d3ee72c..baf53ca 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.cxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.cxx @@ -321,4 +321,32 @@ uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OStatementC return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); } +bool OStatementCommonBase::isDDLStatement(isc_stmt_handle& aStatementHandle) + throw (SQLException) +{ + ISC_STATUS_ARRAY aStatusVector; + ISC_STATUS aErr; + + char aInfoItems[] = {isc_info_sql_stmt_type}; + char aResultsBuffer[8]; + + aErr = isc_dsql_sql_info(aStatusVector, + &aStatementHandle, + sizeof(aInfoItems), + aInfoItems, + sizeof(aResultsBuffer), + aResultsBuffer); + + if (!aErr && aResultsBuffer[0] == isc_info_sql_stmt_type) + { + const short aBytes = (short) isc_vax_integer(aResultsBuffer+1, 2); + const short aStatementType = (short) isc_vax_integer(aResultsBuffer+3, aBytes); + if (aStatementType == isc_info_sql_stmt_ddl) + return true; + } + evaluateStatusVector(aStatusVector, + "isc_dsq_sql_info", + *this); + return false; +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.hxx b/connectivity/source/drivers/firebird/StatementCommonBase.hxx index 12483a6..0496b11 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.hxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.hxx @@ -87,6 +87,9 @@ namespace connectivity isc_stmt_handle& aStatementHandle, XSQLDA*& pOutSqlda, XSQLDA* pInSqlda=0); + bool isDDLStatement(isc_stmt_handle& aStatementHandle) + throw (::com::sun::star::sdbc::SQLException); + public: ::cppu::OBroadcastHelper& rBHelper; commit 89b37927c0cd62cd648dd7d085c761545451e659 Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Wed Aug 7 18:16:41 2013 +0100 Add error checking to commit(). (firebird-sdbc) Change-Id: I0717fad287f95d510d044055edc11737fde0c505 diff --git a/connectivity/source/drivers/firebird/Connection.cxx b/connectivity/source/drivers/firebird/Connection.cxx index db26523..0402581 100644 --- a/connectivity/source/drivers/firebird/Connection.cxx +++ b/connectivity/source/drivers/firebird/Connection.cxx @@ -492,6 +492,9 @@ void SAL_CALL OConnection::commit() throw(SQLException, RuntimeException) { clearStatements(); isc_commit_transaction(status_vector, &m_transactionHandle); + evaluateStatusVector(status_vector, + "isc_commit_transaction", + *this); } } commit ebe37593c53f9fbad0e9a798834db10fc19b7479 Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Wed Aug 7 18:10:20 2013 +0100 Clean up ResultSet management. (firebird-sdbc) Change-Id: I00cd0aa08a5a3da17f06933ebc3422a6b4b8bc74 diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx index 55bba8c..f391618 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx @@ -258,6 +258,7 @@ sal_Bool SAL_CALL OPreparedStatement::execute() MutexGuard aGuard( m_pConnection->getMutex() ); checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); + ensurePrepared(); ISC_STATUS aErr; @@ -273,9 +274,12 @@ sal_Bool SAL_CALL OPreparedStatement::execute() evaluateStatusVector(m_statusVector, "isc_dsql_execute", *this); } - // TODO: check we actually got results -- ? + m_xResultSet = new OResultSet(m_pConnection, + uno::Reference< XInterface >(*this), + m_statementHandle, + m_pOutSqlda); - return sal_True; + return m_xResultSet.is(); // TODO: implement handling of multiple ResultSets. } @@ -296,12 +300,6 @@ Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery() throw SQLException(); // TODO: add message to exception } - uno::Reference< OResultSet > pResult(new OResultSet(m_pConnection, - uno::Reference< XInterface >(*this), - m_statementHandle, - m_pOutSqlda)); - m_xResultSet = pResult.get(); - return m_xResultSet; } // ------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/firebird/Statement.cxx b/connectivity/source/drivers/firebird/Statement.cxx index 8809330..6f2ee58 100644 --- a/connectivity/source/drivers/firebird/Statement.cxx +++ b/connectivity/source/drivers/firebird/Statement.cxx @@ -82,7 +82,6 @@ void SAL_CALL OStatement::release() throw() sal_Int32 SAL_CALL OStatement::executeUpdate(const OUString& sql) throw(SQLException, RuntimeException) { - // TODO: close ResultSet if existing -- so so in all 3 execute methods. MutexGuard aGuard(m_pConnection->getMutex()); checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); @@ -133,12 +132,10 @@ uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& s SAL_WARN("connectivity.firebird", "isc_dsql_execute failed" ); } - uno::Reference< OResultSet > pResult(new OResultSet(m_pConnection, - uno::Reference< XInterface >(*this), - aStatementHandle, - pOutSqlda)); - //initializeResultSet( pResult.get() ); - m_xResultSet = pResult.get(); + m_xResultSet = new OResultSet(m_pConnection, + uno::Reference< XInterface >(*this), + aStatementHandle, + pOutSqlda); // TODO: deal with cleanup // close(); diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.cxx b/connectivity/source/drivers/firebird/StatementCommonBase.cxx index eba79de..d3ee72c 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.cxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.cxx @@ -59,11 +59,10 @@ OStatementCommonBase::~OStatementCommonBase() void OStatementCommonBase::disposeResultSet() { - //free the cursor if alive -// uno::Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY); -// if (xComp.is()) -// xComp->dispose(); -// m_xResultSet = uno::Reference< XResultSet>(); + uno::Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY); + if (xComp.is()) + xComp->dispose(); + m_xResultSet = uno::Reference< XResultSet>(); } //----------------------------------------------------------------------------- @@ -101,7 +100,7 @@ void SAL_CALL OStatementCommonBase::close( ) throw(SQLException, RuntimeExcepti { MutexGuard aGuard(m_pConnection->getMutex()); checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); - + disposeResultSet(); } dispose(); } @@ -191,11 +190,11 @@ int OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql, uno::Reference< XResultSet > SAL_CALL OStatementCommonBase::getResultSet() throw(SQLException, RuntimeException) { // TODO: verify we really can't support this - return uno::Reference< XResultSet >(); -// MutexGuard aGuard( m_aMutex ); -// checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); +// return uno::Reference< XResultSet >(); + MutexGuard aGuard(m_pConnection->getMutex()); + checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); -// return m_xResultSet; + return m_xResultSet; } sal_Bool SAL_CALL OStatementCommonBase::getMoreResults() throw(SQLException, RuntimeException) diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.hxx b/connectivity/source/drivers/firebird/StatementCommonBase.hxx index 99f4563..12483a6 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.hxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.hxx @@ -53,7 +53,7 @@ namespace connectivity { protected: - ::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::XResultSet> m_xResultSet; // The last ResultSet created // for this Statement ::std::list< ::rtl::OUString> m_aBatchList; commit eb5e9ab4c4d6a00be96f6db760c2c64ca061e426 Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Wed Aug 7 11:32:16 2013 +0100 Clean up statement handle on closing ResultSet. (firebird-sdbc) Change-Id: I7e59c1939651cc55090ca3a5f1a9a388d685dc43 diff --git a/connectivity/source/drivers/firebird/ResultSet.cxx b/connectivity/source/drivers/firebird/ResultSet.cxx index 36c59af..c91af92 100644 --- a/connectivity/source/drivers/firebird/ResultSet.cxx +++ b/connectivity/source/drivers/firebird/ResultSet.cxx @@ -569,7 +569,7 @@ Any SAL_CALL OResultSet::getObject( sal_Int32 columnIndex, const uno::Reference< // ------------------------------------------------------------------------- -void SAL_CALL OResultSet::close( ) throw(SQLException, RuntimeException) +void SAL_CALL OResultSet::close() throw(SQLException, RuntimeException) { SAL_INFO("connectivity.firebird", "close()."); @@ -577,6 +577,16 @@ void SAL_CALL OResultSet::close( ) throw(SQLException, RuntimeException) MutexGuard aGuard(m_pConnection->getMutex()); checkDisposed(OResultSet_BASE::rBHelper.bDisposed); + ISC_STATUS_ARRAY aStatusVector; + ISC_STATUS aErr; + aErr = isc_dsql_free_statement(aStatusVector, + &m_statementHandle, + DSQL_drop); + if (aErr) + evaluateStatusVector(aStatusVector, + "isc_dsql_free_statement", + *this); + } dispose(); } commit 211094992c610b77abd46d93b3e46b5a25fe4f95 Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Wed Aug 7 11:06:09 2013 +0100 Fix transaction creation when autocommit disabled. (firebird-sdbc) Change-Id: I190a90e9821961c4e972ec26ac282b05fd375d4b diff --git a/connectivity/source/drivers/firebird/Connection.cxx b/connectivity/source/drivers/firebird/Connection.cxx index 07b16eb..db26523 100644 --- a/connectivity/source/drivers/firebird/Connection.cxx +++ b/connectivity/source/drivers/firebird/Connection.cxx @@ -82,7 +82,7 @@ OConnection::OConnection(FirebirdDriver* _pDriver) m_pDriver(_pDriver), m_bClosed(sal_False), m_bUseOldDateFormat(sal_False), - m_bAutoCommit(sal_True), + m_bAutoCommit(sal_False), m_bReadOnly(sal_False), m_aTransactionIsolation(TransactionIsolation::REPEATABLE_READ), m_DBHandler(0), @@ -413,6 +413,7 @@ sal_Bool SAL_CALL OConnection::getAutoCommit() throw(SQLException, RuntimeExcept } void OConnection::setupTransaction() + throw (SQLException) { MutexGuard aGuard( m_aMutex ); ISC_STATUS status_vector[20]; @@ -445,19 +446,32 @@ void OConnection::setupTransaction() assert( false ); // We must have a valid TransactionIsolation. } - static char isc_tpb[] = { - isc_tpb_version3, - (char) (m_bAutoCommit ? isc_tpb_autocommit : 0), - (char) (!m_bReadOnly ? isc_tpb_write : isc_tpb_read), - aTransactionIsolation, - isc_tpb_wait - }; + // You cannot pass an empty tpb parameter so we have to do some pointer + // arithmetic to avoid problems. (i.e. aTPB[x] = 0 is invalid) + char aTPB[5]; + char* pTPB = aTPB; - isc_start_transaction(status_vector, &m_transactionHandle, 1, &m_DBHandler, - (unsigned short) sizeof(isc_tpb), isc_tpb); + *pTPB++ = isc_tpb_version3; + if (m_bAutoCommit) + *pTPB++ = isc_tpb_autocommit; + *pTPB++ = (!m_bReadOnly ? isc_tpb_write : isc_tpb_read); + *pTPB++ = aTransactionIsolation; + *pTPB++ = isc_tpb_wait; + + isc_start_transaction(status_vector, + &m_transactionHandle, + 1, + &m_DBHandler, + pTPB - aTPB, // bytes used in TPB + aTPB); + + evaluateStatusVector(status_vector, + "isc_start_transaction", + *this); } isc_tr_handle& OConnection::getTransaction() + throw (SQLException) { MutexGuard aGuard( m_aMutex ); if (!m_transactionHandle) diff --git a/connectivity/source/drivers/firebird/Connection.hxx b/connectivity/source/drivers/firebird/Connection.hxx index fcc59ef..5e35b36 100644 --- a/connectivity/source/drivers/firebird/Connection.hxx +++ b/connectivity/source/drivers/firebird/Connection.hxx @@ -111,7 +111,7 @@ namespace connectivity void buildTypeInfo() throw( ::com::sun::star::sdbc::SQLException); - void setupTransaction(); + void setupTransaction() throw(::com::sun::star::sdbc::SQLException); void clearStatements(); public: virtual void construct( const ::rtl::OUString& url, @@ -166,7 +166,7 @@ namespace connectivity ::rtl::OUString getConnectionURL() const { return m_sConnectionURL; } sal_Bool isEmbedded() const { return m_bIsEmbedded; } - isc_tr_handle& getTransaction(); + isc_tr_handle& getTransaction() throw(::com::sun::star::sdbc::SQLException); /** * Create a new Blob tied to this connection. Blobs are tied to a commit 67596ee0b1ad4fa7268488d16ca20ee2d3032d97 Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Wed Aug 7 10:39:16 2013 +0100 Remove unnecessarily duplicated execute/executeQuery. (firebird-sdbc) Change-Id: Ic173346c4cac140b9426560af9a9b196d93ec2f5 diff --git a/connectivity/source/drivers/firebird/Statement.cxx b/connectivity/source/drivers/firebird/Statement.cxx index 7378e5c..8809330 100644 --- a/connectivity/source/drivers/firebird/Statement.cxx +++ b/connectivity/source/drivers/firebird/Statement.cxx @@ -149,39 +149,9 @@ uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& s sal_Bool SAL_CALL OStatement::execute(const OUString& sql) throw(SQLException, RuntimeException) { - SAL_INFO("connectivity.firebird", "executeQuery(). " - "Got called with sql: " << sql); - - MutexGuard aGuard(m_pConnection->getMutex()); - checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); - - XSQLDA* pOutSqlda = 0; - isc_stmt_handle aStatementHandle = 0; - int aErr = 0; - - aErr = prepareAndDescribeStatement(sql, - aStatementHandle, - pOutSqlda); - - if (aErr) - { - SAL_WARN("connectivity.firebird", "prepareAndDescribeStatement failed" ); - } - else - { - aErr = isc_dsql_execute(m_statusVector, - &m_pConnection->getTransaction(), - &aStatementHandle, - 1, - NULL); - if (aErr) - SAL_WARN("connectivity.firebird", "isc_dsql_execute failed" ); - } - - evaluateStatusVector(m_statusVector, sql, *this); - - // returns true when a resultset is available - return sal_False; + uno::Reference< XResultSet > xResults = executeQuery(sql); + return xResults.is(); + // TODO: what if we have multiple results? } uno::Reference< XConnection > SAL_CALL OStatement::getConnection() _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits