[Libreoffice-commits] core.git: 5 commits - connectivity/source dbaccess/source forms/source

Lionel Elie Mamane lionel at mamane.lu
Wed Oct 16 09:46:30 PDT 2013


 connectivity/source/commontools/FValue.cxx    |   10 ++++---
 connectivity/source/commontools/dbtools.cxx   |    2 -
 dbaccess/source/core/api/RowSet.cxx           |    3 +-
 dbaccess/source/core/api/WrappedResultSet.cxx |    2 -
 forms/source/component/CheckBox.cxx           |   37 +++++++++++++++++++++++---
 forms/source/component/CheckBox.hxx           |    1 
 6 files changed, 44 insertions(+), 11 deletions(-)

New commits:
commit ffff47459274d6187bb0ea6533f5acc0e7b7ed92
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Mon Oct 14 17:59:10 2013 +0200

    respect reference values in checkboxes
    
    Change-Id: Ifd0953f779f530af6b190425794f009a891f0afb

diff --git a/connectivity/source/commontools/FValue.cxx b/connectivity/source/commontools/FValue.cxx
index c6c038f..46fe62f 100644
--- a/connectivity/source/commontools/FValue.cxx
+++ b/connectivity/source/commontools/FValue.cxx
@@ -26,6 +26,8 @@
 #include <comphelper/extract.hxx>
 #include <com/sun/star/io/XInputStream.hpp>
 #include <rtl/ustrbuf.hxx>
+#include <boost/type_traits.hpp>
+#include <boost/static_assert.hpp>
 
 using namespace ::dbtools;
 using namespace ::com::sun::star::sdbc;
diff --git a/connectivity/source/commontools/dbtools.cxx b/connectivity/source/commontools/dbtools.cxx
index 6ba64dd..e54ab30 100644
--- a/connectivity/source/commontools/dbtools.cxx
+++ b/connectivity/source/commontools/dbtools.cxx
@@ -1905,7 +1905,7 @@ void setObjectWithInfo(const Reference<XParameters>& _xParams,
                 break;
             case DataType::BIT:
             case DataType::BOOLEAN:
-                _xParams->setBoolean(parameterIndex,_rValue);
+                _xParams->setBoolean(parameterIndex,static_cast<bool>(_rValue));
                 break;
             case DataType::TINYINT:
                 if ( _rValue.isSigned() )
diff --git a/forms/source/component/CheckBox.cxx b/forms/source/component/CheckBox.cxx
index 67751f2..9d352f0 100644
--- a/forms/source/component/CheckBox.cxx
+++ b/forms/source/component/CheckBox.cxx
@@ -203,6 +203,13 @@ void SAL_CALL OCheckBoxModel::read(const Reference<stario::XObjectInputStream>&
         resetNoBroadcast();
 }
 
+bool OCheckBoxModel::DbUseBool()
+{
+    if ( ! (getReferenceValue().isEmpty() && getNoCheckReferenceValue().isEmpty()) )
+        return false;
+    return true;
+}
+
 //------------------------------------------------------------------------------
 Any OCheckBoxModel::translateDbColumnToControlValue()
 {
@@ -210,7 +217,21 @@ Any OCheckBoxModel::translateDbColumnToControlValue()
 
     //////////////////////////////////////////////////////////////////
     // Set value in ControlModel
-    sal_Bool bValue = m_xColumn->getBoolean();
+    bool bValue;
+    if(DbUseBool())
+    {
+        bValue = m_xColumn->getBoolean();
+    }
+    else
+    {
+        const OUString sVal(m_xColumn->getString());
+        if (sVal == getReferenceValue())
+            bValue = true;
+        else if (sVal == getNoCheckReferenceValue())
+            bValue = false;
+        else
+            aValue <<= static_cast<sal_Int16>(getDefaultChecked());
+    }
     if ( m_xColumn->wasNull() )
     {
         sal_Bool bTriState = sal_True;
@@ -218,8 +239,10 @@ Any OCheckBoxModel::translateDbColumnToControlValue()
             m_xAggregateSet->getPropertyValue( PROPERTY_TRISTATE ) >>= bTriState;
         aValue <<= (sal_Int16)( bTriState ? STATE_DONTKNOW : getDefaultChecked() );
     }
-    else
+    else if ( !aValue.hasValue() )
+    {
         aValue <<= (sal_Int16)( bValue ? STATE_CHECK : STATE_NOCHECK );
+    }
 
     return aValue;
 }
@@ -241,10 +264,16 @@ sal_Bool OCheckBoxModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
                     m_xColumnUpdate->updateNull();
                     break;
                 case STATE_CHECK:
-                    m_xColumnUpdate->updateBoolean( sal_True );
+                    if (DbUseBool())
+                        m_xColumnUpdate->updateBoolean( sal_True );
+                    else
+                        m_xColumnUpdate->updateString( getReferenceValue() );
                     break;
                 case STATE_NOCHECK:
-                    m_xColumnUpdate->updateBoolean( sal_False );
+                    if (DbUseBool())
+                        m_xColumnUpdate->updateBoolean( sal_False );
+                    else
+                        m_xColumnUpdate->updateString( getNoCheckReferenceValue() );
                     break;
                 default:
                     OSL_FAIL("OCheckBoxModel::commitControlValueToDbColumn: invalid value !");
diff --git a/forms/source/component/CheckBox.hxx b/forms/source/component/CheckBox.hxx
index c44ed5b..8cc9523 100644
--- a/forms/source/component/CheckBox.hxx
+++ b/forms/source/component/CheckBox.hxx
@@ -33,6 +33,7 @@ class OCheckBoxModel    :public OReferenceValueComponent
 {
 protected:
     sal_Int16   getState(const ::com::sun::star::uno::Any& rValue);
+    bool        DbUseBool();
 
 public:
     DECLARE_DEFAULT_LEAF_XTOR( OCheckBoxModel );
commit d9eac2ceb8c75c7219e7a6f50a3d774be311228b
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Wed Oct 16 18:16:38 2013 +0200

    make sure value passed to updateBoolean is treated as a boolean
    
    Change-Id: I69549fd8ab95cf92ccb06fd9aed1b9dba2935d7d

diff --git a/dbaccess/source/core/api/WrappedResultSet.cxx b/dbaccess/source/core/api/WrappedResultSet.cxx
index 2cdf519..bf2ce01 100644
--- a/dbaccess/source/core/api/WrappedResultSet.cxx
+++ b/dbaccess/source/core/api/WrappedResultSet.cxx
@@ -185,7 +185,7 @@ void WrappedResultSet::updateColumn(sal_Int32 nPos,Reference< XRowUpdate > _xPar
                     break;
                 case DataType::BIT:
                 case DataType::BOOLEAN:
-                    _xParameter->updateBoolean(nPos,_rValue);
+                    _xParameter->updateBoolean(nPos,static_cast<bool>(_rValue));
                     break;
                 case DataType::TINYINT:
                     if ( _rValue.isSigned() )
commit 5c5df097e696dfb186a32838bb77bee3d244b058
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Mon Oct 14 18:05:50 2013 +0200

    janitorial: bool is bool, not sal_Bool
    
    Change-Id: Ia6fbde0521d503c3d774ebd265097804d375ed3b

diff --git a/connectivity/source/commontools/FValue.cxx b/connectivity/source/commontools/FValue.cxx
index 89f1f10..c6c038f 100644
--- a/connectivity/source/commontools/FValue.cxx
+++ b/connectivity/source/commontools/FValue.cxx
@@ -1077,12 +1077,12 @@ bool ORowSetValue::getBool()    const
                     const static OUString s_sFalse("false");
                     if ( sValue.equalsIgnoreAsciiCase(s_sTrue) || (sValue == "1") )
                     {
-                        bRet = sal_True;
+                        bRet = true;
                         break;
                     }
                     else if ( sValue.equalsIgnoreAsciiCase(s_sFalse) || (sValue == "0") )
                     {
-                        bRet = sal_False;
+                        bRet = false;
                         break;
                     }
                 }
commit 1883d4f10f4d6df0da27b5659724188adbf1d3a8
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Mon Oct 14 18:05:06 2013 +0200

    when reading a bool from a database, treat is as a bool
    
    This in particular allows recognition of strings "true" and "false".
    
    Change-Id: I590a5357206e4fb0b92b78b8ee4655e445e6f152

diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx
index f451f98..18a1cb0 100644
--- a/dbaccess/source/core/api/RowSet.cxx
+++ b/dbaccess/source/core/api/RowSet.cxx
@@ -1312,7 +1312,8 @@ OUString SAL_CALL ORowSet::getString( sal_Int32 columnIndex ) throw(SQLException
 sal_Bool SAL_CALL ORowSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
 {
     ::osl::MutexGuard aGuard( *m_pMutex );
-    return getInsertValue(columnIndex);
+    // the extra cast is to recognise the "true" or "false" strings
+    return static_cast<bool>(getInsertValue(columnIndex));
 }
 
 sal_Int8 SAL_CALL ORowSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
commit b9fac5769d831989dcff7bd815ca5630a916075d
Author: Lionel Elie Mamane <lionel at mamane.lu>
Date:   Mon Oct 14 18:03:32 2013 +0200

    string->bool conversion recognise "1"/"0" additionally to "true"/"false"
    
    since that is what the conversion in the other direction recognises.
    It also recognises the "true"/"false" written by LibreOffice versions affected by fdo#68657
    
    Change-Id: I213c23a19e4857905da93eeb2be1b9714215594a

diff --git a/connectivity/source/commontools/FValue.cxx b/connectivity/source/commontools/FValue.cxx
index 5a18711..89f1f10 100644
--- a/connectivity/source/commontools/FValue.cxx
+++ b/connectivity/source/commontools/FValue.cxx
@@ -1075,12 +1075,12 @@ bool ORowSetValue::getBool()    const
                     const OUString sValue(m_aValue.m_pString);
                     const static OUString s_sTrue("true");
                     const static OUString s_sFalse("false");
-                    if ( sValue.equalsIgnoreAsciiCase(s_sTrue) )
+                    if ( sValue.equalsIgnoreAsciiCase(s_sTrue) || (sValue == "1") )
                     {
                         bRet = sal_True;
                         break;
                     }
-                    else if ( sValue.equalsIgnoreAsciiCase(s_sFalse) )
+                    else if ( sValue.equalsIgnoreAsciiCase(s_sFalse) || (sValue == "0") )
                     {
                         bRet = sal_False;
                         break;


More information about the Libreoffice-commits mailing list