Commit 8703b22e authored by unknown's avatar unknown
Browse files

Fix for bug#13934 Silent truncation of table comments

Table comment: issue a warning(error in traditional mode) if length of comment > 60 symbols
Column comment: issue a warning(error in traditional mode) if length of comment > 255 symbols
Table 'comment' is changed from char* to LEX_STRING


mysql-test/r/strict.result:
  test case
mysql-test/t/strict.test:
  test case
sql/handler.h:
  Table 'comment' is changed from char* to LEX_STRING
sql/sql_show.cc:
  Table 'comment' is changed from char* to LEX_STRING
sql/sql_table.cc:
  Table 'comment' is changed from char* to LEX_STRING
sql/sql_yacc.yy:
  Table 'comment' is changed from char* to LEX_STRING
sql/table.cc:
  Table 'comment' is changed from char* to LEX_STRING
sql/table.h:
  Table 'comment' is changed from char* to LEX_STRING
sql/unireg.cc:
  Fix for bug#13934 Silent truncation of table comments
  Table comment: issue a warning(error in traditional mode) if length of comment > 60 symbols
  Column comment: issue a warning(error in traditional mode) if length of comment > 255 symbols
parent a7f9f7ae
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -1298,3 +1298,49 @@ t2 CREATE TABLE `t2` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t2,t1;
set @@sql_mode= @org_mode;
set @@sql_mode='traditional';
create table t1 (i int)
comment '123456789*123456789*123456789*123456789*123456789*
         123456789*123456789*123456789*123456789*123456789*';
ERROR HY000: Too long comment for table 't1'
create table t1 (
i int comment
'123456789*123456789*123456789*123456789*
 123456789*123456789*123456789*123456789*
 123456789*123456789*123456789*123456789*
 123456789*123456789*123456789*123456789*
 123456789*123456789*123456789*123456789*
 123456789*123456789*123456789*123456789*
 123456789*123456789*123456789*123456789*');
ERROR HY000: Too long comment for field 'i'
set @@sql_mode= @org_mode;
create table t1
(i int comment
'123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*');
Warnings:
Warning	1105	Unknown error
select column_name, column_comment from information_schema.columns where
table_schema = 'test' and table_name = 't1';
column_name	column_comment
i	123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
drop table t1;
set names utf8;
create table t1 (i int)
comment '123456789*123456789*123456789*123456789*123456789*123456789*';
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `i` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='123456789*123456789*123456789*123456789*123456789*123456789*'
drop table t1;
+39 −0
Original line number Diff line number Diff line
@@ -1155,3 +1155,42 @@ create table t2 select date from t1;
show create table t2;
drop table t2,t1;
set @@sql_mode= @org_mode;

#
# Bug #13934 Silent truncation of table comments
#
set @@sql_mode='traditional';
--error 1105
create table t1 (i int)
comment '123456789*123456789*123456789*123456789*123456789*
         123456789*123456789*123456789*123456789*123456789*';
--error 1105
create table t1 (
i int comment
'123456789*123456789*123456789*123456789*
 123456789*123456789*123456789*123456789*
 123456789*123456789*123456789*123456789*
 123456789*123456789*123456789*123456789*
 123456789*123456789*123456789*123456789*
 123456789*123456789*123456789*123456789*
 123456789*123456789*123456789*123456789*');
set @@sql_mode= @org_mode;
create table t1
(i int comment
 '123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*
  123456789*123456789*123456789*123456789*');

select column_name, column_comment from information_schema.columns where
table_schema = 'test' and table_name = 't1';
drop table t1;

set names utf8;
create table t1 (i int)
comment '123456789*123456789*123456789*123456789*123456789*123456789*';
show create table t1;
drop table t1;
+2 −1
Original line number Diff line number Diff line
@@ -428,7 +428,8 @@ typedef struct st_ha_create_information
{
  CHARSET_INFO *table_charset, *default_table_charset;
  LEX_STRING connect_string;
  const char *comment,*password;
  LEX_STRING comment;
  const char *password;
  const char *data_file_name, *index_file_name;
  const char *alias;
  ulonglong max_rows,min_rows;
+8 −5
Original line number Diff line number Diff line
@@ -1080,10 +1080,10 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet)
      packet->append(ha_row_type[(uint) share->row_type]);
    }
    table->file->append_create_info(packet);
    if (share->comment && share->comment[0])
    if (share->comment.length)
    {
      packet->append(STRING_WITH_LEN(" COMMENT="));
      append_unescaped(packet, share->comment, strlen(share->comment));
      append_unescaped(packet, share->comment.str, share->comment.length);
    }
    if (share->connect_string.length)
    {
@@ -2547,11 +2547,14 @@ static int get_schema_tables_record(THD *thd, struct st_table_list *tables,
                             (uint) (ptr-option_buff)-1), cs);
    {
      char *comment;
      comment= show_table->file->update_table_comment(share->comment);
      comment= show_table->file->update_table_comment(share->comment.str);
      if (comment)
      {
        table->field[20]->store(comment, strlen(comment), cs);
        if (comment != share->comment)
        table->field[20]->store(comment,
                                (comment == share->comment.str ?
                                 share->comment.length : 
                                 strlen(comment)), cs);
        if (comment != share->comment.str)
          my_free(comment, MYF(0));
      }
    }
+5 −2
Original line number Diff line number Diff line
@@ -3598,8 +3598,11 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
    goto err;
  }
  create_info->db_type=new_db_type;
  if (!create_info->comment)
    create_info->comment= table->s->comment;
  if (!create_info->comment.str)
  {
    create_info->comment.str= table->s->comment.str;
    create_info->comment.length= table->s->comment.length;
  }

  table->file->update_create_info(create_info);
  if ((create_info->table_options &
Loading