Bug #29146 Output truncated when resultset contains \r
Submitted: 15 Jun 2007 19:08 Modified: 5 Mar 2008 8:47
Reporter: Todd Farmer (OCA) Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.0.41 OS:Any
Assigned to: CPU Architecture:Any

[15 Jun 2007 19:08] Todd Farmer
Description:
Rows with \r character in resultset are truncated from leading edge when displayed in command-line client.  No data loss is observed:

mysql> DROP TABLE IF EXISTS `t1`;
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> CREATE TABLE `t1` (
    ->   `dt` datetime default NULL,
    ->   `a` int(11) default NULL,
    ->   `state` varchar(15) default NULL
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.11 sec)

mysql> --
mysql>
mysql> INSERT INTO `t1` VALUES ('2007-06-12 14:11:45',11,'Aborting\r');
Query OK, 1 row affected (0.05 sec)

mysql> INSERT INTO `t1` VALUES ('2007-06-12 14:11:45',11,'Aborting\n');
Query OK, 1 row affected (0.06 sec)

mysql> INSERT INTO `t1` VALUES ('2007-06-12 14:11:45',11,'Aborting');
Query OK, 1 row affected (0.08 sec)

mysql>
mysql> SELECT * FROM t1;
+---------------------+------+-----------+
| dt                  | a    | state     |
+---------------------+------+-----------+
 | 007-06-12 14:11:45 |   11 | Aborting
| 2007-06-12 14:11:45 |   11 | Aborting
 |
| 2007-06-12 14:11:45 |   11 | Aborting  |
+---------------------+------+-----------+
3 rows in set (0.00 sec)

mysql>
mysql> UPDATE t1 SET state = 'done';
Query OK, 3 rows affected (0.02 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql>
mysql> SELECT * FROM t1;
+---------------------+------+-------+
| dt                  | a    | state |
+---------------------+------+-------+
| 2007-06-12 14:11:45 |   11 | done  |
| 2007-06-12 14:11:45 |   11 | done  |
| 2007-06-12 14:11:45 |   11 | done  |
+---------------------+------+-------+
3 rows in set (0.00 sec)

SELECT * FROM t1;

How to repeat:
DROP TABLE IF EXISTS `t1`;
CREATE TABLE `t1` (
  `dt` datetime default NULL,
  `a` int(11) default NULL,
  `state` varchar(15) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--

INSERT INTO `t1` VALUES ('2007-06-12 14:11:45',11,'Aborting\r');
INSERT INTO `t1` VALUES ('2007-06-12 14:11:45',11,'Aborting\n');
INSERT INTO `t1` VALUES ('2007-06-12 14:11:45',11,'Aborting');

SELECT * FROM t1;

UPDATE t1 SET state = 'done';

SELECT * FROM t1;

Suggested fix:
Don't truncate rows with \r characters.
[22 Feb 2008 21:22] Omer Barnir
workaround Use \G
[27 Feb 2008 18:39] Jim Winstead
Is anything really getting truncated here? \r is a carriage return, which on many (most?) terminals will simply move the insertion point back to the beginning of the line.

The output is exactly what I would expect. The first row is printing everything up to the \r, the insertion point is getting moved back to the beginning of the line, and then ' | ' is being printed, overwriting the first few characters of what was already printed. This is different from \n, which goes to the next row, and is why the second row is split across two lines.

I believe that this is not a bug.
[5 Mar 2008 8:47] Todd Farmer
Jim,

You're exactly right, thanks for pointing the way here.  Marking as not a bug.