Bug #86666 Workbench mostly incorrectly exports CSV when double quotes present
Submitted: 13 Jun 2017 1:09 Modified: 13 Jun 2017 7:19
Reporter: J Scavok Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Workbench: SQL Editor Severity:S2 (Serious)
Version:6.3.9 OS:Microsoft Windows (Windows 7 Pro SP1 64-bit)
Assigned to: CPU Architecture:Any
Tags: csv, double quotes, export

[13 Jun 2017 1:09] J Scavok
Description:
Clicking the "Export recordset to an external file" icon (present on the Result Grid) incorrectly represents double quotes in the resultant file.

Subsequently opening the exported CSV in say Excel produces erroneous results.

How to repeat:
CREATE TABLE IF NOT EXISTS `csvs` (
  test VARCHAR(45) NOT NULL
)
ENGINE = InnoDB;

INSERT INTO csvs VALUES 
('hello, world'), 
('"hello, yourself"'), 
('""CSV" spec? "Never heard of it!"'), 
('Venture "Extended Edition"'),
('Venture "Extended Edition, Very Large"');

select * from csvs;

--So far, everything is OK.

--Now this is where the shit hits the fan
--Here is the contents of the "Export recordset to an external file" (with my annotations):

test
"hello, world"
""hello, yourself""                       -- WRONG!
"""CSV" spec?" "Never heard of it!""      -- WRONG!
"Yet more "BUGS" in Workbench."           -- WRONG!
"Venture "Extended Edition""              -- WRONG!
"Venture "Extended Edition, Very Large""  -- WRONG!

Try opening the file in say Excel to see how mangled the data has become.

The correct export is:

test
"hello, world"
"""hello, yourself"""
"""""CSV"" spec?"" ""Never heard of it!"""
"Yet more ""BUGS"" in Workbench."
"Venture ""Extended Edition"""
"Venture ""Extended Edition, Very Large"""

Suggested fix:
Start here: https://en.wikipedia.org/wiki/Comma-separated_values
[13 Jun 2017 7:19] Umesh Shastry
Hello J Scavok,

Thank you for the report and test case.
Verified as described with WB 6.3.9 on Win7.

Thanks,
Umesh
[2 Oct 2017 18:09] Don McCullough
I have this happen in OS X workbench 6.3.9 when double quotes or Linefeeds happen in data is messes up the csv.

6.2.5 does not have this issue.