mycli icon indicating copy to clipboard operation
mycli copied to clipboard

'list index out of range' when dealing with '\r\n'

Open whm2015 opened this issue 6 years ago • 3 comments

I have a table which contains '\r\n' in it. When I select from the table the problem occured. The row which contains the special charactor can't be included in the select result, or else it will report the error.

At first the problem appears in version 1.17.0, then I changed to the newest version 1.21.1 in another machine, it sucessfully retured the result contain '\r\n', but failed to return another results contain '\rx\n'('x' is another charactor)

I draged the special row from the table into a new table named 'user_test', and I uploaded it so you might reproduce the problen. user_test.txt it has only two rows, each row has two columns named 'name' and 'username': ('akop\r\n','akop07') ('Pablo\rß\n','l1nkworld')

in version 1.17.0, select * from any row or all row from the table will fail

mysql root@localhost:test> select * from user_test limit 0, 1
list index out of range
mysql root@localhost:test> select * from user_test limit 1, 1
list index out of range
mysql root@localhost:test> select * from user_test
list index out of range

but select one column, or put the special column to the end, will success:

mysql root@localhost:test> select name from user_test
+-------+
| name  |
+-------+
| akop  |
|       |
|       |
| Pablo |
| ß     |
|       |
+-------+
2 rows in set
Time: 0.014s
mysql root@localhost:test> select username from user_test
+-----------+
| username  |
+-----------+
| akop07    |
| l1nkworld |
+-----------+
2 rows in set
Time: 0.013s
mysql root@localhost:test> select username, name from user_test
+-----------+-------+
| username  | name  |
+-----------+-------+
| akop07    | akop  |
|           |       |
| l1nkworld | Pablo |
|           | ß     |
+-----------+-------+
2 rows in set
Time: 0.013s

in version 1.21.1, it can handle the first row:

mysql [email protected]:test> select * from user_test limit 0, 1
+------+----------+
| name | username |
+------+----------+
| akop | akop07   |
|      |          |
+------+----------+
1 row in set
Time: 0.023s
mysql [email protected]:test> select * from user_test limit 1, 1
list index out of range
mysql [email protected]:test> select * from user_test
list index out of range

and also seccessfully returned when select one row or put the special row to the end, like the above:

mysql [email protected]:test> select name from user_test
+-------+
| name  |
+-------+
| akop  |
|       |
| Pablo |
| ݠ    |
|       |
+-------+
2 rows in set
Time: 0.022s
mysql [email protected]:test> select username from user_test
+-----------+
| username  |
+-----------+
| akop07    |
| l1nkworld |
+-----------+
2 rows in set
Time: 0.021s
mysql [email protected]:test> select username, name from user_test
+-----------+-------+
| username  | name  |
+-----------+-------+
| akop07    | akop  |
|           |       |
| l1nkworld | Pablo |
|           | ݠ    |
+-----------+-------+

If there is any problem with my operation or configuration, please let me know. Thx.

whm2015 avatar May 24 '20 09:05 whm2015

Thanks for reporting! It is a bug in the library we use for drawing tables (terminaltables). I'll see what can be done about it, in the meantime you can use one of the not affected formatters, for example grid or fancy_grid:

mysql root@(none):test> \T fancy_grid;                                              
Changed table format to fancy_grid
Time: 0.000s
mysql root@(none):test> select * from user_test;                                    
╒════════╤════════════╕
│ name   │ username   │
╞════════╪════════════╡
│ akop   │ akop07     │
├────────┼────────────┤
│ Pablo  │ l1nkworld  │
│ ß      │            │
╘════════╧════════════╛
2 rows in set
Time: 0.010s

gfrlv avatar May 24 '20 11:05 gfrlv

I think the right way to handle this situation in the formatters that don't draw lines between rows is to simply escape newline characters, otherwise the output would be ambiguous.

gfrlv avatar May 24 '20 11:05 gfrlv

Thanks a lot!

whm2015 avatar May 24 '20 12:05 whm2015