Commit 96b470ae authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

after review fix (BUG#4067)

parent 523dbb3e
...@@ -5812,3 +5812,30 @@ void Field::set_warning(const uint level, const uint code) ...@@ -5812,3 +5812,30 @@ void Field::set_warning(const uint level, const uint code)
code, ER(code), field_name, thd->row_count); 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 @@ public: ...@@ -267,6 +267,8 @@ public:
void set_warning(const unsigned int level, const unsigned int code); void set_warning(const unsigned int level, const unsigned int code);
virtual field_cast_enum field_cast_type()= 0; virtual field_cast_enum field_cast_type()= 0;
bool field_cast_compatible(field_cast_enum type); 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 bool reopen_table(THD *,struct st_table *,bool);
friend int cre_myisam(my_string name, register TABLE *form, uint options, friend int cre_myisam(my_string name, register TABLE *form, uint options,
ulonglong auto_increment_value); ulonglong auto_increment_value);
...@@ -336,6 +338,7 @@ public: ...@@ -336,6 +338,7 @@ public:
CHARSET_INFO *charset(void) const { return field_charset; } CHARSET_INFO *charset(void) const { return field_charset; }
void set_charset(CHARSET_INFO *charset) { field_charset=charset; } void set_charset(CHARSET_INFO *charset) { field_charset=charset; }
bool binary() const { return field_charset->state & MY_CS_BINSORT ? 1 : 0; } bool binary() const { return field_charset->state & MY_CS_BINSORT ? 1 : 0; }
uint32 max_length() { return field_length; }
friend class create_field; friend class create_field;
}; };
...@@ -366,6 +369,7 @@ public: ...@@ -366,6 +369,7 @@ public:
void overflow(bool negative); void overflow(bool negative);
bool zero_pack() const { return 0; } bool zero_pack() const { return 0; }
void sql_type(String &str) const; void sql_type(String &str) const;
uint32 max_length() { return field_length; }
field_cast_enum field_cast_type() { return FIELD_CAST_DECIMAL; } field_cast_enum field_cast_type() { return FIELD_CAST_DECIMAL; }
}; };
...@@ -397,6 +401,7 @@ public: ...@@ -397,6 +401,7 @@ public:
void sort_string(char *buff,uint length); void sort_string(char *buff,uint length);
uint32 pack_length() const { return 1; } uint32 pack_length() const { return 1; }
void sql_type(String &str) const; void sql_type(String &str) const;
uint32 max_length() { return 4; }
field_cast_enum field_cast_type() { return FIELD_CAST_TINY; } field_cast_enum field_cast_type() { return FIELD_CAST_TINY; }
}; };
...@@ -433,6 +438,7 @@ public: ...@@ -433,6 +438,7 @@ public:
void sort_string(char *buff,uint length); void sort_string(char *buff,uint length);
uint32 pack_length() const { return 2; } uint32 pack_length() const { return 2; }
void sql_type(String &str) const; void sql_type(String &str) const;
uint32 max_length() { return 6; }
field_cast_enum field_cast_type() { return FIELD_CAST_SHORT; } field_cast_enum field_cast_type() { return FIELD_CAST_SHORT; }
}; };
...@@ -464,6 +470,7 @@ public: ...@@ -464,6 +470,7 @@ public:
void sort_string(char *buff,uint length); void sort_string(char *buff,uint length);
uint32 pack_length() const { return 3; } uint32 pack_length() const { return 3; }
void sql_type(String &str) const; void sql_type(String &str) const;
uint32 max_length() { return 8; }
field_cast_enum field_cast_type() { return FIELD_CAST_MEDIUM; } field_cast_enum field_cast_type() { return FIELD_CAST_MEDIUM; }
}; };
...@@ -500,6 +507,7 @@ public: ...@@ -500,6 +507,7 @@ public:
void sort_string(char *buff,uint length); void sort_string(char *buff,uint length);
uint32 pack_length() const { return 4; } uint32 pack_length() const { return 4; }
void sql_type(String &str) const; void sql_type(String &str) const;
uint32 max_length() { return 11; }
field_cast_enum field_cast_type() { return FIELD_CAST_LONG; } field_cast_enum field_cast_type() { return FIELD_CAST_LONG; }
}; };
...@@ -539,6 +547,7 @@ public: ...@@ -539,6 +547,7 @@ public:
uint32 pack_length() const { return 8; } uint32 pack_length() const { return 8; }
void sql_type(String &str) const; void sql_type(String &str) const;
bool store_for_compare() { return 1; } bool store_for_compare() { return 1; }
uint32 max_length() { return 20; }
field_cast_enum field_cast_type() { return FIELD_CAST_LONGLONG; } field_cast_enum field_cast_type() { return FIELD_CAST_LONGLONG; }
}; };
#endif #endif
...@@ -573,6 +582,7 @@ public: ...@@ -573,6 +582,7 @@ public:
void sort_string(char *buff,uint length); void sort_string(char *buff,uint length);
uint32 pack_length() const { return sizeof(float); } uint32 pack_length() const { return sizeof(float); }
void sql_type(String &str) const; void sql_type(String &str) const;
uint32 max_length() { return 24; }
field_cast_enum field_cast_type() { return FIELD_CAST_FLOAT; } field_cast_enum field_cast_type() { return FIELD_CAST_FLOAT; }
}; };
...@@ -607,6 +617,7 @@ public: ...@@ -607,6 +617,7 @@ public:
void sort_string(char *buff,uint length); void sort_string(char *buff,uint length);
uint32 pack_length() const { return sizeof(double); } uint32 pack_length() const { return sizeof(double); }
void sql_type(String &str) const; void sql_type(String &str) const;
uint32 max_length() { return 53; }
field_cast_enum field_cast_type() { return FIELD_CAST_DOUBLE; } field_cast_enum field_cast_type() { return FIELD_CAST_DOUBLE; }
}; };
...@@ -637,6 +648,7 @@ public: ...@@ -637,6 +648,7 @@ public:
uint32 pack_length() const { return 0; } uint32 pack_length() const { return 0; }
void sql_type(String &str) const; void sql_type(String &str) const;
uint size_of() const { return sizeof(*this); } uint size_of() const { return sizeof(*this); }
uint32 max_length() { return 4; }
field_cast_enum field_cast_type() { return FIELD_CAST_NULL; } field_cast_enum field_cast_type() { return FIELD_CAST_NULL; }
}; };
...@@ -1034,6 +1046,7 @@ public: ...@@ -1034,6 +1046,7 @@ public:
bool has_charset(void) const bool has_charset(void) const
{ return charset() == &my_charset_bin ? FALSE : TRUE; } { return charset() == &my_charset_bin ? FALSE : TRUE; }
field_cast_enum field_cast_type() { return FIELD_CAST_BLOB; } field_cast_enum field_cast_type() { return FIELD_CAST_BLOB; }
uint32 max_length();
}; };
#ifdef HAVE_SPATIAL #ifdef HAVE_SPATIAL
...@@ -1062,6 +1075,7 @@ public: ...@@ -1062,6 +1075,7 @@ public:
void get_key_image(char *buff,uint length, CHARSET_INFO *cs,imagetype type); void get_key_image(char *buff,uint length, CHARSET_INFO *cs,imagetype type);
void set_key_image(char *buff,uint length, CHARSET_INFO *cs); 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; } field_cast_enum field_cast_type() { return FIELD_CAST_GEOM; }
}; };
#endif /*HAVE_SPATIAL*/ #endif /*HAVE_SPATIAL*/
......
...@@ -2514,53 +2514,9 @@ bool Item_type_holder::join_types(THD *thd, Item *item) ...@@ -2514,53 +2514,9 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
uint32 Item_type_holder::real_length(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) if (item->type() == Item::FIELD_ITEM)
{ {
switch (((Item_field *)item)->field_type()) return ((Item_field *)item)->max_disp_length();
{
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;
}
} }
switch (item->result_type()) switch (item->result_type())
{ {
......
...@@ -382,6 +382,7 @@ public: ...@@ -382,6 +382,7 @@ public:
bool is_null() { return field->is_null(); } bool is_null() { return field->is_null(); }
Item *get_tmp_table_item(THD *thd); Item *get_tmp_table_item(THD *thd);
void cleanup(); void cleanup();
inline uint32 max_disp_length() { return field->max_length(); }
friend class Item_default_value; friend class Item_default_value;
friend class Item_insert_value; friend class Item_insert_value;
friend class st_select_lex_unit; 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