Comments - mysql Command-line Client

13 years, 6 months ago Sidhartha Mandal
This comment has the status of 'spam' and can only be seen by you.

How about adding -J (or --json) flag to extract json output of a SQL using mysql client. [just like -X or -H options]

Example: Here below, I'm extracting using 2 step process (using sed). It would be great if we can handle this using C and some good JSON parser.

Create a small bash script named tojson: --

  1. !/bin/bash

sed -e 's/\t/\",\"/g' \ -e 's/^/\[\"/' \ -e 's/$/\"\],/' \ -e '1s/\(.*\)/\{\"fields\":\1\ \"data\":[/g' -e '$s/.$/\]\}/' \

tr -d "\n"

--

To execute:

mysql -u<dbuser> -p<dbpass> -S<socket-path> -D<dbname> -X -e "SQL-STATEMENT" | ./tojson

Now a days JSON parsers are widely used and has lots of benefits over XML.

 
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.