summaryrefslogtreecommitdiff
path: root/client/mysql.cc
diff options
context:
space:
mode:
authorunknown <bar@mysql.com>2006-04-17 12:33:45 +0500
committerunknown <bar@mysql.com>2006-04-17 12:33:45 +0500
commitca9c47936cfdf19e9169a482523efca320e5f28e (patch)
treed7404ee97578dbda56d82bbdcfd2f0127deada5f /client/mysql.cc
parent6ef02da5d0c16954aaefed05a514f1a26d73ef26 (diff)
downloadmariadb-git-ca9c47936cfdf19e9169a482523efca320e5f28e.tar.gz
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: Adding column name allignment, the same to data alignment, which was implemented earlier.
Diffstat (limited to 'client/mysql.cc')
-rw-r--r--client/mysql.cc9
1 files changed, 7 insertions, 2 deletions
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);