Skip to content

Conversation

@gfrlv
Copy link
Member

@gfrlv gfrlv commented Apr 28, 2020

Description

Formatters from sql_format didn't handle binary data correctly (tried to print raw data instead of hex strings)

Checklist

  • I've added this contribution to the changelog.md.
  • I've added my name to the AUTHORS file (or it's already there).

@amjith
Copy link
Member

amjith commented May 2, 2020

Can you give me an example sql statement to test? I'm not sure I understand the fix.

@gfrlv
Copy link
Member Author

gfrlv commented May 3, 2020

Sure, we need a table with a binary column:

mysql root@localhost:test> create table t(x binary);                                                                                                                                                               
Query OK, 0 rows affected
Time: 0.138s
mysql root@localhost:test> insert into t (x) values (0xAA)                                                                                                                                                         
Query OK, 1 row affected
Time: 0.100s

Now in ascii format it displays alright:

mysql root@localhost:test> select * from t;                                                                                                                                                                        
+------+
| x    |
+------+
| 0xaa |
+------+

But not so in sql-insert:

mysql root@localhost:test> \T sql-insert                                                                                                                                                                           
Changed table format to sql-insert
Time: 0.000s
mysql root@localhost:test> select * from t;                                                                                                                                                                        
INSERT INTO t (`x`) VALUES
'utf-8' codec can't encode character '\udcaa' in position 4: surrogates not allowed

With the fix:

mysql root@localhost:test> select * from t;                                                                                                                                                                        
INSERT INTO t (`x`) VALUES
  (X'aa')
;

@amjith
Copy link
Member

amjith commented May 4, 2020

Good catch.

I fixed the lint error.

🍦

@amjith amjith merged commit 84dcba2 into master May 4, 2020
@gfrlv gfrlv deleted the sql-insert-bytes branch May 16, 2020 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants