Print binary data as hex in the mysql client #118

Closed
wants to merge 3 commits into
from

Projects

None yet

2 participants

@dveeden
dveeden commented Jan 1, 2017

Print binary data as hex literals.
The result is that this doesn't break my terminal if I select a binary column and this allows me
to copy-paste the output to the were clause of my next query.

mysql> select * from t1;
+----+------------------------------------+
| id | ip                                 |
+----+------------------------------------+
|  1 | 0x00000000000000000000000000000001 |
|  2 | 0x7F000001                         |
|  3 | 0x08080808                         |
|  4 | 0x08080404                         |
+----+------------------------------------+
4 rows in set (0.00 sec)

mysql> show create table t1\G
*************************** 1. row ***************************
       Table: t1
Create Table: CREATE TABLE `t1` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `ip` varbinary(16) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

mysql> select ip,INET6_NTOA(ip) FROM t1 WHERE ip=0x08080404;
+------------+----------------+
| ip         | INET6_NTOA(ip) |
+------------+----------------+
| 0x08080404 | 8.8.4.4        |
+------------+----------------+
1 row in set (0.00 sec)
dveeden added some commits Dec 26, 2016
@dveeden dveeden Print blob and varchar as hex literal in vertical output
Example:

mysql> create table t1(id binary(16) primary key, name varchar(100));
Query OK, 0 rows affected (0.05 sec)

mysql> insert into t1 values(uuid_to_bin(uuid()), 'test 1');
Query OK, 1 row affected (0.01 sec)

mysql> insert into t1 values(uuid_to_bin(uuid()), 'test 2');
Query OK, 1 row affected (0.01 sec)

mysql> insert into t1 values(uuid_to_bin(uuid()), 'test 3');
Query OK, 1 row affected (0.01 sec)

mysql> select * from t1;
+------------------+--------+
| id               | name   |
+------------------+--------+
|  �
�`��w���}4        | test 1 |
| "3l��`��w���}4        | test 2 |
| $����`��w���}4          | test 3 |
+------------------+--------+
3 rows in set (0.00 sec)

mysql> select * from t1\G
*************************** 1. row ***************************
  id: 0x20D7170ACB6011E6BD77AC87A3027D34
name: test 1
*************************** 2. row ***************************
  id: 0x22336CBDCB6011E6BD77AC87A3027D34
name: test 2
*************************** 3. row ***************************
  id: 0x24A2AD93CB6011E6BD77AC87A3027D34
name: test 3
3 rows in set (0.00 sec)

mysql> select * from t1 where id=0x22336CBDCB6011E6BD77AC87A3027D34;
+------------------+--------+
| id               | name   |
+------------------+--------+
| "3l��`��w���}4        | test 2 |
+------------------+--------+
1 row in set (0.00 sec)
152db93
@dveeden dveeden Also print horizontal output as hex 606604d
@dveeden dveeden Add option to disable the print-binary-as-hex feature 6fd9d14
@mysql-oca-bot

Hi, thank you for your contribution. Please confirm this code is submitted under the terms of the OCA (Oracle's Contribution Agreement) you have previously signed by cutting and pasting the following text as a comment:
"I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it."
Thanks

@dveeden
dveeden commented Jan 2, 2017

I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

@mysql-oca-bot

Hi, thank you for your contribution. Your code has been assigned to an internal queue. Please follow
bug http://bugs.mysql.com/bug.php?id=84391 for updates.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment