Skip to content

Conversation

@dveeden
Copy link

@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) 
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)
@mysql-oca-bot
Copy link

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
Copy link
Author

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
Copy link

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

ericherman added a commit to ericherman/mariadb-server that referenced this pull request Mar 3, 2017
original code: mysql/mysql-server#118 MariaDB [test]> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.03 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 1'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 2'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 3'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | ^_?m?T?dl?^T?|H | test 1 | | !?T?dl?^T?|H | test 2 | | #t1?T??dl?^T??|H | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) With the addition of this patch, the following is possible: MariaDB [test]> select * from t1; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x1FE6166DFF5411E6AB646C8814987C48 | test 1 | | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | | 0x237431D4FF5411E6AB646C8814987C48 | test 3 | +------------------------------------+--------+ 3 rows in set (0.00 sec) MariaDB [test]> select * from t1 where id = 0x21EFDCB2FF5411E6AB646C8814987C48; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | +------------------------------------+--------+ 1 row in set (0.00 sec) MariaDB [test]> select * from t1\G *************************** 1. row *************************** id: 0x1FE6166DFF5411E6AB646C8814987C48 name: test 1 *************************** 2. row *************************** id: 0x21EFDCB2FF5411E6AB646C8814987C48 name: test 2 *************************** 3. row *************************** id: 0x237431D4FF5411E6AB646C8814987C48 name: test 3 3 rows in set (0.01 sec) This patch also introduces the new option --binary-as-hex=0 in order to disable this new behavior.
ericherman added a commit to ericherman/mariadb-server that referenced this pull request Mar 3, 2017
original code: mysql/mysql-server#118 MariaDB [test]> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.03 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 1'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 2'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 3'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | ^_?m?T?dl?^T?|H | test 1 | | !?T?dl?^T?|H | test 2 | | #t1?T??dl?^T??|H | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) With the addition of this patch, the following is possible: MariaDB [test]> select * from t1; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x1FE6166DFF5411E6AB646C8814987C48 | test 1 | | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | | 0x237431D4FF5411E6AB646C8814987C48 | test 3 | +------------------------------------+--------+ 3 rows in set (0.00 sec) MariaDB [test]> select * from t1 where id = 0x21EFDCB2FF5411E6AB646C8814987C48; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | +------------------------------------+--------+ 1 row in set (0.00 sec) MariaDB [test]> select * from t1\G *************************** 1. row *************************** id: 0x1FE6166DFF5411E6AB646C8814987C48 name: test 1 *************************** 2. row *************************** id: 0x21EFDCB2FF5411E6AB646C8814987C48 name: test 2 *************************** 3. row *************************** id: 0x237431D4FF5411E6AB646C8814987C48 name: test 3 3 rows in set (0.01 sec) This patch also introduces the new option --binary-as-hex=0 in order to disable this new behavior.
ericherman added a commit to ericherman/mariadb-server that referenced this pull request Mar 14, 2017
original code: mysql/mysql-server#118 MariaDB [test]> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.03 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 1'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 2'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 3'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | ^_?m?T?dl?^T?|H | test 1 | | !?T?dl?^T?|H | test 2 | | #t1?T??dl?^T??|H | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) With the addition of this patch, the following is possible: MariaDB [test]> select * from t1; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x1FE6166DFF5411E6AB646C8814987C48 | test 1 | | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | | 0x237431D4FF5411E6AB646C8814987C48 | test 3 | +------------------------------------+--------+ 3 rows in set (0.00 sec) MariaDB [test]> select * from t1 where id = 0x21EFDCB2FF5411E6AB646C8814987C48; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | +------------------------------------+--------+ 1 row in set (0.00 sec) MariaDB [test]> select * from t1\G *************************** 1. row *************************** id: 0x1FE6166DFF5411E6AB646C8814987C48 name: test 1 *************************** 2. row *************************** id: 0x21EFDCB2FF5411E6AB646C8814987C48 name: test 2 *************************** 3. row *************************** id: 0x237431D4FF5411E6AB646C8814987C48 name: test 3 3 rows in set (0.01 sec) This patch also introduces the new option --binary-as-hex=0 in order to disable this new behavior.
ericherman added a commit to ericherman/mariadb-server that referenced this pull request Mar 15, 2017
original code: mysql/mysql-server#118 MariaDB [test]> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.03 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 1'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 2'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 3'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | ^_?m?T?dl?^T?|H | test 1 | | !?T?dl?^T?|H | test 2 | | #t1?T??dl?^T??|H | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) With the addition of this patch, the following is possible: MariaDB [test]> select * from t1; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x1FE6166DFF5411E6AB646C8814987C48 | test 1 | | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | | 0x237431D4FF5411E6AB646C8814987C48 | test 3 | +------------------------------------+--------+ 3 rows in set (0.00 sec) MariaDB [test]> select * from t1 where id = 0x21EFDCB2FF5411E6AB646C8814987C48; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | +------------------------------------+--------+ 1 row in set (0.00 sec) MariaDB [test]> select * from t1\G *************************** 1. row *************************** id: 0x1FE6166DFF5411E6AB646C8814987C48 name: test 1 *************************** 2. row *************************** id: 0x21EFDCB2FF5411E6AB646C8814987C48 name: test 2 *************************** 3. row *************************** id: 0x237431D4FF5411E6AB646C8814987C48 name: test 3 3 rows in set (0.01 sec) This patch also introduces the new option --binary-as-hex=0 in order to disable this new behavior.
ericherman added a commit to ericherman/mariadb-server that referenced this pull request Mar 24, 2017
original code: mysql/mysql-server#118 MariaDB [test]> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.03 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 1'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 2'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 3'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | ^_?m?T?dl?^T?|H | test 1 | | !?T?dl?^T?|H | test 2 | | #t1?T??dl?^T??|H | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) With the addition of this patch, the following is possible: MariaDB [test]> select * from t1; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x1FE6166DFF5411E6AB646C8814987C48 | test 1 | | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | | 0x237431D4FF5411E6AB646C8814987C48 | test 3 | +------------------------------------+--------+ 3 rows in set (0.00 sec) MariaDB [test]> select * from t1 where id = 0x21EFDCB2FF5411E6AB646C8814987C48; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | +------------------------------------+--------+ 1 row in set (0.00 sec) MariaDB [test]> select * from t1\G *************************** 1. row *************************** id: 0x1FE6166DFF5411E6AB646C8814987C48 name: test 1 *************************** 2. row *************************** id: 0x21EFDCB2FF5411E6AB646C8814987C48 name: test 2 *************************** 3. row *************************** id: 0x237431D4FF5411E6AB646C8814987C48 name: test 3 3 rows in set (0.01 sec) This patch also introduces the new option --binary-as-hex=0 in order to disable this new behavior.
ericherman added a commit to ericherman/mariadb-server that referenced this pull request Mar 24, 2017
original code: mysql/mysql-server#118 MariaDB [test]> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.03 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 1'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 2'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 3'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | ^_?m?T?dl?^T?|H | test 1 | | !?T?dl?^T?|H | test 2 | | #t1?T??dl?^T??|H | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) With the addition of this patch, the following is possible: MariaDB [test]> select * from t1; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x1FE6166DFF5411E6AB646C8814987C48 | test 1 | | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | | 0x237431D4FF5411E6AB646C8814987C48 | test 3 | +------------------------------------+--------+ 3 rows in set (0.00 sec) MariaDB [test]> select * from t1 where id = 0x21EFDCB2FF5411E6AB646C8814987C48; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | +------------------------------------+--------+ 1 row in set (0.00 sec) MariaDB [test]> select * from t1\G *************************** 1. row *************************** id: 0x1FE6166DFF5411E6AB646C8814987C48 name: test 1 *************************** 2. row *************************** id: 0x21EFDCB2FF5411E6AB646C8814987C48 name: test 2 *************************** 3. row *************************** id: 0x237431D4FF5411E6AB646C8814987C48 name: test 3 3 rows in set (0.01 sec) This patch also introduces the new option --binary-as-hex=0 in order to disable this new behavior.
ericherman added a commit to ericherman/mariadb-server that referenced this pull request Jun 9, 2017
original code: mysql/mysql-server#118 MariaDB [test]> create table t1(id binary(16) primary key, name varchar(100)); Query OK, 0 rows affected (0.03 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 1'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 2'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> insert into t1 values(unhex(replace(uuid(),'-','')), 'test 3'); Query OK, 1 row affected (0.00 sec) MariaDB [test]> select * from t1; +------------------+--------+ | id | name | +------------------+--------+ | ^_?m?T?dl?^T?|H | test 1 | | !?T?dl?^T?|H | test 2 | | #t1?T??dl?^T??|H | test 3 | +------------------+--------+ 3 rows in set (0.00 sec) With the addition of this patch, the following is possible: MariaDB [test]> select * from t1; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x1FE6166DFF5411E6AB646C8814987C48 | test 1 | | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | | 0x237431D4FF5411E6AB646C8814987C48 | test 3 | +------------------------------------+--------+ 3 rows in set (0.00 sec) MariaDB [test]> select * from t1 where id = 0x21EFDCB2FF5411E6AB646C8814987C48; +------------------------------------+--------+ | id | name | +------------------------------------+--------+ | 0x21EFDCB2FF5411E6AB646C8814987C48 | test 2 | +------------------------------------+--------+ 1 row in set (0.00 sec) MariaDB [test]> select * from t1\G *************************** 1. row *************************** id: 0x1FE6166DFF5411E6AB646C8814987C48 name: test 1 *************************** 2. row *************************** id: 0x21EFDCB2FF5411E6AB646C8814987C48 name: test 2 *************************** 3. row *************************** id: 0x237431D4FF5411E6AB646C8814987C48 name: test 3 3 rows in set (0.01 sec) This patch also introduces the new option --binary-as-hex=0 in order to disable this new behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants