Thread: Multiple selections delete bug

Multiple selections delete bug

From
"Virgil Frum"
Date:
Platform: Windows 2000(build 2195: Service Pack 4)
Language: english
Distribution: binary
Version: 1.2.0 Post Beta1 (Sept 17 2004)

When multiple rows are selected (in Edit Data window) from bottom to top and
Delete button is pressed then either the program crashes or wrong rows are
deleted.

Example: if table has 20 rows and 10, 9, 8, 7, 6 rows are selected (in this
order), on delete, 10, 8, 6, 12, 14 rows are deleted, same number of rows
but not those selected. If selection is made on last rows, program crashes
and in postgres logs I found:

Oct  5 12:01:57 linux postgres[19624]: [11-1] LOG:  could not receive data
from client: Connection reset by peer
Oct  5 12:01:57 linux postgres[19475]: [11-1] LOG:  could not receive data
from client: Connection reset by peer
Oct  5 12:01:57 linux postgres[19476]: [55-1] LOG:  could not receive data
from client: Connection reset by peer
Oct  5 12:01:57 linux postgres[19624]: [12-1] LOG:  unexpected EOF on client
connection
Oct  5 12:01:57 linux postgres[19476]: [56-1] LOG:  unexpected EOF on client
connection
Oct  5 12:01:57 linux postgres[19475]: [12-1] LOG:  unexpected EOF on client
connection



Re: Multiple selections delete bug

From
"Dave Page"
Date:

> -----Original Message-----
> From: pgadmin-support-owner@postgresql.org
> [mailto:pgadmin-support-owner@postgresql.org] On Behalf Of Virgil Frum
> Sent: 05 October 2004 12:37
> To: pgadmin-support@postgresql.org
> Subject: [pgadmin-support] Multiple selections delete bug
>
> Platform: Windows 2000(build 2195: Service Pack 4)
> Language: english
> Distribution: binary
> Version: 1.2.0 Post Beta1 (Sept 17 2004)
>
> When multiple rows are selected (in Edit Data window) from
> bottom to top and Delete button is pressed then either the
> program crashes or wrong rows are deleted.
>
> Example: if table has 20 rows and 10, 9, 8, 7, 6 rows are
> selected (in this order), on delete, 10, 8, 6, 12, 14 rows
> are deleted, same number of rows but not those selected. If
> selection is made on last rows, program crashes and in
> postgres logs I found:

Thanks. I've committed a fix for this to CVS.

Regards, Dave.


Re: Multiple selections delete bug

From
"Virgil Frum"
Date:
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.

Regards,
Virgil

>> When multiple rows are selected (in Edit Data window) from
>> bottom to top and Delete button is pressed then either the
>> program crashes or wrong rows are deleted.
>>
>
> Thanks. I've committed a fix for this to CVS.
>
> Regards, Dave.



Re: Multiple selections delete bug

From
"Dave Page"
Date:

> -----Original Message-----
> From: pgadmin-support-owner@postgresql.org
> [mailto:pgadmin-support-owner@postgresql.org] On Behalf Of Virgil Frum
> Sent: 06 October 2004 14:37
> To: pgadmin-support@postgresql.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();