Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pawel-slowik/sql-xml-to-csv
Convert MySQL / MariaDB XML into CSV
https://github.com/pawel-slowik/sql-xml-to-csv
csv mariadb mysql xml xslt
Last synced: 10 days ago
JSON representation
Convert MySQL / MariaDB XML into CSV
- Host: GitHub
- URL: https://github.com/pawel-slowik/sql-xml-to-csv
- Owner: pawel-slowik
- License: unlicense
- Created: 2024-02-28T14:59:27.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-12-20T12:50:07.000Z (28 days ago)
- Last Synced: 2024-12-20T13:46:31.615Z (28 days ago)
- Topics: csv, mariadb, mysql, xml, xslt
- Language: XSLT
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Convert MySQL / MariaDB XML into CSV
This is a XSLT 1.0 transformation that converts MySQL / MariaDB XML output into
CSV format.It can be useful for dumping database contents into CSV files when you can't use
the `SELECT ... INTO OUTFILE ...` syntax.## Usage
With the CLI client:
echo 'SELECT * FROM table' | \
mariadb --batch --xml --host localhost --user user --password=password db | \
xsltproc xml2csv.xslt - > output.csvWith the `mysqldump` CLI utility:
mysqldump --xml --host localhost --user user --password=password db table | \
xsltproc xml2csv.xslt - > output.csvUsing `;` instead of the default `,` as column separators:
mysqldump --xml --host localhost --user user --password=password db table | \
xsltproc --stringparam column_separator ';' xml2csv.xslt - > output.csv### Parameters
- `column_separator` - string used to separate columns. This is the equivalent
of the `TERMINATED BY ...` option for `SELECT ... INTO OUTFILE ...`. Default
is `,`.
- `column_enclosed_by` - string used to quote column values. This is meant to be
the equivalent of the `ENCLOSED BY ...` option, but its handling may be
slightly different. Default is `"`. Can be empty.
- `column_escaped_by` - string used to escape the `column_enclosed_by`
character. This is roughly equivalent to the `ESCAPED BY ...` option.
Default is `\`.
- `escape_newlines` - string with two allowed values:
- `1`: replace newlines in column content with the string `\n`. This is the
default.
- `0`: output newlines unchanged.## End of line processing
The XML engine does not distinguish between various [newline
representations](https://en.wikipedia.org/wiki/End_of_line). Therefore any
required end of line processing should be performed separately. This could be
implemented either before any XML processing, e.g. in SQL queries, or after
finishing it, with tools like `sed`, `tr`, `dos2unix` etc.`xsltproc`'s internal representation of a newline can be verified like this:
printf 'a\nb' | xsltproc test_newlines.xslt -
printf 'a\rb' | xsltproc test_newlines.xslt -
The output is the same for both cases, even though they contain data with
different line endings.