yy0931 / sqlite3-editor

https://marketplace.visualstudio.com/items?itemName=yy0931.vscode-sqlite3-editor
GNU General Public License v3.0
1.02k stars 7 forks source link

CSV export, issue with special characters in text, blank lines added #22

Closed DominiqueE38 closed 1 year ago

DominiqueE38 commented 1 year ago

Congrats for this very useful extension. I would like to mention some issues in the CSV export when having text in a table:

1-The export is not working in case of text with special characters, see description below 2- A new line is generated in case of a text embedding a newline character in it 3- There are additional blank lines generated in CSV (on windows)

To Reproduce Issue 1

  1. open a Sqlite database in the editor, select a table with a text column with some of those texts having extended ASCII codes
  2. Click on 'other Tools' > Export Table to CSV
  3. See error in the terminal: Traceback (most recent call last): File "c:\Users....vscode\extensions\yy0931.vscode-sqlite3-editor-1.0.85\export_table.py", line 26, in writer.writerow(row) File "C:\Users...\AppData\Local\Programs\Python\Python311\Lib\encodings\cp1252.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0]

Solution tested I have modified "export_table.py" by adding some arguments to the open, and it does solve the 3 issues for me:

with contextlib.closing(sqlite3.connect(args.database)) as conn, open(args.out_file, "w") as f:

with contextlib.closing(sqlite3.connect(args.database)) as conn, open(args.out_file, "w",newline='', encoding='utf-8') as f:

yy0931 commented 1 year ago

Thanks! I will include the change in the next version.

yy0931 commented 1 year ago

v1.0.86 includes the fix.