diff options
author | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-07-23 17:24:12 +0200 |
---|---|---|
committer | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-07-23 19:29:06 +0200 |
commit | ed9dac3baff5a75b95af6ccfdfcafc64a58200e2 (patch) | |
tree | 981ace29e7e08719a44d45a7bad666f9f677b40c /connectivity | |
parent | 2b541c928ca6eaca9cb5dcbe7f4f43f9f0b20101 (diff) |
Move Statement specific methods out of common base. (firebird-sdbc)
Change-Id: If85f7f419b7c67bc84f8a74422cc8c9080a34353
Diffstat (limited to 'connectivity')
8 files changed, 153 insertions, 132 deletions
diff --git a/connectivity/source/drivers/firebird/FPreparedStatement.cxx b/connectivity/source/drivers/firebird/FPreparedStatement.cxx index 2e66504339df..c7a08f8e7f05 100644 --- a/connectivity/source/drivers/firebird/FPreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/FPreparedStatement.cxx @@ -308,7 +308,7 @@ Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery() } uno::Reference< OResultSet > pResult(new OResultSet(m_pConnection, - uno::Reference< XStatement >(this), + uno::Reference< XInterface >(*this), m_statementHandle, m_pOutSqlda)); m_xResultSet = pResult.get(); diff --git a/connectivity/source/drivers/firebird/FPreparedStatement.hxx b/connectivity/source/drivers/firebird/FPreparedStatement.hxx index 75dd18fbf93b..b7f4a9674875 100644 --- a/connectivity/source/drivers/firebird/FPreparedStatement.hxx +++ b/connectivity/source/drivers/firebird/FPreparedStatement.hxx @@ -35,7 +35,11 @@ #ifndef CONNECTIVITY_FIREBIRD_PREPAREDSTATEMENT_HXX #define CONNECTIVITY_FIREBIRD_PREPAREDSTATEMENT_HXX + #include "FStatement.hxx" + +#include <cppuhelper/implbase5.hxx> + #include <com/sun/star/sdbc/XPreparedStatement.hpp> #include <com/sun/star/sdbc/XParameters.hpp> #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp> @@ -110,11 +114,8 @@ namespace connectivity virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException); // XPreparedStatement - using OStatement_Base::executeQuery; virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - using OStatement_Base::executeUpdate; virtual sal_Int32 SAL_CALL executeUpdate( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - using OStatement_Base::execute; virtual sal_Bool SAL_CALL execute( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); // XParameters diff --git a/connectivity/source/drivers/firebird/FResultSet.cxx b/connectivity/source/drivers/firebird/FResultSet.cxx index a234057fc561..2b05342fdfc3 100644 --- a/connectivity/source/drivers/firebird/FResultSet.cxx +++ b/connectivity/source/drivers/firebird/FResultSet.cxx @@ -66,7 +66,7 @@ using namespace ::com::sun::star::io; using namespace ::com::sun::star::util; OResultSet::OResultSet(OConnection* pConnection, - const uno::Reference< XStatement >& xStatement, + const uno::Reference< XInterface >& xStatement, isc_stmt_handle& aStatementHandle, XSQLDA* pSqlda) : OResultSet_BASE(pConnection->getMutex()) diff --git a/connectivity/source/drivers/firebird/FResultSet.hxx b/connectivity/source/drivers/firebird/FResultSet.hxx index 917f21ddacc0..894eaffe3c2e 100644 --- a/connectivity/source/drivers/firebird/FResultSet.hxx +++ b/connectivity/source/drivers/firebird/FResultSet.hxx @@ -82,7 +82,7 @@ namespace connectivity { protected: OConnection* m_pConnection; - const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement >& m_xStatement; + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& m_xStatement; ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData> m_xMetaData; @@ -136,7 +136,7 @@ namespace connectivity DECLARE_SERVICE_INFO(); OResultSet(OConnection* pConnection, - const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement >& xStatement, + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xStatement, isc_stmt_handle& aStatementHandle, XSQLDA* aSqlda); diff --git a/connectivity/source/drivers/firebird/FStatement.cxx b/connectivity/source/drivers/firebird/FStatement.cxx index 9c435809e114..0bf7067684f4 100644 --- a/connectivity/source/drivers/firebird/FStatement.cxx +++ b/connectivity/source/drivers/firebird/FStatement.cxx @@ -100,4 +100,124 @@ Any SAL_CALL OStatement::queryInterface( const Type & rType ) throw(RuntimeExcep return aRet; } +// ---- XStatement ----------------------------------------------------------- +sal_Int32 SAL_CALL OStatement::executeUpdate(const OUString& sqlIn) + throw(SQLException, RuntimeException) +{ + // TODO: close ResultSet if existing -- so so in all 3 execute methods. + MutexGuard aGuard(m_pConnection->getMutex()); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + const OUString sql = sanitizeSqlString(sqlIn); + + int aErr = isc_dsql_execute_immediate(m_statusVector, + &m_pConnection->getDBHandle(), + &m_pConnection->getTransaction(), + 0, + OUStringToOString(sql, RTL_TEXTENCODING_UTF8).getStr(), + 1, + NULL); + + if (aErr) + SAL_WARN("connectivity.firebird", "isc_dsql_execute_immediate failed" ); + + m_pConnection->evaluateStatusVector(m_statusVector, sql, *this); + // TODO: get number of changed rows with SELECT ROW_COUNT (use executeQuery) + // return getUpdateCount(); + return 0; +} + + +uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& sqlIn) + throw(SQLException, RuntimeException) +{ + MutexGuard aGuard(m_pConnection->getMutex()); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + const OUString sql = sanitizeSqlString(sqlIn); + + 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" ); + } + + uno::Reference< OResultSet > pResult(new OResultSet(m_pConnection, + uno::Reference< XInterface >(*this), + aStatementHandle, + pOutSqlda)); + //initializeResultSet( pResult.get() ); + m_xResultSet = pResult.get(); + + // TODO: deal with cleanup +// close(); + m_pConnection->evaluateStatusVector(m_statusVector, sql, *this); + return m_xResultSet; +} + +sal_Bool SAL_CALL OStatement::execute(const OUString& sqlIn) + throw(SQLException, RuntimeException) +{ + SAL_INFO("connectivity.firebird", "executeQuery(). " + "Got called with sql: " << sqlIn); + + MutexGuard aGuard(m_pConnection->getMutex()); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + XSQLDA* pOutSqlda = 0; + isc_stmt_handle aStatementHandle = 0; + int aErr = 0; + + const OUString sql = sanitizeSqlString(sqlIn); + + 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" ); + } + + m_pConnection->evaluateStatusVector(m_statusVector, sql, *this); + + // returns true when a resultset is available + return sal_False; +} + +uno::Reference< XConnection > SAL_CALL OStatement::getConnection() + throw(SQLException, RuntimeException) +{ + MutexGuard aGuard(m_pConnection->getMutex()); + checkDisposed(OStatement_BASE::rBHelper.bDisposed); + + return (uno::Reference< XConnection >)m_pConnection; +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/firebird/FStatement.hxx b/connectivity/source/drivers/firebird/FStatement.hxx index 07c5afb8bc4d..cecc0e1a89fc 100644 --- a/connectivity/source/drivers/firebird/FStatement.hxx +++ b/connectivity/source/drivers/firebird/FStatement.hxx @@ -38,12 +38,21 @@ #include "StatementCommonBase.hxx" +#include <cppuhelper/implbase1.hxx> + namespace connectivity { namespace firebird { + // The name OStatementStatement_BASE is temporary and will be changed + // once the general restructuring of Statement/PreparedStatement is + // complete. + typedef ::cppu::ImplHelper1< ::com::sun::star::sdbc::XStatement > + OStatementStatement_BASE; + class OStatement : public OStatement_Base, + public OStatementStatement_BASE, public ::com::sun::star::sdbc::XBatchExecution, public ::com::sun::star::lang::XServiceInfo { @@ -60,6 +69,20 @@ namespace connectivity virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException); virtual void SAL_CALL acquire() throw(); virtual void SAL_CALL release() throw(); + + // XStatement + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL + executeQuery(const ::rtl::OUString& sql) + throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual sal_Int32 SAL_CALL executeUpdate(const ::rtl::OUString& sqlIn) + throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL + execute(const ::rtl::OUString& sql) + throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL + getConnection() + throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + // XBatchExecution - UNSUPPORTED virtual void SAL_CALL addBatch( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL clearBatch( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.cxx b/connectivity/source/drivers/firebird/StatementCommonBase.cxx index 4816f0f25b44..d599b781148d 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.cxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.cxx @@ -121,32 +121,6 @@ void SAL_CALL OStatement_Base::close( ) throw(SQLException, RuntimeException) dispose(); } -// ---- XStatement ----------------------------------------------------------- -sal_Int32 SAL_CALL OStatement_Base::executeUpdate(const OUString& sqlIn) - throw(SQLException, RuntimeException) -{ - // TODO: close ResultSet if existing -- so so in all 3 execute methods. - MutexGuard aGuard(m_pConnection->getMutex()); - checkDisposed(OStatement_BASE::rBHelper.bDisposed); - - const OUString sql = sanitizeSqlString(sqlIn); - - int aErr = isc_dsql_execute_immediate(m_statusVector, - &m_pConnection->getDBHandle(), - &m_pConnection->getTransaction(), - 0, - OUStringToOString(sql, RTL_TEXTENCODING_UTF8).getStr(), - 1, - NULL); - - if (aErr) - SAL_WARN("connectivity.firebird", "isc_dsql_execute_immediate failed" ); - - m_pConnection->evaluateStatusVector(m_statusVector, sql, *this); - // TODO: get number of changed rows with SELECT ROW_COUNT (use executeQuery) - // return getUpdateCount(); - return 0; -} OUString OStatement_Base::sanitizeSqlString(const OUString& sqlIn) { @@ -239,97 +213,6 @@ int OStatement_Base::prepareAndDescribeStatement(const OUString& sqlIn, return aErr; } -uno::Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery(const OUString& sqlIn) throw(SQLException, RuntimeException) -{ - MutexGuard aGuard(m_pConnection->getMutex()); - checkDisposed(OStatement_BASE::rBHelper.bDisposed); - - const OUString sql = sanitizeSqlString(sqlIn); - - 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" ); - } - - uno::Reference< OResultSet > pResult(new OResultSet(m_pConnection, - uno::Reference< XStatement >(this), - aStatementHandle, - pOutSqlda)); - //initializeResultSet( pResult.get() ); - m_xResultSet = pResult.get(); - - // TODO: deal with cleanup -// close(); - m_pConnection->evaluateStatusVector(m_statusVector, sql, *this); - return m_xResultSet; -} - -sal_Bool SAL_CALL OStatement_Base::execute(const OUString& sqlIn) throw(SQLException, RuntimeException) -{ - SAL_INFO("connectivity.firebird", "executeQuery(). " - "Got called with sql: " << sqlIn); - - MutexGuard aGuard(m_pConnection->getMutex()); - checkDisposed(OStatement_BASE::rBHelper.bDisposed); - - XSQLDA* pOutSqlda = 0; - isc_stmt_handle aStatementHandle = 0; - int aErr = 0; - - const OUString sql = sanitizeSqlString(sqlIn); - - 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" ); - } - - m_pConnection->evaluateStatusVector(m_statusVector, sql, *this); - - // returns true when a resultset is available - return sal_False; -} - -uno::Reference< XConnection > SAL_CALL OStatement_Base::getConnection() - throw(SQLException, RuntimeException) -{ - MutexGuard aGuard(m_pConnection->getMutex()); - checkDisposed(OStatement_BASE::rBHelper.bDisposed); - - return (uno::Reference< XConnection >)m_pConnection; -} - // ---- XMultipleResults - UNSUPPORTED ---------------------------------------- uno::Reference< XResultSet > SAL_CALL OStatement_Base::getResultSet() throw(SQLException, RuntimeException) { diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.hxx b/connectivity/source/drivers/firebird/StatementCommonBase.hxx index 7ee121c4846d..6c39853aeedc 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.hxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.hxx @@ -41,7 +41,7 @@ #include <ibase.h> #include <connectivity/OSubComponent.hxx> -#include <cppuhelper/compbase5.hxx> +#include <cppuhelper/compbase4.hxx> #include <list> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -58,8 +58,7 @@ namespace connectivity namespace firebird { - typedef ::cppu::WeakComponentImplHelper5< ::com::sun::star::sdbc::XStatement, - ::com::sun::star::sdbc::XWarningsSupplier, + typedef ::cppu::WeakComponentImplHelper4< ::com::sun::star::sdbc::XWarningsSupplier, ::com::sun::star::util::XCancellable, ::com::sun::star::sdbc::XCloseable, ::com::sun::star::sdbc::XMultipleResults> OStatement_BASE; @@ -123,11 +122,6 @@ namespace connectivity // XPropertySet virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException); - // XStatement - virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ; - virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sqlIn ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ; - virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ; - virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ; // XWarningsSupplier - UNSUPPORTED virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); |