Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


Attached patch fixes (old! at least back to 3.3) bugs exposed by
fixing fdo#46843, about sort orders in the graphical query editor:

fdo#47370: when sort columns order does not match result columns
           order, sort is reordered to result order

           E.g. "SELECT a, b, c FROM foo ORDER BY c, a"
           becomes "SELECT a, b, c FROM foo ORDER BY a, c"

fdo#47560: when several sort columns are "out of result order", all
           are set to the last

           E.g. "SELECT a, b, c FROM foo ORDER BY c, a, b"
           becomes "SELECT a, b, c FROM foo ORDER BY c, b, b"

           That is simply because those "additional" sort columns were
           set in the *same* in-memory structure. Fix: allocate a
           fresh structure for each new sort column.

Please apply to libreoffice-3-5.

-- 
Lionel
From bf1294a1597a50a495ae76aa111d411e254a8e41 Mon Sep 17 00:00:00 2001
From: Lionel Elie Mamane <lionel@mamane.lu>
Date: Tue, 20 Mar 2012 11:01:12 +0100
Subject: [PATCH 1/2] fdo#47370 properly duplicate (invisible) out-of-order
 sort columns

Keep track of position of previous sorting column and use it to decide whether to duplicate 
invisible new sort column
---
 .../source/ui/querydesign/SelectionBrowseBox.cxx   |   12 ++++++++++--
 .../source/ui/querydesign/SelectionBrowseBox.hxx   |    1 +
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx 
b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
index d13d5f9..177313c 100644
--- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
+++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
@@ -68,6 +68,7 @@ const String g_strZero = String::CreateFromAscii("0");
 #define CHECKBOX_SIZE       10
 #define HANDLE_ID            0
 #define HANDLE_COLUMN_WITDH 70
+#define SORT_COLUMN_NONE    0xFFFFFFFF
 
 // -----------------------------------------------------------------------------
 namespace
@@ -113,6 +114,7 @@ OSelectionBrowseBox::OSelectionBrowseBox( Window* pParent )
                                   BROWSER_HIDECURSOR | BROWSER_HLINESFULL | BROWSER_VLINESFULL )
                    ,m_aFunctionStrings(ModuleRes(STR_QUERY_FUNCTIONS))
                    ,m_nVisibleCount(0)
+                   ,m_nLastSortColumn(SORT_COLUMN_NONE)
                    ,m_bOrderByUnRelated(sal_True)
                    ,m_bGroupByUnRelated(sal_True)
                    ,m_bStopTimer(sal_False)
@@ -418,6 +420,7 @@ void OSelectionBrowseBox::ClearAll()
             aIter = getFields().rbegin();
         }
     }
+    m_nLastSortColumn = SORT_COLUMN_NONE;
     SetUpdateMode(sal_True);
 }
 //------------------------------------------------------------------------------
@@ -1873,11 +1876,14 @@ void OSelectionBrowseBox::AddCondition( const OTableFieldDescRef& rInfo, 
const S
 //------------------------------------------------------------------------------
 void OSelectionBrowseBox::AddOrder( const OTableFieldDescRef& rInfo, const EOrderDir eDir, 
sal_uInt32 _nCurrentPos)
 {
+    if (_nCurrentPos == 0)
+        m_nLastSortColumn = SORT_COLUMN_NONE;
+
     Reference< XConnection> xConnection = 
static_cast<OQueryController&>(getDesignView()->getController()).getConnection();
     if(!xConnection.is())
         return;
     DBG_CHKTHIS(OSelectionBrowseBox,NULL);
-    OSL_ENSURE(!rInfo->IsEmpty(),"AddOrder:: OTableFieldDescRef sollte nicht Empty sein!");
+    OSL_ENSURE(!rInfo->IsEmpty(),"AddOrder:: OTableFieldDescRef should not be Empty!");
     OTableFieldDescRef pEntry;
     Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData();
     ::comphelper::UStringMixEqual bCase(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers());
@@ -1896,7 +1902,7 @@ void OSelectionBrowseBox::AddOrder( const OTableFieldDescRef& rInfo, const 
EOrde
             bCase(aAlias,rInfo->GetAlias()))
         {
             sal_uInt32 nPos = aIter - rFields.begin();
-            bAppend = _nCurrentPos > nPos;
+            bAppend = (m_nLastSortColumn != SORT_COLUMN_NONE) && (nPos <= m_nLastSortColumn);
             if ( bAppend )
                 aIter = rFields.end();
             else
@@ -1904,6 +1910,7 @@ void OSelectionBrowseBox::AddOrder( const OTableFieldDescRef& rInfo, const 
EOrde
                 if ( !m_bOrderByUnRelated )
                     pEntry->SetVisible(sal_True);
                 pEntry->SetOrderDir( eDir );
+                m_nLastSortColumn = nPos;
             }
             break;
         }
@@ -1914,6 +1921,7 @@ void OSelectionBrowseBox::AddOrder( const OTableFieldDescRef& rInfo, const 
EOrde
         OTableFieldDescRef pTmp = InsertField(rInfo, BROWSER_INVALIDID, sal_False, sal_False );
         if(pTmp.is())
         {
+            m_nLastSortColumn = pTmp->GetColumnId() - 1;
             if ( !m_bOrderByUnRelated && !bAppend )
                 pTmp->SetVisible(sal_True);
             pTmp->SetOrderDir( eDir );
diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.hxx 
b/dbaccess/source/ui/querydesign/SelectionBrowseBox.hxx
index 35b666f..50c0244 100644
--- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.hxx
+++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.hxx
@@ -87,6 +87,7 @@ namespace dbaui
 
         String                              m_aFunctionStrings;
         sal_uInt16                          m_nVisibleCount;                // Anzahl der max 
sichtbaren Zeilen
+        sal_uInt32                          m_nLastSortColumn;              // index of last 
(highest) sort column
         sal_Bool                            m_bOrderByUnRelated;
         sal_Bool                            m_bGroupByUnRelated;
         sal_Bool                            m_bStopTimer;
-- 
1.7.7.3

From 6143d292e8aaffbb58963bd22fa00a8b58374cb3 Mon Sep 17 00:00:00 2001
From: Lionel Elie Mamane <lionel@mamane.lu>
Date: Tue, 20 Mar 2012 11:03:08 +0100
Subject: [PATCH 2/2] fdo#47560 properly separate each new sorting column

---
 dbaccess/source/ui/querydesign/QueryDesignView.cxx |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx 
b/dbaccess/source/ui/querydesign/QueryDesignView.cxx
index c9c6092..1a18286 100644
--- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx
+++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx
@@ -2325,9 +2325,9 @@ namespace
 
             OQueryController& rController = 
static_cast<OQueryController&>(_pView->getController());
             EOrderDir eOrderDir;
-            OTableFieldDescRef aDragLeft = new OTableFieldDesc();
             for( sal_uInt32 i=0 ; i<pNode->count() ; i++ )
             {
+                OTableFieldDescRef aDragLeft = new OTableFieldDesc();
                 eOrderDir = ORDER_ASC;
                 ::connectivity::OSQLParseNode*  pChild = pNode->getChild( i );
 
-- 
1.7.7.3


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.