Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql2csv: Support encoding flag for query files (--query-encoding) #614

Closed
jonashaag opened this issue May 31, 2016 · 7 comments · Fixed by #771
Closed

sql2csv: Support encoding flag for query files (--query-encoding) #614

jonashaag opened this issue May 31, 2016 · 7 comments · Fixed by #771
Labels
Milestone

Comments

@jonashaag
Copy link

jonashaag commented May 31, 2016

$ sql2csv ...
...
Your file is not "utf-8" encoded. Please specify the correct encoding with the -e flag.
Use the -v flag to see the complete error.

$ sql2csv ... -e 'iso-8859-1'
usage: sql2csv [-h] [-v] [-l] [--db CONNECTION_STRING] [--query QUERY] [-H]
               [FILE]
sql2csv: error: argument FILE: can't open 'iso-8859-1': [Errno 2] No such file or directory: 'iso-8859-1'
@jpmckinney jpmckinney added the bug label Jun 3, 2016
@jpmckinney jpmckinney added question and removed bug labels Oct 11, 2016
@jpmckinney
Copy link
Member

Can you provide a sample file?

@jonashaag
Copy link
Author

This doesn't have anything to do with my input fine. It's simply that the -e option is not implemented.

@jpmckinney
Copy link
Member

To reproduce the first error:

sql2csv examples/test_latin1.csv

@jpmckinney
Copy link
Member

jpmckinney commented Oct 11, 2016

sql2csv accepts a SQL query as an argument, not a CSV file. The -e option only applies to input CSV files. Why is your SQL query stored in a non-UTF-8 file?

I admit the error message is confusing.

@jpmckinney jpmckinney changed the title Cannot specify encoding in sql2csv Confusing error message if sql2csv's query file is not UTF-8 Oct 11, 2016
@jpmckinney jpmckinney changed the title Confusing error message if sql2csv's query file is not UTF-8 sql2csv: Confusing error message if query file is not UTF-8 Oct 11, 2016
@jonashaag
Copy link
Author

Why is your SQL query stored in a non-UTF-8 file?

I don't know, it's simply what comes out of mysqldump

@jpmckinney jpmckinney added bug and removed question labels Oct 14, 2016
@todofixthis
Copy link

mysqldump should default to using UTF8 as the character set for its output (source). If necessary, you can instruct it to use a different character set via the --default-character-set option.

Are you running mysqldump on Windows? See this note in the mysqldump documentation:

Note

A dump made using PowerShell on Windows with output redirection creates a file that has UTF-16 encoding:

shell> mysqldump [options] > dump.sql

However, UTF-16 is not permitted as a connection character set (see Section 11.1.4, “Connection Character Sets and Collations”), so the dump file will not load correctly. To work around this issue, use the --result-file option, which creates the output in ASCII format:

shell> mysqldump [options] --result-file=dump.sql

@jonashaag
Copy link
Author

No, Linux/Mac OS but the table is in Latin1

@onyxfish onyxfish changed the title sql2csv: Confusing error message if query file is not UTF-8 sql2csv: Support encoding flag for query files (--query-encoding) Dec 29, 2016
@jpmckinney jpmckinney added this to the Easy milestone Jan 27, 2017
jpmckinney pushed a commit that referenced this issue Jan 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants