[Libreoffice-commits] core.git: 6 commits - connectivity/source

Andrzej J.R. Hunt andrzej at ahunt.org
Wed Aug 28 10:00:04 PDT 2013


 connectivity/source/drivers/firebird/DatabaseMetaData.cxx  |    2 
 connectivity/source/drivers/firebird/PreparedStatement.cxx |  112 +++----------
 connectivity/source/drivers/firebird/PreparedStatement.hxx |    6 
 connectivity/source/drivers/firebird/Util.cxx              |    6 
 4 files changed, 43 insertions(+), 83 deletions(-)

New commits:
commit 0501026fb882de656887cb5af696f1cf7ceab3e9
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Aug 28 17:47:45 2013 +0100

    Implement set[Float|Double]. (firebird-sdbc)
    
    Change-Id: I70d5ab9bacdeabe6c4edf6f70a9ba283b46c180f

diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx
index 3078c7d..fdbb0a4 100644
--- a/connectivity/source/drivers/firebird/PreparedStatement.cxx
+++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx
@@ -376,6 +376,19 @@ void SAL_CALL OPreparedStatement::setLong(sal_Int32 nIndex, sal_Int64 nValue)
 {
     setValue< sal_Int64 >(nIndex, nValue, SQL_INT64);
 }
+
+void SAL_CALL OPreparedStatement::setFloat(sal_Int32 nIndex, float nValue)
+    throw(SQLException, RuntimeException)
+{
+    setValue< sal_Int64 >(nIndex, nValue, SQL_FLOAT);
+}
+
+void SAL_CALL OPreparedStatement::setDouble(sal_Int32 nIndex, double nValue)
+    throw(SQLException, RuntimeException)
+{
+    setValue< sal_Int64 >(nIndex, nValue, SQL_DOUBLE); // TODO: SQL_D_FLOAT?
+}
+
 // -------------------------------------------------------------------------
 
 void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const Date& aData ) throw(SQLException, RuntimeException)
@@ -409,27 +422,6 @@ void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 parameterIndex, const
 }
 // -------------------------------------------------------------------------
 
-void SAL_CALL OPreparedStatement::setDouble( sal_Int32 parameterIndex, double x ) throw(SQLException, RuntimeException)
-{
-    (void) parameterIndex;
-    (void) x;
-    ::osl::MutexGuard aGuard( m_pConnection->getMutex() );
-    checkDisposed(OStatementCommonBase_Base::rBHelper.bDisposed);
-
-}
-
-// -------------------------------------------------------------------------
-
-void SAL_CALL OPreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) throw(SQLException, RuntimeException)
-{
-    (void) parameterIndex;
-    (void) x;
-    ::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 9310cf2b9f121cd2b11a06596e0db44244fba59b
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Aug 28 17:46:51 2013 +0100

    Firebird uses "DOUBLE PRECISION" for doubles. (firebird-sdbc)
    
    Change-Id: I99bac2cfde956d2b91dce33fc12ce9044a9c219a

diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
index 215d84f..c35e03d 100644
--- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx
@@ -949,7 +949,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo()
         aRow[15] = new ORowSetValueDecorator(sal_Int16(7)); // Max scale
         aResults.push_back(aRow);
         // SQL_DOUBLE
-        aRow[1] = new ORowSetValueDecorator(OUString("REAL"));
+        aRow[1] = new ORowSetValueDecorator(OUString("DOUBLE PRECISION"));
         aRow[2] = new ORowSetValueDecorator(getColumnTypeFromFBType(SQL_DOUBLE));
         aRow[3] = new ORowSetValueDecorator(sal_Int16(15)); // Precision
         aRow[14] = new ORowSetValueDecorator(sal_Int16(1)); // Minimum scale
commit 3eddbbec432bf0aa66a4edc4ef68ec83ecac4ee4
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Aug 28 17:29:02 2013 +0100

    SQL_FLOAT corresponds to DataType::FLOAT.
    
    Change-Id: Id5e2aab669ba047e9ecb392187aae7c4aa384dda

diff --git a/connectivity/source/drivers/firebird/Util.cxx b/connectivity/source/drivers/firebird/Util.cxx
index 6d176db..6941835 100644
--- a/connectivity/source/drivers/firebird/Util.cxx
+++ b/connectivity/source/drivers/firebird/Util.cxx
@@ -69,11 +69,11 @@ sal_Int32 firebird::getColumnTypeFromFBType(short aType)
     case SQL_LONG:
         return DataType::INTEGER;
     case SQL_FLOAT:
-        return DataType::REAL;
+        return DataType::FLOAT;
     case SQL_DOUBLE:
         return DataType::DOUBLE;
     case SQL_D_FLOAT:
-        return DataType::FLOAT;
+        return DataType::DOUBLE;
     case SQL_TIMESTAMP:
         return DataType::TIMESTAMP;
     case SQL_BLOB:
commit c2602a4c2e4bd76634c90adc495a9e79a62974ba
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Aug 28 17:11:42 2013 +0100

    Use correct type for SQL_FLOAT. (firebird-sdbc)
    
    Change-Id: Ic27e886643128edeb5b2d5c81e86681f4dd8d33b

diff --git a/connectivity/source/drivers/firebird/Util.cxx b/connectivity/source/drivers/firebird/Util.cxx
index 47661db..6d176db 100644
--- a/connectivity/source/drivers/firebird/Util.cxx
+++ b/connectivity/source/drivers/firebird/Util.cxx
@@ -207,7 +207,7 @@ void firebird::mallocSQLVAR(XSQLDA* pSqlda)
             pVar->sqldata = (char *)malloc(sizeof(long));
             break;
         case SQL_FLOAT:
-            pVar->sqldata = (char *)malloc(sizeof(double));
+            pVar->sqldata = (char *)malloc(sizeof(float));
             break;
         case SQL_DOUBLE:
             pVar->sqldata = (char *)malloc(sizeof(double));
commit fe8e3be835cce5fc3e22f550567dd2d650766657
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Aug 28 16:30:40 2013 +0100

    Remove unused code (firebird-sdbc)
    
    Change-Id: I88f47ee442ade499c7f4018ce8b1ffe54b362067

diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx
index ffa3124..3078c7d 100644
--- a/connectivity/source/drivers/firebird/PreparedStatement.cxx
+++ b/connectivity/source/drivers/firebird/PreparedStatement.cxx
@@ -106,22 +106,7 @@ void OPreparedStatement::ensurePrepared()
                                1,
                                m_pInSqlda);
     }
-//         char aItems[] = {
-//             isc_info_sql_num_variables
-//         };
-//         char aResultBuffer[8];
-//         isc_dsql_sql_info(m_statusVector,
-//                           &m_aStatementHandle,
-//                           sizeof(aItems),
-//                           aItems,
-//                           sizeof(aResultBuffer),
-//                           aResultBuffer);
-//         if (aResultBuffer[0] == isc_info_sql_num_variables)
-//         {
-//             short aVarLength = (short) isc_vax_integer(aResultBuffer+1, 2);
-//             m_nNumParams = isc_vax_integer(aResultBuffer+3, aVarLength);
-//         }
-//     }
+
     if (!aErr)
         mallocSQLVAR(m_pInSqlda);
     else
commit c338f1cf704ac5061d6eb290beb69d7503c95eee
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date:   Wed Aug 28 16:09:54 2013 +0100

    Use template to set integer parameters. (firebird-sdbc)
    
    Change-Id: I8a6c9f335574196a50827db7eb44b82f9ea4df16

diff --git a/connectivity/source/drivers/firebird/PreparedStatement.cxx b/connectivity/source/drivers/firebird/PreparedStatement.cxx
index 2c59931..ffa3124 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 4434a64..5392a93 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()


More information about the Libreoffice-commits mailing list