diff options
author | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-08-28 16:09:54 +0100 |
---|---|---|
committer | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2013-08-28 17:56:19 +0100 |
commit | c338f1cf704ac5061d6eb290beb69d7503c95eee (patch) | |
tree | 9ae4d137dd1928d0d5fbf2827ceaacd546916383 /connectivity | |
parent | b5f91618d710803a26fa23d154d7252384f74e6f (diff) |
Use template to set integer parameters. (firebird-sdbc)
Change-Id: I8a6c9f335574196a50827db7eb44b82f9ea4df16
Diffstat (limited to 'connectivity')
-rw-r--r-- | connectivity/source/drivers/firebird/PreparedStatement.cxx | 65 | ||||
-rw-r--r-- | connectivity/source/drivers/firebird/PreparedStatement.hxx | 6 |
2 files changed, 27 insertions, 44 deletions
diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx index 2c59931c1ca8..ffa3124d3add 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.cxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx @@ -345,18 +345,9 @@ 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 nValue) - throw(SQLException, RuntimeException) -{ - (void) nIndex; - (void) nValue; - ::dbtools::throwFunctionNotSupportedException("setByte not supported in firebird", - *this, - Any()); -} - -void SAL_CALL OPreparedStatement::setShort(sal_Int32 nIndex, sal_Int16 nValue) - throw(SQLException, RuntimeException) +template <typename T> +void OPreparedStatement::setValue(sal_Int32 nIndex, T nValue, ISC_SHORT nType) + throw(SQLException) { MutexGuard aGuard( m_pConnection->getMutex() ); checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed); @@ -367,52 +358,38 @@ void SAL_CALL OPreparedStatement::setShort(sal_Int32 nIndex, sal_Int16 nValue) XSQLVAR* pVar = m_pInSqlda->sqlvar + (nIndex - 1); - int dtype = (pVar->sqltype & ~1); // drop flag bit for now - - if (dtype != SQL_SHORT) + if ((pVar->sqltype & ~1) != nType) throw SQLException(); // TODO: cast instead? memcpy(pVar->sqldata, &nValue, sizeof(nValue)); } -void SAL_CALL OPreparedStatement::setInt(sal_Int32 nIndex, sal_Int32 nValue) +void SAL_CALL OPreparedStatement::setByte(sal_Int32 nIndex, sal_Int8 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 + (void) nIndex; + (void) nValue; + ::dbtools::throwFunctionNotSupportedException("setByte not supported in firebird", + *this, + Any()); +} - if (dtype != SQL_LONG) - throw SQLException(); // TODO: cast instead? +void SAL_CALL OPreparedStatement::setShort(sal_Int32 nIndex, sal_Int16 nValue) + throw(SQLException, RuntimeException) +{ + setValue< sal_Int16 >(nIndex, nValue, SQL_SHORT); +} - memcpy(pVar->sqldata, &nValue, sizeof(nValue)); +void SAL_CALL OPreparedStatement::setInt(sal_Int32 nIndex, sal_Int32 nValue) + throw(SQLException, RuntimeException) +{ + setValue< sal_Int32 >(nIndex, nValue, SQL_LONG); } 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)); + setValue< sal_Int64 >(nIndex, nValue, SQL_INT64); } // ------------------------------------------------------------------------- diff --git a/connectivity/source/drivers/firebird/PreparedStatement.hxx b/connectivity/source/drivers/firebird/PreparedStatement.hxx index 4434a644620c..5392a93d6a52 100644 --- a/connectivity/source/drivers/firebird/PreparedStatement.hxx +++ b/connectivity/source/drivers/firebird/PreparedStatement.hxx @@ -74,6 +74,12 @@ namespace connectivity void checkParameterIndex(sal_Int32 nParameterIndex) throw(::com::sun::star::sdbc::SQLException); + /** + * Set a numeric value in the input SQLDA. If the destination + * parameter is not of nType then an Exception will be thrown. + */ + template <typename T> void setValue(sal_Int32 nIndex, T nValue, ISC_SHORT nType) + throw(::com::sun::star::sdbc::SQLException); void setParameterNull(sal_Int32 nParameterIndex, bool bSetNull = true); void ensurePrepared() |