From aa8ab68fea734374521aacf696fe970a7f8334ac Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Mon, 17 Apr 2006 12:33:45 +0500 Subject: Bug#17939: Wrong table format when using UTF8 strings Lines with column names consisting of national letters were wrongly formatted in "mysql --table" results: mysql> SELECT 'xxx xxx xxx' as 'xxx xxx xxx'; +-------------------+ | xxx xxx xxx | +-------------------+ | xxx xxx xxx | +-------------------+ 1 row in set (0.00 sec) It happened because in UTF-8 (and other multibyte charsets) the number of display cells is not always equal to the number of bytes of the string. Data lines (unlike column name lines) were formatted correctly, because data lines were displayed taking in account number of display cells. This patch takes in account number of cells when displaying column names, the same way like displaying data lines does. Note: The patch is going to be applied to 4.1. Test case will be added after merge to 5.0, into "mysql.test", which appeared in 5.0. mysql.cc: Adding column name allignment using numcells(), the same to data alignment, which was implemented earlier. --- client/mysql.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'client/mysql.cc') diff --git a/client/mysql.cc b/client/mysql.cc index 2f9031b84b8..22fe6e81b25 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -2145,9 +2145,14 @@ print_table_data(MYSQL_RES *result) (void) tee_fputs("|", PAGER); for (uint off=0; (field = mysql_fetch_field(result)) ; off++) { - tee_fprintf(PAGER, " %-*s|",(int) min(field->max_length, + uint name_length= (uint) strlen(field->name); + uint numcells= charset_info->cset->numcells(charset_info, + field->name, + field->name + name_length); + uint display_length= field->max_length + name_length - numcells; + tee_fprintf(PAGER, " %-*s|",(int) min(display_length, MAX_COLUMN_LENGTH), - field->name); + field->name); num_flag[off]= IS_NUM(field->type); } (void) tee_fputs("\n", PAGER); -- cgit v1.2.1