summaryrefslogtreecommitdiff
path: root/connectivity/source/drivers/firebird/PreparedStatement.cxx
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2013-08-28 16:09:54 +0100
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2013-08-28 17:56:19 +0100
commitc338f1cf704ac5061d6eb290beb69d7503c95eee (patch)
tree9ae4d137dd1928d0d5fbf2827ceaacd546916383 /connectivity/source/drivers/firebird/PreparedStatement.cxx
parentb5f91618d710803a26fa23d154d7252384f74e6f (diff)
Use template to set integer parameters. (firebird-sdbc)
Change-Id: I8a6c9f335574196a50827db7eb44b82f9ea4df16
Diffstat (limited to 'connectivity/source/drivers/firebird/PreparedStatement.cxx')
-rw-r--r--connectivity/source/drivers/firebird/PreparedStatement.cxx65
1 files changed, 21 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);
}
// -------------------------------------------------------------------------