diff options
author | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-08-08 08:16:41 +0100 |
---|---|---|
committer | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-08-11 16:05:09 +0100 |
commit | 75b2c92cfbaafff09e4f6e40010e5bc876979794 (patch) | |
tree | 1dbada71bcb11590dc2fb3a4b49382ec86a4f94e /connectivity | |
parent | 6e11164d57c5f8be324e32f65a31b1112e65639f (diff) |
Improve exceptions in Statement.
Change-Id: Ib1915c143abee8c9162477da07462a68dd45e03c
Diffstat (limited to 'connectivity')
4 files changed, 60 insertions, 88 deletions
diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx index 7e4b5af909a8..9a9f9888a4de 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx @@ -79,20 +79,15 @@ void OPreparedStatement::ensurePrepared() m_pInSqlda->sqln = 10; } // TODO: free this on closing - aErr = prepareAndDescribeStatement(m_sSqlStatement, - m_pOutSqlda, - m_pInSqlda); - if (aErr) - { - SAL_WARN("connectivity.firebird", "prepareAndDescribeStatement failed"); - } - else if (m_aStatementHandle) - { - isc_dsql_describe_bind(m_statusVector, - &m_aStatementHandle, - 1, + prepareAndDescribeStatement(m_sSqlStatement, + m_pOutSqlda, m_pInSqlda); - } + + + aErr = isc_dsql_describe_bind(m_statusVector, + &m_aStatementHandle, + 1, + m_pInSqlda); if (aErr) { diff --git a/connectivity/source/drivers/firebird/Statement.cxx b/connectivity/source/drivers/firebird/Statement.cxx index 3cf8c79a8c49..db44f51e7323 100644 --- a/connectivity/source/drivers/firebird/Statement.cxx +++ b/connectivity/source/drivers/firebird/Statement.cxx @@ -110,24 +110,18 @@ uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& s checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); XSQLDA* pOutSqlda = 0; - int aErr = 0; + ISC_STATUS aErr = 0; - aErr = prepareAndDescribeStatement(sql, - pOutSqlda); + prepareAndDescribeStatement(sql, + pOutSqlda); + + aErr = isc_dsql_execute(m_statusVector, + &m_pConnection->getTransaction(), + &m_aStatementHandle, + 1, + NULL); if (aErr) - { - SAL_WARN("connectivity.firebird", "prepareAndDescribeStatement failed"); - } - else - { - aErr = isc_dsql_execute(m_statusVector, - &m_pConnection->getTransaction(), - &m_aStatementHandle, - 1, - NULL); - if (aErr) - SAL_WARN("connectivity.firebird", "isc_dsql_execute failed" ); - } + SAL_WARN("connectivity.firebird", "isc_dsql_execute failed"); m_xResultSet = new OResultSet(m_pConnection, uno::Reference< XInterface >(*this), @@ -135,14 +129,11 @@ uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& s pOutSqlda); // TODO: deal with cleanup -// close(); evaluateStatusVector(m_statusVector, sql, *this); if (isDDLStatement(m_aStatementHandle)) - { m_pConnection->commit(); - } return m_xResultSet; } diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.cxx b/connectivity/source/drivers/firebird/StatementCommonBase.cxx index ee294fe55533..632962a81871 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.cxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.cxx @@ -74,17 +74,9 @@ void OStatementCommonBase::freeStatementHandle() isc_dsql_free_statement(m_statusVector, &m_aStatementHandle, DSQL_drop); - try { - evaluateStatusVector(m_statusVector, - "isc_dsql_free_statement", - *this); - } - catch (SQLException e) - { - // we cannot throw any exceptions here anyway - SAL_WARN("connectivity.firebird", - "isc_dsql_free_statement failed\n" << e.Message); - } + evaluateStatusVector(m_statusVector, + "isc_dsql_free_statement", + *this); } } @@ -130,9 +122,10 @@ void SAL_CALL OStatementCommonBase::close() dispose(); } -int OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql, +void OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql, XSQLDA*& pOutSqlda, XSQLDA* pInSqlda) + throw (SQLException) { MutexGuard aGuard(m_pConnection->getMutex()); @@ -145,48 +138,43 @@ int OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql, pOutSqlda->sqln = 10; } - int aErr = 0; + ISC_STATUS aErr = 0; aErr = isc_dsql_allocate_statement(m_statusVector, &m_pConnection->getDBHandle(), &m_aStatementHandle); if (aErr) - { - SAL_WARN("connectivity.firebird", "isc_dsql_allocate_statement failed"); - return aErr; - } - else - { - aErr = isc_dsql_prepare(m_statusVector, - &m_pConnection->getTransaction(), - &m_aStatementHandle, - 0, - OUStringToOString(sql, RTL_TEXTENCODING_UTF8).getStr(), - FIREBIRD_SQL_DIALECT, - pInSqlda); - } + evaluateStatusVector(m_statusVector, + "isc_dsql_allocate_statement", + *this); + + aErr = isc_dsql_prepare(m_statusVector, + &m_pConnection->getTransaction(), + &m_aStatementHandle, + 0, + OUStringToOString(sql, RTL_TEXTENCODING_UTF8).getStr(), + FIREBIRD_SQL_DIALECT, + pInSqlda); if (aErr) - { - SAL_WARN("connectivity.firebird", "isc_dsql_prepare failed"); - return aErr; - } - else - { - aErr = isc_dsql_describe(m_statusVector, - &m_aStatementHandle, - 1, - pOutSqlda); - } + evaluateStatusVector(m_statusVector, + "isc_dsql_prepare", + *this); + + aErr = isc_dsql_describe(m_statusVector, + &m_aStatementHandle, + 1, + pOutSqlda); + - // Ensure we have enough space in pOutSqlda if (aErr) - { - SAL_WARN("connectivity.firebird", "isc_dsql_describe failed"); - return aErr; - } - else if (!aErr && (pOutSqlda->sqld > pOutSqlda->sqln)) + evaluateStatusVector(m_statusVector, + "isc_dsql_describe", + *this); + + // Ensure we have enough space in pOutSqlda + if (pOutSqlda->sqld > pOutSqlda->sqln) { int n = pOutSqlda->sqld; free(pOutSqlda); @@ -200,16 +188,11 @@ int OStatementCommonBase::prepareAndDescribeStatement(const OUString& sql, // Process each XSQLVAR parameter structure in the output XSQLDA if (aErr) - { - SAL_WARN("connectivity.firebird","isc_dsql_describe failed when resizing pOutSqlda"); - return aErr; - } - else - { - mallocSQLVAR(pOutSqlda); - } + evaluateStatusVector(m_statusVector, + "isc_dsql_describe", + *this); - return aErr; + mallocSQLVAR(pOutSqlda); } // ---- XMultipleResults - UNSUPPORTED ---------------------------------------- diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.hxx b/connectivity/source/drivers/firebird/StatementCommonBase.hxx index a64026e8bc2b..db172fa1e04e 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.hxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.hxx @@ -86,9 +86,12 @@ namespace connectivity ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle) const; virtual ~OStatementCommonBase(); - int prepareAndDescribeStatement(const OUString& sqlIn, - XSQLDA*& pOutSqlda, - XSQLDA* pInSqlda=0); + + void prepareAndDescribeStatement(const OUString& sqlIn, + XSQLDA*& pOutSqlda, + XSQLDA* pInSqlda=0) + throw (::com::sun::star::sdbc::SQLException); + bool isDDLStatement(isc_stmt_handle& aStatementHandle) throw (::com::sun::star::sdbc::SQLException); |