summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamas Bunth <tamas.bunth@collabora.co.uk>2017-12-08 22:08:45 +0100
committerTamás Bunth <btomi96@gmail.com>2017-12-09 12:02:37 +0100
commit9ccc1f59446bc4a16b6d090a3b556e184eb5f159 (patch)
tree18b753ecace94ae14535e9f5e28e59ca3a925281
parent521d92b39b64f503876ca194d009b29f7188cc87 (diff)
tdf#70425 Firebird: accept integers in setDouble
Change-Id: I471197a9c60ca28b93be0974956e5e1d90f843ca Reviewed-on: https://gerrit.libreoffice.org/46125 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tamás Bunth <btomi96@gmail.com>
-rw-r--r--connectivity/source/drivers/firebird/PreparedStatement.cxx32
-rw-r--r--connectivity/source/drivers/firebird/PreparedStatement.hxx2
2 files changed, 31 insertions, 3 deletions
diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx
index 400b6c147cf8..3dfb092d12e7 100644
--- a/connectivity/source/drivers/firebird/PreparedStatement.cxx
+++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx
@@ -350,7 +350,7 @@ void SAL_CALL OPreparedStatement::setBoolean(sal_Int32 nIndex, sal_Bool bValue)
}
template <typename T>
-void OPreparedStatement::setValue(sal_Int32 nIndex, T& nValue, ISC_SHORT nType)
+void OPreparedStatement::setValue(sal_Int32 nIndex, const T& nValue, ISC_SHORT nType)
{
MutexGuard aGuard( m_aMutex );
checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
@@ -399,7 +399,35 @@ void SAL_CALL OPreparedStatement::setFloat(sal_Int32 nIndex, float nValue)
void SAL_CALL OPreparedStatement::setDouble(sal_Int32 nIndex, double nValue)
{
- setValue< double >(nIndex, nValue, SQL_DOUBLE); // TODO: SQL_D_FLOAT?
+ MutexGuard aGuard( m_aMutex );
+ checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
+ ensurePrepared();
+
+ XSQLVAR* pVar = m_pInSqlda->sqlvar + (nIndex - 1);
+ int dType = (pVar->sqltype & ~1); // drop flag bit for now
+
+ // Caller might try to set an integer type here. It makes sense to convert
+ // it instead of throwing an error.
+ switch(dType)
+ {
+ case SQL_SHORT:
+ setValue< sal_Int16 >(nIndex,
+ static_cast<sal_Int16>(nValue),
+ dType);
+ break;
+ case SQL_LONG:
+ setValue< sal_Int32 >(nIndex,
+ static_cast<sal_Int32>(nValue),
+ dType);
+ break;
+ case SQL_INT64:
+ setValue< sal_Int64 >(nIndex,
+ static_cast<sal_Int64>(nValue),
+ dType);
+ break;
+ default:
+ setValue< double >(nIndex, nValue, SQL_DOUBLE); // TODO: SQL_D_FLOAT?
+ }
}
void SAL_CALL OPreparedStatement::setDate(sal_Int32 nIndex, const Date& rDate)
diff --git a/connectivity/source/drivers/firebird/PreparedStatement.hxx b/connectivity/source/drivers/firebird/PreparedStatement.hxx
index 986752cd66c1..81910ad1f3dd 100644
--- a/connectivity/source/drivers/firebird/PreparedStatement.hxx
+++ b/connectivity/source/drivers/firebird/PreparedStatement.hxx
@@ -64,7 +64,7 @@ namespace connectivity
* @throws css::sdbc::SQLException
* @throws css::uno::RuntimeException
*/
- template <typename T> void setValue(sal_Int32 nIndex, T& nValue, ISC_SHORT nType);
+ template <typename T> void setValue(sal_Int32 nIndex, const T& nValue, ISC_SHORT nType);
void setParameterNull(sal_Int32 nParameterIndex, bool bSetNull = true);
/// @throws css::sdbc::SQLException