connectivity/source/drivers/firebird/PreparedStatement.cxx | 131 ++++++----- connectivity/source/drivers/firebird/PreparedStatement.hxx | 26 +- connectivity/source/drivers/firebird/Statement.cxx | 24 -- connectivity/source/drivers/firebird/StatementCommonBase.cxx | 96 +++++++- connectivity/source/drivers/firebird/StatementCommonBase.hxx | 6 5 files changed, 196 insertions(+), 87 deletions(-)
New commits: commit 7bc88db8c500b41fe926fb99cd403accd696e671 Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Tue Aug 27 20:52:37 2013 +0100 Implemet setNull. (firebird-sdbc) Change-Id: I9fd53a5e8b5d1dba467fa8064f9f2ea1b93f26df diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx index 00f7b0e..2c59931 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx @@ -323,6 +323,16 @@ Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery() } //----- XParameters ----------------------------------------------------------- +void SAL_CALL OPreparedStatement::setNull(sal_Int32 nIndex, sal_Int32 nSqlType) + throw(SQLException, RuntimeException) +{ + (void) nSqlType; + MutexGuard aGuard( m_pConnection->getMutex() ); + checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); + + setParameterNull(nIndex, true); +} + void SAL_CALL OPreparedStatement::setBoolean(sal_Int32 nIndex, sal_Bool x) throw(SQLException, RuntimeException) { @@ -458,16 +468,6 @@ void SAL_CALL OPreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) } // ------------------------------------------------------------------------- -void SAL_CALL OPreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) throw(SQLException, RuntimeException) -{ - (void) parameterIndex; - (void) sqlType; - ::osl::MutexGuard aGuard( m_pConnection->getMutex() ); - checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); - -} -// ------------------------------------------------------------------------- - void SAL_CALL OPreparedStatement::setClob( sal_Int32 parameterIndex, const Reference< XClob >& x ) throw(SQLException, RuntimeException) { (void) parameterIndex; commit 186f264dc2ac45c3de16a651b64de77794589eab Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Tue Aug 27 20:50:44 2013 +0100 Implement set[Int|Long]. (firebird-sdbc) Change-Id: I234b8f136b90f56c689553d0df8ec2d473a92225 diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx index 004d191..00f7b0e 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx @@ -335,17 +335,17 @@ void SAL_CALL OPreparedStatement::setBoolean(sal_Int32 nIndex, sal_Bool x) // it might be best to just determine the db type and set as appropriate? } -void SAL_CALL OPreparedStatement::setByte(sal_Int32 nIndex, sal_Int8 x) +void SAL_CALL OPreparedStatement::setByte(sal_Int32 nIndex, sal_Int8 nValue) throw(SQLException, RuntimeException) { (void) nIndex; - (void) x; + (void) nValue; ::dbtools::throwFunctionNotSupportedException("setByte not supported in firebird", *this, Any()); } -void SAL_CALL OPreparedStatement::setShort(sal_Int32 nIndex, sal_Int16 x) +void SAL_CALL OPreparedStatement::setShort(sal_Int32 nIndex, sal_Int16 nValue) throw(SQLException, RuntimeException) { MutexGuard aGuard( m_pConnection->getMutex() ); @@ -362,7 +362,47 @@ void SAL_CALL OPreparedStatement::setShort(sal_Int32 nIndex, sal_Int16 x) if (dtype != SQL_SHORT) throw SQLException(); // TODO: cast instead? - memcpy(pVar->sqldata, &x, 2); + memcpy(pVar->sqldata, &nValue, sizeof(nValue)); +} + +void SAL_CALL OPreparedStatement::setInt(sal_Int32 nIndex, sal_Int32 nValue) + throw(SQLException, RuntimeException) +{ + MutexGuard aGuard( m_pConnection->getMutex() ); + checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); + ensurePrepared(); + + checkParameterIndex(nIndex); + setParameterNull(nIndex, false); + + XSQLVAR* pVar = m_pInSqlda->sqlvar + (nIndex - 1); + + int dtype = (pVar->sqltype & ~1); // drop flag bit for now + + if (dtype != SQL_LONG) + throw SQLException(); // TODO: cast instead? + + memcpy(pVar->sqldata, &nValue, sizeof(nValue)); +} + +void SAL_CALL OPreparedStatement::setLong(sal_Int32 nIndex, sal_Int64 nValue) + throw(SQLException, RuntimeException) +{ + MutexGuard aGuard( m_pConnection->getMutex() ); + checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); + ensurePrepared(); + + checkParameterIndex(nIndex); + setParameterNull(nIndex, false); + + XSQLVAR* pVar = m_pInSqlda->sqlvar + (nIndex - 1); + + int dtype = (pVar->sqltype & ~1); // drop flag bit for now + + if (dtype != SQL_INT64) + throw SQLException(); // TODO: cast instead? + + memcpy(pVar->sqldata, &nValue, sizeof(nValue)); } // ------------------------------------------------------------------------- @@ -418,26 +458,6 @@ void SAL_CALL OPreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) } // ------------------------------------------------------------------------- -void SAL_CALL OPreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(SQLException, RuntimeException) -{ - (void) parameterIndex; - (void) x; - ::osl::MutexGuard aGuard( m_pConnection->getMutex() ); - checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); - -} -// ------------------------------------------------------------------------- - -void SAL_CALL OPreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 aVal ) throw(SQLException, RuntimeException) -{ - (void) parameterIndex; - (void) aVal; - ::osl::MutexGuard aGuard( m_pConnection->getMutex() ); - checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); - -} -// ------------------------------------------------------------------------- - void SAL_CALL OPreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) throw(SQLException, RuntimeException) { (void) parameterIndex; diff --git a/connectivity/source/drivers/firebird/PreparedStatement.hxx b/connectivity/source/drivers/firebird/PreparedStatement.hxx index eca8562..4434a64 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.hxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.hxx @@ -117,13 +117,25 @@ namespace connectivity ::com::sun::star::uno::RuntimeException); // XParameters - virtual void SAL_CALL setNull( sal_Int32 nParameterIndex, sal_Int32 sqlType ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setLong( sal_Int32 parameterIndex, sal_Int64 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setNull(sal_Int32 nIndex, sal_Int32 nValue) + throw(::com::sun::star::sdbc::SQLException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setObjectNull(sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setBoolean( sal_Int32 nIndex, sal_Bool nValue) + throw(::com::sun::star::sdbc::SQLException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setByte(sal_Int32 nIndex, sal_Int8 nValue) + throw(::com::sun::star::sdbc::SQLException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setShort(sal_Int32 nIndex, sal_Int16 nValue) + throw(::com::sun::star::sdbc::SQLException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setInt(sal_Int32 nIndex, sal_Int32 nValue) + throw(::com::sun::star::sdbc::SQLException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setLong(sal_Int32 nIndex, sal_Int64 nValue) + throw(::com::sun::star::sdbc::SQLException, + ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL setFloat( sal_Int32 parameterIndex, float x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL setDouble( sal_Int32 parameterIndex, double x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); virtual void SAL_CALL setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); commit 8620524f1979105c35460ad7cf621468b7ef6a28 Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Tue Aug 27 20:35:33 2013 +0100 Implement setShort. (firebird-sdbc) Change-Id: Ia543f34344915c4621ba0c6ce6984dce7ca9e08b diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx index 1898777..004d191 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx @@ -24,6 +24,7 @@ #include "Util.hxx" #include <comphelper/sequence.hxx> +#include <connectivity/dbexception.hxx> #include <cppuhelper/typeprovider.hxx> #include <osl/diagnose.h> #include <propertyids.hxx> @@ -320,25 +321,48 @@ Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery() return m_xResultSet; } -// ------------------------------------------------------------------------- -void SAL_CALL OPreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(SQLException, RuntimeException) +//----- XParameters ----------------------------------------------------------- +void SAL_CALL OPreparedStatement::setBoolean(sal_Int32 nIndex, sal_Bool x) + throw(SQLException, RuntimeException) { - (void) parameterIndex; + (void) nIndex; (void) x; - ::osl::MutexGuard aGuard( m_pConnection->getMutex() ); + MutexGuard aGuard(m_pConnection->getMutex()); checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); + // TODO: decide how to deal with bools. Probably just as a byte, although + // it might be best to just determine the db type and set as appropriate? } -// ------------------------------------------------------------------------- -void SAL_CALL OPreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(SQLException, RuntimeException) + +void SAL_CALL OPreparedStatement::setByte(sal_Int32 nIndex, sal_Int8 x) + throw(SQLException, RuntimeException) { - (void) parameterIndex; + (void) nIndex; (void) x; - ::osl::MutexGuard aGuard( m_pConnection->getMutex() ); + ::dbtools::throwFunctionNotSupportedException("setByte not supported in firebird", + *this, + Any()); +} + +void SAL_CALL OPreparedStatement::setShort(sal_Int32 nIndex, sal_Int16 x) + throw(SQLException, RuntimeException) +{ + MutexGuard aGuard( m_pConnection->getMutex() ); checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); + ensurePrepared(); + + checkParameterIndex(nIndex); + setParameterNull(nIndex, false); + XSQLVAR* pVar = m_pInSqlda->sqlvar + (nIndex - 1); + + int dtype = (pVar->sqltype & ~1); // drop flag bit for now + if (dtype != SQL_SHORT) + throw SQLException(); // TODO: cast instead? + + memcpy(pVar->sqldata, &x, 2); } // ------------------------------------------------------------------------- @@ -497,16 +521,6 @@ void SAL_CALL OPreparedStatement::setObject( sal_Int32 parameterIndex, const Any } // ------------------------------------------------------------------------- -void SAL_CALL OPreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(SQLException, RuntimeException) -{ - (void) parameterIndex; - (void) x; - ::osl::MutexGuard aGuard( m_pConnection->getMutex() ); - checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); - -} -// ------------------------------------------------------------------------- - void SAL_CALL OPreparedStatement::setBytes( sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException) { (void) parameterIndex; commit dadba3efcb2fb3df3b89058dfd4a98d648241ec6 Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Tue Aug 27 13:33:00 2013 +0100 Return change count for Statement:executeUpdate too. (firebird-sdbc) This also simplifies Statement, although not using execute_immediate is somewhat less efficient. Change-Id: I4bebe13e5a63cb02e6b2659dec534f0c6feeba52 diff --git a/connectivity/source/drivers/firebird/Statement.cxx b/connectivity/source/drivers/firebird/Statement.cxx index 59f89de..00978b7 100644 --- a/connectivity/source/drivers/firebird/Statement.cxx +++ b/connectivity/source/drivers/firebird/Statement.cxx @@ -97,28 +97,8 @@ void OStatement::disposeResultSet() sal_Int32 SAL_CALL OStatement::executeUpdate(const OUString& sql) throw(SQLException, RuntimeException) { - MutexGuard aGuard(m_pConnection->getMutex()); - checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); - - SAL_INFO("connectivity.firebird", "executeUpdate(" << sql << ")"); - - int aErr = isc_dsql_execute_immediate(m_statusVector, - &m_pConnection->getDBHandle(), - &m_pConnection->getTransaction(), - 0, - OUStringToOString(sql, RTL_TEXTENCODING_UTF8).getStr(), - FIREBIRD_SQL_DIALECT, - NULL); - - if (aErr) - SAL_WARN("connectivity.firebird", "isc_dsql_execute_immediate failed" ); - - evaluateStatusVector(m_statusVector, sql, *this); - // TODO: get number of changed rows with SELECT ROW_COUNT (use executeQuery) - // return getUpdateCount(); - // We can't use return getStatementChangeCount(); since that depends - // on having the statement handle, so maybe just use executeQuery instead? - return 0; + execute(sql); + return getStatementChangeCount(); } commit 73aaa4da674ac8389ee8269e4d7c827d7e642e26 Author: Andrzej J.R. Hunt <andr...@ahunt.org> Date: Tue Aug 27 13:27:23 2013 +0100 Implement retrieving change count for executeUpdate. (firebird-sdbc) Change-Id: Ied47f421dc801bb6790bed49b28d3231844e6ee5 diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx index 7645748..1898777 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx @@ -306,10 +306,7 @@ sal_Int32 SAL_CALL OPreparedStatement::executeUpdate() throw(SQLException, RuntimeException) { execute(); - // TODO: get the number of rows changed -- look in Statement::executeUpdate for details - // 1 is a temporary hack so that things like dbaccess's keyset which rely - // on the value work correctly. - return 1; + return getStatementChangeCount(); } Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery() diff --git a/connectivity/source/drivers/firebird/Statement.cxx b/connectivity/source/drivers/firebird/Statement.cxx index 32b6243..59f89de 100644 --- a/connectivity/source/drivers/firebird/Statement.cxx +++ b/connectivity/source/drivers/firebird/Statement.cxx @@ -116,6 +116,8 @@ sal_Int32 SAL_CALL OStatement::executeUpdate(const OUString& sql) evaluateStatusVector(m_statusVector, sql, *this); // TODO: get number of changed rows with SELECT ROW_COUNT (use executeQuery) // return getUpdateCount(); + // We can't use return getStatementChangeCount(); since that depends + // on having the statement handle, so maybe just use executeQuery instead? return 0; } @@ -152,7 +154,7 @@ uno::Reference< XResultSet > SAL_CALL OStatement::executeQuery(const OUString& s evaluateStatusVector(m_statusVector, sql, *this); - if (isDDLStatement(m_aStatementHandle)) + if (isDDLStatement()) m_pConnection->commit(); return m_xResultSet; diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.cxx b/connectivity/source/drivers/firebird/StatementCommonBase.cxx index f7a3a3c..77e0052 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.cxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.cxx @@ -344,32 +344,112 @@ uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL OStatementC return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); } -bool OStatementCommonBase::isDDLStatement(isc_stmt_handle& aStatementHandle) +short OStatementCommonBase::getSqlInfoItem(char aInfoItem) throw (SQLException) { ISC_STATUS_ARRAY aStatusVector; ISC_STATUS aErr; - char aInfoItems[] = {isc_info_sql_stmt_type}; + char aInfoItems[] = {aInfoItem}; char aResultsBuffer[8]; aErr = isc_dsql_sql_info(aStatusVector, - &aStatementHandle, + &m_aStatementHandle, sizeof(aInfoItems), aInfoItems, sizeof(aResultsBuffer), aResultsBuffer); - if (!aErr && aResultsBuffer[0] == isc_info_sql_stmt_type) + if (!aErr && aResultsBuffer[0] == aInfoItem) { 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; + return (short) isc_vax_integer(aResultsBuffer+3, aBytes); } + evaluateStatusVector(aStatusVector, "isc_dsq_sql_info", *this); - return false; + return 0; +} + +bool OStatementCommonBase::isDDLStatement() + throw (SQLException) +{ + if (getSqlInfoItem(isc_info_sql_stmt_type) == isc_info_sql_stmt_ddl) + return true; + else + return false; +} + +sal_Int32 OStatementCommonBase::getStatementChangeCount() + throw (SQLException) +{ + const short aStatementType = getSqlInfoItem(isc_info_sql_stmt_type); + + + + ISC_STATUS_ARRAY aStatusVector; + ISC_STATUS aErr; + + // This is somewhat undocumented so I'm just guessing and hoping for the best. + char aInfoItems[] = {isc_info_sql_records}; + char aResultsBuffer[1024]; + + aErr = isc_dsql_sql_info(aStatusVector, + &m_aStatementHandle, + sizeof(aInfoItems), + aInfoItems, + sizeof(aResultsBuffer), + aResultsBuffer); + + if (aErr) + { + evaluateStatusVector(aStatusVector, + "isc_dsq_sql_info", + *this); + return 0; + } + + short aDesiredInfoType = 0; + switch (aStatementType) + { + case isc_info_sql_stmt_select: + aDesiredInfoType = isc_info_req_select_count; + break; + case isc_info_sql_stmt_insert: + aDesiredInfoType = isc_info_req_insert_count; + break; + case isc_info_sql_stmt_update: + aDesiredInfoType = isc_info_req_update_count; + break; + case isc_info_sql_stmt_delete: + aDesiredInfoType = isc_info_req_delete_count; + break; + default: + throw SQLException(); // TODO: better error message? + } + + char* pResults = aResultsBuffer; + if (((short) *pResults++) == isc_info_sql_records) + { +// const short aTotalLength = (short) isc_vax_integer(pResults, 2); + pResults += 2; + + // Seems to be of form TOKEN (1 byte), LENGTH (2 bytes), DATA (LENGTH bytes) + while (*pResults != isc_info_rsb_end) + { + const char aToken = *pResults; + const short aLength = (short) isc_vax_integer(pResults+1, 2); + + if (aToken == aDesiredInfoType) + { + return sal_Int32(isc_vax_integer(pResults + 3, aLength)); + } + + pResults += (3 + aLength); + } + } + + return 0; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/firebird/StatementCommonBase.hxx b/connectivity/source/drivers/firebird/StatementCommonBase.hxx index bb4fc3c..46377fc 100644 --- a/connectivity/source/drivers/firebird/StatementCommonBase.hxx +++ b/connectivity/source/drivers/firebird/StatementCommonBase.hxx @@ -92,7 +92,11 @@ namespace connectivity XSQLDA* pInSqlda=0) throw (::com::sun::star::sdbc::SQLException); - bool isDDLStatement(isc_stmt_handle& aStatementHandle) + short getSqlInfoItem(char aInfoItem) + throw (::com::sun::star::sdbc::SQLException); + bool isDDLStatement() + throw (::com::sun::star::sdbc::SQLException); + sal_Int32 getStatementChangeCount() throw (::com::sun::star::sdbc::SQLException); public: _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits