Python script to fill a SQLite DB file by SQL dump and write content as CSV.
convert
csv
db
forensic
forensic-software
forensic-tools
forensics
forensics-tools
python
python3
sql
sqlite
sqlite3
- Python 100%
| .gitignore | ||
| LICENSE | ||
| README.md | ||
| sql2csv.py | ||
SQL2CSV
Python script to fill a SQLite DB file by SQL dump and write content as CSV.
Features
- Execute SQL statements directly or from files
- Create a SQLite DB file if necessary
- Convert SQL dumps to SQLite-compatible format
- View database schema
- Export tables to CSV files
Usage
python sql2csv.py [-h] [-a DIRECTORY] [-c COLUMN NAME / STRING] [-d CHAR / STRING]
[-e SQL STATEMENT / STRING] [-f SQL FILE] [-g] [-l] [-n INTEGER]
[-r PATH] [-s] [-t TABLE NAME / STRING] [-w FILE]
FILE
Arguments
FILE: SQLite database file path
Options
-a, --all DIRECTORY: Export all tables to CSV files in the specified directory-c, --column COLUMN: Select a specific column (requires-t/--table)-d, --delimiter CHAR: Set delimiter between columns (default: tab)-e, --execute SQL: Execute SQL statement-f, --file PATH: Execute SQL statements from file with SQLite compatibility translation-g, --debug: Enable debug mode (gives output on -e/--execute, -f/--file or -r/--read)-l, --headless: Omit headers/field names in output-n, --lines INTEGER: Limit output to n lines (0 for headers only)-r, --read PATH: Execute SQL statements from file without translation-s, --schema: Print database schema-t, --table TABLE: Select table to export-w, --write FILE: Write output to file instead of stdout
Examples
Execute SQL statement
python sql2csv.py sqlite.db -e "CREATE TABLE table_name (col1_name, col2_name);"
Import SQL dump with SQLite compatibility
python sql2csv.py sqlite.db -f dump.sql
View database schema
python sql2csv.py sqlite.db -s
Export a table to CSV
python sql2csv.py sqlite.db -t table_name -w outfile.csv
Export a specific column
python sql2csv.py sqlite.db -t table_name -c column_name -w outfile.csv
Export all tables to separate CSV files in given directory
python sql2csv.py sqlite.db -a ./exports
Create SQLite file from SQL dump and create CSV files
Choose an unused file name for sqlite.db to convert dump.sql directly into CSV files
python sql2csv.py sqlite.db -f dump.sql -a ./exports
Legal Notice
License
Respect GPL-3: https://www.gnu.org/licenses/gpl-3.0.en.html
Disclaimer
Use the software on your own risk.
This is not a commercial product with an army of developers and a department for quality control behind it.