Skip to content

Pull Request: Add support for Windows and multi-file CSV export with cleaned values #9

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dmikester1
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant