diff options
author | Javier Fernandez <jfernandez@igalia.com> | 2013-06-04 13:54:48 +0000 |
---|---|---|
committer | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-07-16 16:40:07 +0200 |
commit | 1d7ad3244504249824cdfe8f88333a1a60773861 (patch) | |
tree | 810c4c2235a855d5fab82970a6178c387f246eff | |
parent | fd3271899c0b56ff0051e43db6adf3c22d0b6b8b (diff) |
Executing again a PreparedStatement.
Change-Id: I10afa596ed0464e14c4fd95d3a7fb687451a10b4
5 files changed, 44 insertions, 32 deletions
diff --git a/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx b/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx index c952c0f50220..908af7149fe2 100644 --- a/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx +++ b/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx @@ -61,6 +61,7 @@ namespace connectivity ODatabaseMetaData::ODatabaseMetaData(OConnection* _pCon) : m_pConnection(_pCon) +, m_pGetTablesStm(NULL) , m_bUseCatalog(sal_True) { OSL_ENSURE(m_pConnection,"ODatabaseMetaData::ODatabaseMetaData: No connection set!"); @@ -865,25 +866,28 @@ Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTables( ODatabaseMetaDataResultSet* pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTables); Reference< XResultSet > xResultSet = pResultSet; - Reference< XPreparedStatement > statement = m_pConnection->prepareStatement( + if (!m_pGetTablesStm.is()) + { + m_pGetTablesStm = m_pConnection->prepareStatement( "SELECT " "'schema' as schema, RDB$RELATION_NAME, RDB$SYSTEM_FLAG, RDB$RELATION_TYPE, 'description' as description " // avoid duplicates "FROM RDB$RELATIONS " "WHERE (RDB$RELATION_TYPE = 0 OR RDB$RELATION_TYPE = 1) " "AND 'schema' LIKE ? " "AND RDB$RELATION_NAME LIKE ? "); + } SAL_INFO("connectivity.firebird", "=> ODatabaseMetaData::getTables(). " "Setting query parameters."); - Reference< XParameters > parameters( statement, UNO_QUERY_THROW ); + Reference< XParameters > parameters( m_pGetTablesStm, UNO_QUERY_THROW ); parameters->setString( 1 , schemaPattern ); parameters->setString( 2 , tableNamePattern ); SAL_INFO("connectivity.firebird", "=> ODatabaseMetaData::getTables(). " "About to execute the query."); - Reference< XResultSet > rs = statement->executeQuery(); + Reference< XResultSet > rs = m_pGetTablesStm->executeQuery(); Reference< XRow > xRow( rs, UNO_QUERY_THROW ); ODatabaseMetaDataResultSet::ORows aRows; int rows = 0; diff --git a/connectivity/source/drivers/firebird/FDatabaseMetaData.hxx b/connectivity/source/drivers/firebird/FDatabaseMetaData.hxx index a2852e0d6bd4..a9f802db5e18 100644 --- a/connectivity/source/drivers/firebird/FDatabaseMetaData.hxx +++ b/connectivity/source/drivers/firebird/FDatabaseMetaData.hxx @@ -53,6 +53,7 @@ namespace connectivity class ODatabaseMetaData : public ODatabaseMetaData_BASE { OConnection* m_pConnection; + ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > m_pGetTablesStm; sal_Bool m_bUseCatalog; public: diff --git a/connectivity/source/drivers/firebird/FPreparedStatement.cxx b/connectivity/source/drivers/firebird/FPreparedStatement.cxx index 6a146acfbb39..1f3d6bb740dc 100644 --- a/connectivity/source/drivers/firebird/FPreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/FPreparedStatement.cxx @@ -354,25 +354,24 @@ Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) throw(SQLE checkDisposed(OStatement_BASE::rBHelper.bDisposed); ISC_STATUS_ARRAY status; /* status vector */ - if (NULL != m_INsqlda) + if (0 == m_TRANSHandler) { - if (isc_dsql_execute2(status, &m_TRANSHandler, &m_STMTHandler, 1, m_INsqlda, NULL)) - if (pr_error(status, "execute2 query")) - return NULL; - } - else - { - if (isc_dsql_execute(status, &m_TRANSHandler, &m_STMTHandler, 1, NULL)) - if (pr_error(status, "execute query")) + isc_db_handle db = m_pConnection->getDBHandler(); // database handle + if (isc_start_transaction(status, &m_TRANSHandler, 1, &db, 0, NULL)) + if (pr_error(status, "start transaction")) return NULL; } + if (isc_dsql_execute(status, &m_TRANSHandler, &m_STMTHandler, 1, m_INsqlda)) + if (pr_error(status, "execute query")) + return NULL; + Reference< OResultSet > pResult( new OResultSet( this) ); //initializeResultSet( pResult.get() ); Reference< XResultSet > xRS = pResult.get(); if (isc_commit_transaction(status, &m_TRANSHandler)) - if (pr_error(status, "start transaction")) + if (pr_error(status, "commit transaction")) return NULL; SAL_INFO("connectivity.firebird", "=> OPreparedStatement::executeQuery(). " diff --git a/connectivity/source/drivers/firebird/FResultSet.cxx b/connectivity/source/drivers/firebird/FResultSet.cxx index 6a2dcabde8a9..e64019e9da4a 100644 --- a/connectivity/source/drivers/firebird/FResultSet.cxx +++ b/connectivity/source/drivers/firebird/FResultSet.cxx @@ -143,8 +143,8 @@ OResultSet::OResultSet(OStatement_Base* pStmt) if (pr_error(status, "fetch data")) return; } - if (isc_dsql_free_statement(status, &stmt, DSQL_drop)) - if (pr_error(status, "fetch data")) + if (isc_dsql_free_statement(status, &stmt, DSQL_close)) + if (pr_error(status, "free statement")) return; } // ------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/firebird/FStatement.cxx b/connectivity/source/drivers/firebird/FStatement.cxx index 6d3a9ed3c789..f540624dbb99 100644 --- a/connectivity/source/drivers/firebird/FStatement.cxx +++ b/connectivity/source/drivers/firebird/FStatement.cxx @@ -59,6 +59,26 @@ using namespace com::sun::star::container; using namespace com::sun::star::io; using namespace com::sun::star::util; //------------------------------------------------------------------------------ + +/* + * Print the status, the SQLCODE, and exit. + * Also, indicate which operation the error occured on. + */ +static int pr_error (long* status, char* operation) +{ + printf("[\n"); + printf("PROBLEM ON \"%s\".\n", operation); + + isc_print_status(status); + + printf("SQLCODE:%d\n", isc_sqlcode(status)); + + printf("]\n"); + + return 1; +} + +//------------------------------------------------------------------------------ OStatement_Base::OStatement_Base(OConnection* _pConnection ) : OStatement_BASE(m_aMutex), OPropertySetHelper(OStatement_BASE::rBHelper), @@ -108,6 +128,11 @@ void OStatement_BASE2::disposing() free(m_INsqlda); } + ISC_STATUS_ARRAY status; // status vector + if (isc_dsql_free_statement(status, &m_STMTHandler, DSQL_drop)) + if (pr_error(status, "fetch data")) + return; + dispose_ChildImpl(); OStatement_Base::disposing(); } @@ -172,23 +197,6 @@ sal_Bool SAL_CALL OStatement_Base::execute( const ::rtl::OUString& sql ) throw(S } // ------------------------------------------------------------------------- -/* - * Print the status, the SQLCODE, and exit. - * Also, indicate which operation the error occured on. - */ -static int pr_error (long* status, char* operation) -{ - SAL_WARN("connectivity.firebird", "=> OStatement_Base static pr_error()."); - - isc_print_status(status); - - SAL_WARN("connectivity.firebird", "=> OStatement_Base static pr_error(). " - "PROBLEM ON " << operation << ". " - "SQLCODE: " << isc_sqlcode(status) << "."); - - return 1; -} - Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery( const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) { SAL_INFO("connectivity.firebird", "=> OStatement_Base::executeQuery(). " |