Commit 1e2bde0d authored by unknown's avatar unknown

Only expand the empty string to the letters "NULL" if the column

does not have "NOT NULL" attribute set.  Also, calculate the padding
characters more safely, so that a negative number doesn't cause it to 
print MAXINT-n spaces.


mysql-test/r/mysql.result:
  Add test result.
mysql-test/t/mysql.test:
  Add test.
parent be4548d4
......@@ -2268,8 +2268,10 @@ print_table_data(MYSQL_RES *result)
MYSQL_ROW cur;
MYSQL_FIELD *field;
bool *num_flag;
bool *not_null_flag;
num_flag=(bool*) my_alloca(sizeof(bool)*mysql_num_fields(result));
not_null_flag=(bool*) my_alloca(sizeof(bool)*mysql_num_fields(result));
if (info_flag)
{
print_field_types(result);
......@@ -2287,7 +2289,7 @@ print_table_data(MYSQL_RES *result)
length=max(length,field->max_length);
if (length < 4 && !IS_NOT_NULL(field->flags))
length=4; // Room for "NULL"
field->max_length=length+1;
field->max_length=length;
separator.fill(separator.length()+length+2,'-');
separator.append('+');
}
......@@ -2299,10 +2301,11 @@ 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,
tee_fprintf(PAGER, " %-*s |",(int) min(field->max_length,
MAX_COLUMN_LENGTH),
field->name);
num_flag[off]= IS_NUM(field->type);
not_null_flag[off]= IS_NOT_NULL(field->flags);
}
(void) tee_fputs("\n", PAGER);
tee_puts((char*) separator.ptr(), PAGER);
......@@ -2322,7 +2325,8 @@ print_table_data(MYSQL_RES *result)
uint visible_length;
uint extra_padding;
if (lengths[off] == 0)
/* If this column may have a null value, use "NULL" for empty. */
if (! not_null_flag[off] && (lengths[off] == 0))
{
buffer= "NULL";
data_length= 4;
......@@ -2362,6 +2366,7 @@ print_table_data(MYSQL_RES *result)
}
tee_puts((char*) separator.ptr(), PAGER);
my_afree((gptr) num_flag);
my_afree((gptr) not_null_flag);
}
......@@ -2376,11 +2381,8 @@ tee_print_sized_data(const char *data, unsigned int data_length, unsigned int to
unsigned int i;
const char *p;
total_bytes_to_send -= 1;
/* Off by one, perhaps mistakenly accounting for a terminating NUL. */
if (right_justified)
for (i= 0; i < (total_bytes_to_send - data_length); i++)
for (i= data_length; i < total_bytes_to_send; i++)
tee_putc((int)' ', PAGER);
for (i= 0, p= data; i < data_length; i+= 1, p+= 1)
......@@ -2392,7 +2394,7 @@ tee_print_sized_data(const char *data, unsigned int data_length, unsigned int to
}
if (! right_justified)
for (i= 0; i < (total_bytes_to_send - data_length); i++)
for (i= data_length; i < total_bytes_to_send; i++)
tee_putc((int)' ', PAGER);
}
......
......@@ -85,3 +85,15 @@ c_cp932
| NULL | NULL | Τη γλώσσα |
| NULL | NULL | ᛖᚴ ᚷᛖᛏ |
+------+------+---------------------------+
+------+---+------+
| i | j | k |
+------+---+------+
| NULL | 1 | NULL |
+------+---+------+
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| i | int(11) | YES | | NULL | |
| j | int(11) | NO | | NULL | |
| k | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
......@@ -67,3 +67,8 @@ drop table t1;
#
--exec $MYSQL -t --default-character-set utf8 test -e "create table t1 (i int, j int, k char(25) charset utf8); insert into t1 (i) values (1); insert into t1 (k) values ('<----------------------->'); insert into t1 (k) values ('<-----'); insert into t1 (k) values ('Τη γλώσσα'); insert into t1 (k) values ('ᛖᚴ ᚷᛖᛏ'); select * from t1; DROP TABLE t1;"
#
# "DESCRIBE" commands may return strange NULLness flags.
#
--exec $MYSQL -t --default-character-set utf8 test -e "create table t1 (i int, j int not null, k int); insert into t1 values (null, 1, null); select * from t1; describe t1; drop table t1;"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment