Bug #7606 Embedded newlines break table-format display
Submitted: 1 Jan 2005 14:25
Reporter: Geoff Kuenning Email Updates:
Status: Open Impact on me:
Category:MySQL Server: Command-line Clients Severity:S4 (Feature request)
Version:4.0.21 OS:Linux (Linux)
Assigned to: CPU Architecture:Any

[1 Jan 2005 14:25] Geoff Kuenning
If a table contains a text field with embedded newline characters, the
mysql client will format it incorrectly in table-display mode (and
will also do a fairly bad job in vertical mode).  The reason is that
the display code doesn't detect the newlines and give any special
treatment to them.

How to repeat:
The following brief mysql session illustrates the problem:

$ mysql
mysql> use test;
mysql> create table broken (id mediumint not null auto_increment, name text, primary key (id));
mysql> insert into broken values(NULL, 'abcdef'),(NULL, 'ghi
    '> jkl');
mysql> select * from broken;
| id | name    |
|  1 | abcdef  |
|  2 | ghi
jkl |
2 rows in set (0.40 sec)

mysql> select * from broken\G
*************************** 1. row ***************************
  id: 1
name: abcdef
*************************** 2. row ***************************
  id: 2
name: ghi
2 rows in set (0.00 sec)

mysql> drop table broken;
mysql> quit

Suggested fix:
The quick-and-easy fix would be to add a command-line switch that was
the inverse of "-r", so that newlines (and other troublesome
characters such as carriage returns) would be escaped as \n or a
similar sequence.

The nicer fix would be to modify the table-display code to do what web
browsers and text formatters do with multi-line tables, producing
output like:

| id | name    |
|  1 | abcdef  |
|  2 | ghi     |
|    | jkl     |

But of course that's nontrivial even if only one column has embedded