Commit 6edb8d5b authored by unknown's avatar unknown

after review fix (BUG#4067)


sql/field.cc:
  method getting maximum display length for fields
sql/field.h:
  method getting maximum display length for fields
sql/item.cc:
  code cleanup
  switch replaced with new method
sql/item.h:
  method getting maximum display length for fields
parent b01f9387
......@@ -5812,3 +5812,30 @@ void Field::set_warning(const uint level, const uint code)
code, ER(code), field_name, thd->row_count);
}
}
/*
maximum possible display length for blob
SYNOPSIS
Field_blob::max_length()
RETURN
length
*/
uint32 Field_blob::max_length()
{
switch (packlength)
{
case 1:
return 255;
case 2:
return 65535;
case 3:
return 16777215;
case 4:
return (uint32)4294967295;
default:
DBUG_ASSERT(0); // we should never go here
return 0;
}
}
......@@ -267,6 +267,8 @@ class Field
void set_warning(const unsigned int level, const unsigned int code);
virtual field_cast_enum field_cast_type()= 0;
bool field_cast_compatible(field_cast_enum type);
/* maximum possible display length */
virtual uint32 max_length()= 0;
friend bool reopen_table(THD *,struct st_table *,bool);
friend int cre_myisam(my_string name, register TABLE *form, uint options,
ulonglong auto_increment_value);
......@@ -336,6 +338,7 @@ class Field_str :public Field {
CHARSET_INFO *charset(void) const { return field_charset; }
void set_charset(CHARSET_INFO *charset) { field_charset=charset; }
bool binary() const { return field_charset->state & MY_CS_BINSORT ? 1 : 0; }
uint32 max_length() { return field_length; }
friend class create_field;
};
......@@ -366,6 +369,7 @@ class Field_decimal :public Field_num {
void overflow(bool negative);
bool zero_pack() const { return 0; }
void sql_type(String &str) const;
uint32 max_length() { return field_length; }
field_cast_enum field_cast_type() { return FIELD_CAST_DECIMAL; }
};
......@@ -397,6 +401,7 @@ class Field_tiny :public Field_num {
void sort_string(char *buff,uint length);
uint32 pack_length() const { return 1; }
void sql_type(String &str) const;
uint32 max_length() { return 4; }
field_cast_enum field_cast_type() { return FIELD_CAST_TINY; }
};
......@@ -433,6 +438,7 @@ class Field_short :public Field_num {
void sort_string(char *buff,uint length);
uint32 pack_length() const { return 2; }
void sql_type(String &str) const;
uint32 max_length() { return 6; }
field_cast_enum field_cast_type() { return FIELD_CAST_SHORT; }
};
......@@ -464,6 +470,7 @@ class Field_medium :public Field_num {
void sort_string(char *buff,uint length);
uint32 pack_length() const { return 3; }
void sql_type(String &str) const;
uint32 max_length() { return 8; }
field_cast_enum field_cast_type() { return FIELD_CAST_MEDIUM; }
};
......@@ -500,6 +507,7 @@ class Field_long :public Field_num {
void sort_string(char *buff,uint length);
uint32 pack_length() const { return 4; }
void sql_type(String &str) const;
uint32 max_length() { return 11; }
field_cast_enum field_cast_type() { return FIELD_CAST_LONG; }
};
......@@ -539,6 +547,7 @@ class Field_longlong :public Field_num {
uint32 pack_length() const { return 8; }
void sql_type(String &str) const;
bool store_for_compare() { return 1; }
uint32 max_length() { return 20; }
field_cast_enum field_cast_type() { return FIELD_CAST_LONGLONG; }
};
#endif
......@@ -573,6 +582,7 @@ class Field_float :public Field_num {
void sort_string(char *buff,uint length);
uint32 pack_length() const { return sizeof(float); }
void sql_type(String &str) const;
uint32 max_length() { return 24; }
field_cast_enum field_cast_type() { return FIELD_CAST_FLOAT; }
};
......@@ -607,6 +617,7 @@ class Field_double :public Field_num {
void sort_string(char *buff,uint length);
uint32 pack_length() const { return sizeof(double); }
void sql_type(String &str) const;
uint32 max_length() { return 53; }
field_cast_enum field_cast_type() { return FIELD_CAST_DOUBLE; }
};
......@@ -637,6 +648,7 @@ class Field_null :public Field_str {
uint32 pack_length() const { return 0; }
void sql_type(String &str) const;
uint size_of() const { return sizeof(*this); }
uint32 max_length() { return 4; }
field_cast_enum field_cast_type() { return FIELD_CAST_NULL; }
};
......@@ -1034,6 +1046,7 @@ class Field_blob :public Field_str {
bool has_charset(void) const
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
field_cast_enum field_cast_type() { return FIELD_CAST_BLOB; }
uint32 max_length();
};
#ifdef HAVE_SPATIAL
......@@ -1062,6 +1075,7 @@ class Field_geom :public Field_blob {
void get_key_image(char *buff,uint length, CHARSET_INFO *cs,imagetype type);
void set_key_image(char *buff,uint length, CHARSET_INFO *cs);
uint32 max_length() { return field_length; }
field_cast_enum field_cast_type() { return FIELD_CAST_GEOM; }
};
#endif /*HAVE_SPATIAL*/
......
......@@ -2514,53 +2514,9 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
uint32 Item_type_holder::real_length(Item *item)
{
if (item->result_type() == STRING_RESULT)
return item->max_length;
if (item->type() == Item::FIELD_ITEM)
{
switch (((Item_field *)item)->field_type())
{
case MYSQL_TYPE_TINY:
return 4;
case MYSQL_TYPE_SHORT:
return 6;
case MYSQL_TYPE_LONG:
return 11;
case MYSQL_TYPE_FLOAT:
return 24;
case MYSQL_TYPE_DOUBLE:
return 53;
case MYSQL_TYPE_NULL:
return 4;
case MYSQL_TYPE_LONGLONG:
return 20;
case MYSQL_TYPE_INT24:
return 8;
case MYSQL_TYPE_TINY_BLOB:
return 256;
case MYSQL_TYPE_MEDIUM_BLOB:
return 65535;
case MYSQL_TYPE_LONG_BLOB:
return (uint32)4294967295;
case MYSQL_TYPE_BLOB:
return 16777215;
case MYSQL_TYPE_SET:
case MYSQL_TYPE_ENUM:
case MYSQL_TYPE_NEWDATE:
case MYSQL_TYPE_YEAR:
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_TIME:
case MYSQL_TYPE_DATE:
case MYSQL_TYPE_TIMESTAMP:
case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_VAR_STRING:
case MYSQL_TYPE_STRING:
case MYSQL_TYPE_GEOMETRY:
return item->max_length;
default:
DBUG_ASSERT(0); // we should never go there
return 0;
}
return ((Item_field *)item)->max_disp_length();
}
switch (item->result_type())
{
......
......@@ -382,6 +382,7 @@ class Item_field :public Item_ident
bool is_null() { return field->is_null(); }
Item *get_tmp_table_item(THD *thd);
void cleanup();
inline uint32 max_disp_length() { return field->max_length(); }
friend class Item_default_value;
friend class Item_insert_value;
friend class st_select_lex_unit;
......
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