Bug #46323 mysql client, prettier HTML output

Submitted: 21 Jul 2009 12:50 Modified: 21 Jul 2009 13:16
Reporter: Kai Voigt Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:any OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution, mysql command line client html output pretty

[21 Jul 2009 12:50] Kai Voigt
Description:
The output format of mysql --html is not as pretty as --xml output. A couple of line breaks and indents would help to make the output more readable.

How to repeat:
kai-voigts-macbook-air:client k$ mysql -V
mysql  Ver 14.14 Distrib 5.1.32-ndb-7.0.5, for apple-darwin9.5.0 (i386) using readline 5.1
kai-voigts-macbook-air:client k$ mysql -uroot -proot -e "select * from world.city limit 3" --html
<TABLE BORDER=1><TR><TH>ID</TH><TH>Name</TH><TH>CountryCode</TH><TH>District</TH><TH>Population</TH></TR><TR><TD>1</TD><TD>Kabul</TD><TD>AFG</TD><TD>Kabol</TD><TD>1780000</TD></TR><TR><TD>2</TD><TD>Qandahar</TD><TD>AFG</TD><TD>Qandahar</TD><TD>237500</TD></TR><TR><TD>3</TD><TD>Herat</TD><TD>AFG</TD><TD>Herat</TD><TD>186800</TD></TR></TABLE>kai-voigts-macbook-air:client k$ 

Suggested fix:
kai-voigts-macbook-air:client k$ diff -c mysql.cc.orig mysql.cc
*** mysql.cc.orig	2009-06-16 14:22:52.000000000 +0200
--- mysql.cc	2009-07-21 13:39:47.000000000 +0200
***************
*** 3388,3422 ****
    MYSQL_FIELD	*field;
  
    mysql_field_seek(result,0);
!   (void) tee_fputs("<TABLE BORDER=1><TR>", PAGER);
    if (column_names)
    {
      while((field = mysql_fetch_field(result)))
      {
!       tee_fputs("<TH>", PAGER);
!       if (field->name && field->name[0])
          xmlencode_print(field->name, field->name_length);
!       else
          tee_fputs(field->name ? " &nbsp; " : "NULL", PAGER);
!       tee_fputs("</TH>", PAGER);
      }
!     (void) tee_fputs("</TR>", PAGER);
    }
    while ((cur = mysql_fetch_row(result)))
    {
      if (interrupted_query)
        break;
      ulong *lengths=mysql_fetch_lengths(result);
!     (void) tee_fputs("<TR>", PAGER);
      for (uint i=0; i < mysql_num_fields(result); i++)
      {
!       (void) tee_fputs("<TD>", PAGER);
        xmlencode_print(cur[i], lengths[i]);
!       (void) tee_fputs("</TD>", PAGER);
      }
!     (void) tee_fputs("</TR>", PAGER);
    }
!   (void) tee_fputs("</TABLE>", PAGER);
  }
  
  
--- 3388,3423 ----
    MYSQL_FIELD	*field;
  
    mysql_field_seek(result,0);
!   (void) tee_fputs("<TABLE BORDER=1>\n  <TR>\n", PAGER);
    if (column_names)
    {
      while((field = mysql_fetch_field(result)))
      {
!       tee_fputs("    <TH>", PAGER);
!       if (field->name && field->name[0]) {
          xmlencode_print(field->name, field->name_length);
!       } else {
          tee_fputs(field->name ? " &nbsp; " : "NULL", PAGER);
!       }
!       tee_fputs("</TH>\n", PAGER);
      }
!     (void) tee_fputs("  </TR>\n", PAGER);
    }
    while ((cur = mysql_fetch_row(result)))
    {
      if (interrupted_query)
        break;
      ulong *lengths=mysql_fetch_lengths(result);
!     (void) tee_fputs("  <TR>\n", PAGER);
      for (uint i=0; i < mysql_num_fields(result); i++)
      {
!       (void) tee_fputs("    <TD>", PAGER);
        xmlencode_print(cur[i], lengths[i]);
!       (void) tee_fputs("</TD>\n", PAGER);
      }
!     (void) tee_fputs("  </TR>\n", PAGER);
    }
!   (void) tee_fputs("</TABLE>\n", PAGER);
  }
  
kai-voigts-macbook-air:client k$ ./mysql -uroot -proot -e "select * from world.city limit 3" --html
<TABLE BORDER=1>
  <TR>
    <TH>ID</TH>
    <TH>Name</TH>
    <TH>CountryCode</TH>
    <TH>District</TH>
    <TH>Population</TH>
  </TR>
  <TR>
    <TD>1</TD>
    <TD>Kabul</TD>
    <TD>AFG</TD>
    <TD>Kabol</TD>
    <TD>1780000</TD>
  </TR>
  <TR>
    <TD>2</TD>
    <TD>Qandahar</TD>
    <TD>AFG</TD>
    <TD>Qandahar</TD>
    <TD>237500</TD>
  </TR>
  <TR>
    <TD>3</TD>
    <TD>Herat</TD>
    <TD>AFG</TD>
    <TD>Herat</TD>
    <TD>186800</TD>
  </TR>
</TABLE>
kai-voigts-macbook-air:client k$
[21 Jul 2009 13:16] Valeriy Kravchuk
Thank you for the feature request.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.