mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Bug#16859 involves truncating column data at NUL characters. Instead, the
client will now substitute spaces for NULs, so that the grid isn't messed up due to silently consumed NULs and that the full field is shown. client/mysql.cc: For non-numbers, print each character at a time, instead of using the fprintf() facility, which interprets an array of chars as a C string, which is necessarily NUL terminated. We mustn't terminate on NULs, and since we know the length of the data, we needn't. mysql-test/r/mysql.result: Add a test. mysql-test/t/mysql.test: Add a test.
This commit is contained in:
@@ -185,6 +185,7 @@ void tee_fprintf(FILE *file, const char *fmt, ...);
|
||||
void tee_fputs(const char *s, FILE *file);
|
||||
void tee_puts(const char *s, FILE *file);
|
||||
void tee_putc(int c, FILE *file);
|
||||
static void tee_print_sized_data(const char *data, unsigned int length, unsigned int width);
|
||||
/* The names of functions that actually do the manipulation. */
|
||||
static int get_options(int argc,char **argv);
|
||||
static int com_quit(String *str,char*),
|
||||
@@ -2308,20 +2309,29 @@ print_table_data(MYSQL_RES *result)
|
||||
for (uint off= 0; off < mysql_num_fields(result); off++)
|
||||
{
|
||||
const char *str= cur[off] ? cur[off] : "NULL";
|
||||
uint currlength;
|
||||
uint maxlength;
|
||||
uint numcells;
|
||||
|
||||
field= mysql_fetch_field(result);
|
||||
uint maxlength= field->max_length;
|
||||
maxlength= field->max_length;
|
||||
currlength= (uint) lengths[off];
|
||||
numcells= charset_info->cset->numcells(charset_info,
|
||||
str, str + currlength);
|
||||
if (maxlength > MAX_COLUMN_LENGTH)
|
||||
{
|
||||
tee_fputs(str, PAGER);
|
||||
tee_fputs(" |", PAGER);
|
||||
tee_print_sized_data(str, currlength, maxlength);
|
||||
tee_fputs(" |", PAGER);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint currlength= (uint) lengths[off];
|
||||
uint numcells= charset_info->cset->numcells(charset_info,
|
||||
str, str + currlength);
|
||||
tee_fprintf(PAGER, num_flag[off] ? "%*s |" : " %-*s|",
|
||||
maxlength + currlength - numcells, str);
|
||||
if (num_flag[off] != 0)
|
||||
tee_fprintf(PAGER, " %-*s|", maxlength + currlength - numcells, str);
|
||||
else
|
||||
{
|
||||
tee_print_sized_data(str, currlength, maxlength);
|
||||
tee_fputs(" |", PAGER);
|
||||
}
|
||||
}
|
||||
}
|
||||
(void) tee_fputs("\n", PAGER);
|
||||
@@ -2331,6 +2341,35 @@ print_table_data(MYSQL_RES *result)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
tee_print_sized_data(const char *data, unsigned int length, unsigned int width)
|
||||
{
|
||||
/*
|
||||
It is not a number, so print each character justified to the left.
|
||||
For '\0's print ASCII spaces instead, as '\0' is eaten by (at
|
||||
least my) console driver, and that messes up the pretty table
|
||||
grid. (The \0 is also the reason we can't use fprintf() .)
|
||||
*/
|
||||
unsigned int i;
|
||||
const char *p;
|
||||
|
||||
tee_putc(' ', PAGER);
|
||||
|
||||
for (i= 0, p= data; i < length; i+= 1, p+= 1)
|
||||
{
|
||||
if (*p == '\0')
|
||||
tee_putc((int)' ', PAGER);
|
||||
else
|
||||
tee_putc((int)*p, PAGER);
|
||||
}
|
||||
|
||||
i+= 1;
|
||||
for ( ; i < width; i+= 1)
|
||||
tee_putc((int)' ', PAGER);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
print_table_data_html(MYSQL_RES *result)
|
||||
{
|
||||
|
Reference in New Issue
Block a user