mycli icon indicating copy to clipboard operation
mycli copied to clipboard

Linefeeds are unconditionally (?) shown as \n, making certain output hard to read

Open doublep opened this issue 3 years ago • 9 comments

Version 1.25.0.

When I issue a command like show create table ..., I get hardly-readable output in one string, with \n in place of linefeeds. In comparison, in the standard command-line client, this is shown with linefeeds preserved, making the output easy to read.

I don't see any options in ~/.myclirc that would control this.

doublep avatar Sep 12 '22 14:09 doublep

Hi!

I can't replicate this. I wonder what it depends upon. Do you see the same issue if you terminate the show create table statement with \G instead of ;?

rolandwalker avatar Sep 12 '22 20:09 rolandwalker

I thought it was the standard behavior, but then this explains why I haven't found this reported.

  • Yes, with \G as query terminator linefeeds are displayed as linefeeds, not as \n.
  • Doesn't seem to depend on contents of ~/.myclirc.
  • Mycli version: 1.25.0.
  • Python version: 2.7.16; Python3: 3.10.5.

doublep avatar Sep 13 '22 09:09 doublep

You might go ahead and upgrade mycli if possible, as I am running 1.26.1. But I don't think that is the issue.

I just tried Python 3.10 and it doesn't cause an issue.

The version of MySQL might matter.

Another thing to double-check is running your command after nopager, but I don't think that will be the issue.

Does it only happen with show create table or is it common to every output?

rolandwalker avatar Sep 13 '22 13:09 rolandwalker

You might go ahead and upgrade mycli if possible, as I am running 1.26.1. But I don't think that is the issue.

Done, no change. (Debian has a bug in that sqlglot package is not installed or even present; had to install it with pip3.)

The version of MySQL might matter.

MariaDB 10.6.8-1 (both server and client) from Debian packages.

Another thing to double-check is running your command after nopager

I don't know what that is.

Does it only happen with show create table or is it common to every output?

select 'a\nb';
+------+
| a
b      |
+------+
| a\nb |
+------+

doublep avatar Sep 13 '22 14:09 doublep

That's neat. The column header is wrong too. It should be

select 'a\nb';
+---+
| a |
| b |
|---|
| a |
| b |
+---+

Maybe that's a clue.

rolandwalker avatar Sep 13 '22 15:09 rolandwalker

As I'm a programmer myself, I could do some debugging. But keep in mind that I'm completely unfamiliar with the project and my knowledge of Python is pretty rusty as well. So, you'd need to give me some instructions on what to do and what to look for.

doublep avatar Sep 13 '22 15:09 doublep

Try setting

table_format = psql

in ~/.myclirc if you currently have ascii.

rolandwalker avatar Sep 13 '22 18:09 rolandwalker

Yes, that sort-of fixes the appearance. However, given that it says "# Recommended: ascii", I still see this as a bug.

Also, in psql mode the value is easy to read, but not easy to use:

> create table xxx (x int); show create table xxx;
Query OK, 0 rows affected
Time: 0.023s

+-------+----------------------------+
| Table | Create Table               |
|-------+----------------------------|
| xxx   | CREATE TABLE "xxx" (       |
|       |   "x" int(11) DEFAULT NULL |
|       | )                          |
+-------+----------------------------+

You cannot just copy-paste this into something else, you have to invoke an editor to trim down needless crap. In comparison, the standard client gives a statement that is ready to be copied and executed:

> show create table xxx;
+-------+---------------------------------------------------+
| Table | Create Table                                      |
+-------+---------------------------------------------------+
| xxx   | CREATE TABLE "xxx" (
  "x" int(11) DEFAULT NULL
) |
+-------+---------------------------------------------------+

It would be best, from my point of view, if Mycli could somehow special-case certain queries to skip drawing nice tables, but instead prefer usability. Maybe optionally.

doublep avatar Sep 13 '22 18:09 doublep

You make good points.

The behavior of ascii makes no sense with \n and we should look into the relevant code for bugs.

It's desirable to have ways to emulate the stock client for familiarity, and then have optional ways to make interaction better.

I use psql mode for reading and then \G selectively for copy-paste.

rolandwalker avatar Sep 13 '22 19:09 rolandwalker