Skip site navigation (1) Skip section navigation (2)

Re: Multiple selections delete bug

From: "Dave Page" <dpage(at)vale-housing(dot)co(dot)uk>
To: "Virgil Frum" <virgil(at)netappi(dot)com>,<pgadmin-support(at)postgresql(dot)org>
Subject: Re: Multiple selections delete bug
Date: 2004-10-06 13:43:22
Message-ID: E7F85A1B5FF8D44C8A1AF6885BC9A0E430697C@ratbert.vale-housing.co.uk (view raw or flat)
Thread:
Lists: pgadmin-support
 

> -----Original Message-----
> From: pgadmin-support-owner(at)postgresql(dot)org 
> [mailto:pgadmin-support-owner(at)postgresql(dot)org] On Behalf Of Virgil Frum
> Sent: 06 October 2004 14:37
> To: pgadmin-support(at)postgresql(dot)org
> Subject: Re: [pgadmin-support] Multiple selections delete bug
> 
> The problem is just partially resolved. I've made some new 
> tests (on oct 05
> release) and looked over changes you've made in 
> src/ui/frmEditGrid.cpp.
> Conclusion: deletion is working correctly only if rows are 
> selected in ascending or descending order with or without 
> gaps. Selecting rows in an arbitrary order (ex. 7, 8, 9, 4, 
> 5, 6) won't work.
> 
> Method sqlTable::DeleteRows(size_t pos, size_t rows) is 
> working correctly only on successively rows. So, I see 2 
> possible solutions (with DeleteRows()
> unchanged):
> 1) order ascending 'delrows' array (wxArrayInt from 
> frmEditGrid::OnDelete - line 498) and remove lines added in 
> version 1.56
> 2) call  sqlGrid->GetSelectedRows() after every
> sqlGrid->DeleteRows(delrows.Item(0), 1);
> 
> I'm sorry for insistence, but I want to avoid deletion of wrong lines.

No problem - I committed a fix 5 minutes before your email implementing
your option 1!!

Regards, Dave

Index: frmEditGrid.cpp
===================================================================
RCS file: /projects/pgadmin3/src/ui/frmEditGrid.cpp,v
retrieving revision 1.56
retrieving revision 1.57
diff -Lsrc/ui/frmEditGrid.cpp -Lsrc/ui/frmEditGrid.cpp -u -w -r1.56
-r1.57
--- src/ui/frmEditGrid.cpp
+++ src/ui/frmEditGrid.cpp
@@ -488,6 +488,18 @@
 	if (optionsChanged) Go();
 }
 
+template < class T >
+int ArrayCmp(T *a, T *b)
+{
+	if (*a == *b)
+		return 0;
+
+	if (*a > *b)
+		return 1;
+	else
+		return -1;
+}
+
 void frmEditGrid::OnDelete(wxCommandEvent& event)
 {
 	wxMessageDialog msg(this, _("Are you sure you wish to delete the
selected row(s)?"), _("Delete rows?"), wxYES_NO | wxICON_QUESTION);
@@ -498,22 +510,17 @@
     wxArrayInt delrows=sqlGrid->GetSelectedRows();
     int i=delrows.GetCount();
 
+	// Sort the grid so we always delete last->first, otherwise we 
+	// could end up deleting anything because the array returned by 
+	// GetSelectedRows is in the order that rows were selected by
+	// the user.
+	delrows.Sort(ArrayCmp);
+
     // don't care a lot about optimizing here; doing it line by line
     // just as sqlTable::DeleteRows does
-	if (delrows.Item(i-1) > delrows.Item(0))
-	{
 		while (i--)
 			sqlGrid->DeleteRows(delrows.Item(i), 1);
-	}
-	else
-	{
-		int j = 0;
-		while (j < i)
-		{
-			sqlGrid->DeleteRows(delrows.Item(j), 1);
-			++j;
-		}
-	}
+
 
     sqlGrid->EndBatch();
 


pgadmin-support by date

Next:From: Eder I. CĂ´rtesDate: 2004-10-06 19:42:32
Subject: BUG WHEN ADDING FIELD VARCHAR WITH FIXED SIZE
Previous:From: Virgil FrumDate: 2004-10-06 13:37:22
Subject: Re: Multiple selections delete bug

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group