Pull Request: Add support for Windows and multi-file CSV export with cleaned values #9
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR enhances the mysqldump-to-csv script by:
💾 Creating one CSV file per INSERT statement, named after the table (e.g., chemicals.csv)
🧹 Removing surrounding single quotes from values for clean CSV output
🧠 Handling NULLs gracefully
📝 Including column headers in the generated CSV files
Motivation
I ran into issues when parsing MySQL dump files — especially with quoted values, multi-row inserts, and the desire to organize output by table. This update improves compatibility and readability of exported data for downstream tools like Excel, pandas, etc.
Changes
Fixed support for Windows by conditionally importing SIGPIPE
Modified parse_values() to manually split and clean each value, avoiding edge cases from csv.reader
Added logic to extract table name from INSERT INTO lines
Writes each set of rows into a dedicated CSV file, with matching table name
Added header row based on the column list from the SQL
Example
From this SQL:
sql
Copy
Edit
INSERT INTO
chemicals
(id
,name
,created_at
,updated_at
,deleted_at
) VALUES(1, 'Acelepryn', '2020-08-04 17:07:09', '2020-08-04 17:07:09', NULL);
It generates a file chemicals.csv with:
csv
Copy
Edit
id,name,created_at,updated_at,deleted_at
1,Acelepryn,2020-08-04 17:07:09,2020-08-04 17:07:09,
Thanks for the cool project 🙌
— Mike