dbcli / mycli

A Terminal Client for MySQL with AutoCompletion and Syntax Highlighting.
http://mycli.net
Other
11.49k stars 663 forks source link

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

Open doublep opened 2 years ago

doublep commented 2 years ago

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.

rolandwalker commented 2 years ago

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 ;?

doublep commented 2 years ago

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

rolandwalker commented 2 years ago

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?

doublep commented 2 years ago

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 |
+------+
rolandwalker commented 2 years ago

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

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

Maybe that's a clue.

doublep commented 2 years ago

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.

rolandwalker commented 2 years ago

Try setting

table_format = psql

in ~/.myclirc if you currently have ascii.

doublep commented 2 years ago

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.

rolandwalker commented 2 years ago

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.