Skip to content
Permalink
Browse files
MDEV-19125 Change Send_field::type from enum_field_types to Type_hand…
…ler*
  • Loading branch information
abarkov committed Apr 2, 2019
1 parent e10f9e6 commit 4d12a64
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 95 deletions.
@@ -1073,7 +1073,7 @@ bool Protocol_text::store_field_metadata(const THD * thd,
client_field->length= server_field.max_octet_length(charset_for_protocol,
thd_cs);
}
client_field->type= server_field.type;
client_field->type= server_field.type_handler()->type_code_for_protocol();
client_field->flags= (uint16) server_field.flags;
client_field->decimals= server_field.decimals;

@@ -1968,7 +1968,7 @@ void Field::make_send_field(Send_field *field)
}
field->col_name= field_name;
field->length=field_length;
field->type=type();
field->set_handler(type_handler());
field->flags=table->maybe_null ? (flags & ~NOT_NULL_FLAG) : flags;
field->decimals= 0;
}
@@ -8743,6 +8743,20 @@ uint Field_blob::is_equal(Create_field *new_field)
}


void Field_blob::make_send_field(Send_field *field)
{
/*
Historically all BLOB variant Fields are displayed as MYSQL_TYPE_BLOB
in the result set metadata. Note, Item can work differently and
display the exact BLOB type, such as
MYSQL_TYPE_{TINY_BLOB|BLOB|MEDIUM_BLOB|LONG_BLOB}.
QQ: this should be made consistent eventually.
*/
Field_longstr::make_send_field(field);
field->set_handler(&type_handler_blob);
}


int Field_blob_compressed::store(const char *from, size_t length,
CHARSET_INFO *cs)
{
@@ -10915,6 +10929,13 @@ bool Column_definition::set_compressed(const char *method)
}


Send_field::Send_field(THD *thd, Item *item)
{
item->make_send_field(thd, this);
normalize();
}


/**
maximum possible display length for blob.

@@ -3861,6 +3861,7 @@ class Field_blob :public Field_longstr {
uint32 chars= octets / field_charset->mbminlen;
return Information_schema_character_attributes(octets, chars);
}
void make_send_field(Send_field *);
Copy_func *get_copy_func(const Field *from) const
{
/*
@@ -4115,6 +4116,10 @@ class Field_geom :public Field_blob {
{
return Information_schema_character_attributes();
}
void make_send_field(Send_field *to)
{
Field_longstr::make_send_field(to);
}
bool can_optimize_range(const Item_bool_func *cond,
const Item *item,
bool is_eq_func) const;
@@ -4994,60 +4999,54 @@ class Create_field :public Column_definition
A class for sending info to the client
*/

class Send_field :public Sql_alloc {
public:
class Send_field :public Sql_alloc,
public Type_handler_hybrid_field_type
{
public:
const char *db_name;
const char *table_name,*org_table_name;
LEX_CSTRING col_name, org_col_name;
ulong length;
uint flags, decimals;
enum_field_types type;
Send_field() {}
Send_field(Field *field)
{
field->make_send_field(this);
DBUG_ASSERT(table_name != 0);
normalize();
}

Send_field(THD *thd, Item *item);
Send_field(Field *field,
const char *db_name_arg,
const char *table_name_arg)
:db_name(db_name_arg),
:Type_handler_hybrid_field_type(field->type_handler()),
db_name(db_name_arg),
table_name(table_name_arg),
org_table_name(table_name_arg),
col_name(field->field_name),
org_col_name(field->field_name),
length(field->field_length),
flags(field->table->maybe_null ?
(field->flags & ~NOT_NULL_FLAG) : field->flags),
decimals(field->decimals()),
type(field->type())
decimals(field->decimals())
{
normalize();
}

// This should move to Type_handler eventually
static enum_field_types protocol_type_code(enum_field_types type)
{
/* Keep things compatible for old clients */
if (type == MYSQL_TYPE_VARCHAR)
return MYSQL_TYPE_VAR_STRING;
return type;
}
private:
void normalize()
{
/* limit number of decimals for float and double */
if (type == MYSQL_TYPE_FLOAT || type == MYSQL_TYPE_DOUBLE)
if (type_handler()->field_type() == MYSQL_TYPE_FLOAT ||
type_handler()->field_type() == MYSQL_TYPE_DOUBLE)
set_if_smaller(decimals, FLOATING_POINT_DECIMALS);
/* Keep things compatible for old clients */
type= protocol_type_code(type);
}

public:
// This should move to Type_handler eventually
uint32 max_char_length(CHARSET_INFO *cs) const
{
return type >= MYSQL_TYPE_TINY_BLOB && type <= MYSQL_TYPE_BLOB ?
return type_handler()->field_type() >= MYSQL_TYPE_TINY_BLOB &&
type_handler()->field_type() <= MYSQL_TYPE_BLOB ?
length / cs->mbminlen :
length / cs->mbmaxlen;
}
@@ -5077,8 +5076,8 @@ class Send_field :public Sql_alloc {
bool is_sane() const
{
return (decimals <= FLOATING_POINT_DECIMALS ||
(type != MYSQL_TYPE_FLOAT && type != MYSQL_TYPE_DOUBLE)) &&
type != MYSQL_TYPE_VARCHAR;
(type_handler()->field_type() != MYSQL_TYPE_FLOAT &&
type_handler()->field_type() != MYSQL_TYPE_DOUBLE));
}
};

@@ -4696,7 +4696,7 @@ void
Item_param::set_out_param_info(Send_field *info)
{
m_out_param_info= info;
set_handler_by_field_type(m_out_param_info->type);
set_handler(m_out_param_info->type_handler());
}


@@ -4737,16 +4737,7 @@ void Item_param::make_send_field(THD *thd, Send_field *field)
OUT-parameter info to fill out the names.
*/

field->db_name= m_out_param_info->db_name;
field->table_name= m_out_param_info->table_name;
field->org_table_name= m_out_param_info->org_table_name;
field->col_name= m_out_param_info->col_name;
field->org_col_name= m_out_param_info->org_col_name;

field->length= m_out_param_info->length;
field->flags= m_out_param_info->flags;
field->decimals= m_out_param_info->decimals;
field->type= m_out_param_info->type;
*field= *m_out_param_info;
}

bool Item_param::append_for_log(THD *thd, String *str)
@@ -6124,7 +6115,7 @@ Item *Item_field::replace_equal_field(THD *thd, uchar *arg)


void Item::init_make_send_field(Send_field *tmp_field,
enum enum_field_types field_type_arg)
const Type_handler *h)
{
tmp_field->db_name= "";
tmp_field->org_table_name= "";
@@ -6134,7 +6125,7 @@ void Item::init_make_send_field(Send_field *tmp_field,
tmp_field->flags= (maybe_null ? 0 : NOT_NULL_FLAG) |
(my_binary_compare(charset_for_protocol()) ?
BINARY_FLAG : 0);
tmp_field->type= field_type_arg;
tmp_field->set_handler(h);
tmp_field->length=max_length;
tmp_field->decimals=decimals;
if (unsigned_flag)
@@ -6143,13 +6134,13 @@ void Item::init_make_send_field(Send_field *tmp_field,

void Item::make_send_field(THD *thd, Send_field *tmp_field)
{
init_make_send_field(tmp_field, field_type());
init_make_send_field(tmp_field, type_handler());
}


void Item_empty_string::make_send_field(THD *thd, Send_field *tmp_field)
{
init_make_send_field(tmp_field, string_type_handler()->field_type());
init_make_send_field(tmp_field, string_type_handler());
}


@@ -946,7 +946,7 @@ class Item: public Value_source,
void set_name(THD *thd, const char *str, size_t length, CHARSET_INFO *cs);
void set_name_no_truncate(THD *thd, const char *str, uint length,
CHARSET_INFO *cs);
void init_make_send_field(Send_field *tmp_field,enum enum_field_types type);
void init_make_send_field(Send_field *tmp_field, const Type_handler *h);
virtual void cleanup();
virtual void make_send_field(THD *thd, Send_field *field);

@@ -59,10 +59,6 @@ class Item_proc :public Item
virtual void set(longlong nr)=0;
const Type_handler *type_handler() const=0;
void set(const char *str) { set(str,(uint) strlen(str), default_charset()); }
void make_send_field(THD *thd, Send_field *tmp_field)
{
init_make_send_field(tmp_field,field_type());
}
unsigned int size_of() { return sizeof(*this);}
bool check_vcol_func_processor(void *arg)
{

0 comments on commit 4d12a64

Please sign in to comment.