[Patch] Multiline paste bug in EditGrid - Mailing list pgadmin-hackers

From Robins
Subject [Patch] Multiline paste bug in EditGrid
Date
Msg-id CAEP4nAwutDdsM2No4EF2Yfy=ukQH7SBnhuuTfz8DuwLJD5Vi5A@mail.gmail.com
Whole thread Raw
Responses Re: [Patch] Multiline paste bug in EditGrid  (Dave Page <dpage@pgadmin.org>)
List pgadmin-hackers
Hi,

This is a small patch for a small bug I found while working in EditGrid. 
I've outlined the bug below and given the patch alongside. 

I intend to work on a few more minor bugs / small enhancements, that I've noted down over time. Do let me know in case you believe that these patches come in another way / presented differently etc..

---
Robins Tharakan

Issue: When we paste the following onto the first cell of the last row (the empty row) in EditGrid, the last column is incorrectly evaluated. The value accepted goes beyond the '\n' and is an odd mix of values with a '\n' sandwiched in between. It generally is the last column of the first row as well as the first value of the next row, with a '\n' sandwiched in between. (If the first cell of the next row is quoted, the beginning quote is included in this value as well). I believe that until we have a system in place to accept multi-line paste, ideally we should omit the remaining lines for now. 

I've provided a few sample test cases below for better understanding.

Table: 
CREATE TABLE tempdel
(
  project character varying(100) NOT NULL,
  st date,
  stop date,
  CONSTRAINT pk PRIMARY KEY (project )
)
WITH (
  OIDS=FALSE
);

Patch: 
--- a/pgadmin/frm/frmEditGrid.cpp
+++ b/pgadmin/frm/frmEditGrid.cpp
@@ -3042,7 +3042,7 @@ bool sqlTable::Paste()
                }
 
                if (inQuotes && text[pos] == quoteChar &&
-                       text[pos + 1] == colSep)
+                       (text[pos + 1] == colSep || text[pos + 1] == '\n'))
                {
                        data.Add(text.Mid(start, pos - start));
                        start = (pos += 2);


===========
Test Case 1:
XML1a;"2010-12-24";"2011-02-24"
XML1b;"2010-12-24";"2011-02-24"

Last Cell Contents: 
2011-02-24"
XML1b;"2010-12-24

===========
Test Case 2:
XML2a;2010-12-24;"2011-02-24"
XML2b;2010-12-24;"2011-02-24"

Last Cell Contents: 
2011-02-24"
XML2b;2010-12-24;"2011-02-24"

===========
Test Case 5:
XML5a;"2010-12-24";"2011-02-24"

XML5b;"2010-12-24";"2011-02-24"

Last Cell Contents: 
2011-02-24"

XML5b;"2010-12-24

===========
Test Case 6:
XML6a;"2010-12-24";"2011-02-24"
;"2010-12-24";"2011-02-24"

Last Cell Contents: 
2011-02-24"
;"2010-12-24

pgadmin-hackers by date:

Previous
From: Guillaume Lelarge
Date:
Subject: Re: Polish translation of pgadmin3.po
Next
From: Dave Page
Date:
Subject: pgAdmin III commit: Fix pasting in the Edit Grid to avoid tacking garba