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/8.0.15 OS: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] MySQL Verification Team
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.
[6 Mar 2019 20:56] Michael Lyons
The report at https://bugs.mysql.com/bug.php?id=87856 is a duplicate of this bug.
[24 Jan 2020 16:25] Michael Lyons
This is now a bigger problem, because downgrading to a working version of MySQL Workbench is no longer an available workaround on MacOS Catalina.

Please give this regression some priority. I see that the results pane code uses Python. Python's builtin `csv` library will use the right format for the results we need.
[14 May 2020 10:13] - -
This still an issue in latest version 8.0.20 - a fix would be much appreciated.