Commit 5e356ce7 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-20721 Implement sql_type() for Field_real and Field_int

parent 9c031fc2
......@@ -3637,6 +3637,17 @@ int Field_int::store_time_dec(const MYSQL_TIME *ltime, uint dec_arg)
}
void Field_int::sql_type(String &res) const
{
CHARSET_INFO *cs=res.charset();
Name name= type_handler()->type_handler_signed()->name();
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"%.*s(%d)", (int) name.length(), name.ptr(),
(int) field_length));
add_zerofill_and_unsigned(res);
}
/****************************************************************************
** tiny int
****************************************************************************/
......@@ -3789,14 +3800,6 @@ void Field_tiny::sort_string(uchar *to,uint length __attribute__((unused)))
to[0] = (char) (ptr[0] ^ (uchar) 128); /* Revers signbit */
}
void Field_tiny::sql_type(String &res) const
{
CHARSET_INFO *cs=res.charset();
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"tinyint(%d)",(int) field_length));
add_zerofill_and_unsigned(res);
}
/****************************************************************************
Field type short int (2 byte)
****************************************************************************/
......@@ -3962,15 +3965,6 @@ void Field_short::sort_string(uchar *to,uint length __attribute__((unused)))
to[1] = ptr[0];
}
void Field_short::sql_type(String &res) const
{
CHARSET_INFO *cs=res.charset();
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"smallint(%d)",(int) field_length));
add_zerofill_and_unsigned(res);
}
/****************************************************************************
Field type medium int (3 byte)
****************************************************************************/
......@@ -4161,14 +4155,6 @@ void Field_medium::sort_string(uchar *to,uint length __attribute__((unused)))
}
void Field_medium::sql_type(String &res) const
{
CHARSET_INFO *cs=res.charset();
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"mediumint(%d)",(int) field_length));
add_zerofill_and_unsigned(res);
}
/****************************************************************************
** long int
****************************************************************************/
......@@ -4334,14 +4320,6 @@ void Field_long::sort_string(uchar *to,uint length __attribute__((unused)))
}
void Field_long::sql_type(String &res) const
{
CHARSET_INFO *cs=res.charset();
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"int(%d)",(int) field_length));
add_zerofill_and_unsigned(res);
}
/****************************************************************************
Field type longlong int (8 bytes)
****************************************************************************/
......@@ -4485,14 +4463,6 @@ void Field_longlong::sort_string(uchar *to,uint length __attribute__((unused)))
}
void Field_longlong::sql_type(String &res) const
{
CHARSET_INFO *cs=res.charset();
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"bigint(%d)",(int) field_length));
add_zerofill_and_unsigned(res);
}
void Field_longlong::set_max()
{
DBUG_ASSERT(marked_for_write_or_computed());
......@@ -4663,22 +4633,6 @@ Binlog_type_info Field_float::binlog_type_info() const
}
void Field_float::sql_type(String &res) const
{
if (dec >= FLOATING_POINT_DECIMALS)
{
res.set_ascii(STRING_WITH_LEN("float"));
}
else
{
CHARSET_INFO *cs= res.charset();
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"float(%d,%d)",(int) field_length,dec));
}
add_zerofill_and_unsigned(res);
}
/****************************************************************************
double precision floating point numbers
****************************************************************************/
......@@ -4900,6 +4854,24 @@ Item *Field_real::get_equal_const_item(THD *thd, const Context &ctx,
}
void Field_real::sql_type(String &res) const
{
const Name name= type_handler()->name();
if (dec >= FLOATING_POINT_DECIMALS)
{
res.set_ascii(name.ptr(), name.length());
}
else
{
CHARSET_INFO *cs= res.charset();
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"%.*s(%d,%d)", (int) name.length(), name.ptr(),
(int) field_length,dec));
}
add_zerofill_and_unsigned(res);
}
String *Field_double::val_str(String *val_buffer,
String *val_ptr __attribute__((unused)))
{
......@@ -4975,22 +4947,6 @@ Binlog_type_info Field_double::binlog_type_info() const
}
void Field_double::sql_type(String &res) const
{
CHARSET_INFO *cs=res.charset();
if (dec >= FLOATING_POINT_DECIMALS)
{
res.set_ascii(STRING_WITH_LEN("double"));
}
else
{
res.length(cs->cset->snprintf(cs,(char*) res.ptr(),res.alloced_length(),
"double(%d,%d)",(int) field_length,dec));
}
add_zerofill_and_unsigned(res);
}
/**
TIMESTAMP type holds datetime values in range from 1970-01-01 00:00:01 UTC to
2038-01-01 00:00:00 UTC stored as number of seconds since Unix
......
......@@ -2136,6 +2136,7 @@ class Field_real :public Field_num {
Information_schema_numeric_attributes(field_length) :
Information_schema_numeric_attributes(field_length, dec);
}
void sql_type(String &str) const override;
int save_in_field(Field *to) override { return to->store(val_real()); }
bool memcpy_field_possible(const Field *from) const override
{
......@@ -2372,6 +2373,7 @@ class Field_int :public Field_num
uint32 prec= type_limits_int()->precision();
return Information_schema_numeric_attributes(prec, 0);
}
void sql_type(String &str) const override;
SEL_ARG *get_mm_leaf(RANGE_OPT_PARAM *param, KEY_PART *key_part,
const Item_bool_func *cond,
scalar_comparison_op op, Item *value) override
......@@ -2410,7 +2412,6 @@ class Field_tiny :public Field_int
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 1; }
void sql_type(String &str) const override;
const Type_limits_int *type_limits_int() const override
{
return type_handler_priv()->type_limits_int();
......@@ -2472,7 +2473,6 @@ class Field_short :public Field_int
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 2; }
void sql_type(String &str) const override;
const Type_limits_int *type_limits_int() const override
{
return type_handler_priv()->type_limits_int();
......@@ -2518,7 +2518,6 @@ class Field_medium :public Field_int
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 3; }
void sql_type(String &str) const override;
const Type_limits_int *type_limits_int() const override
{
return type_handler_priv()->type_limits_int();
......@@ -2569,7 +2568,6 @@ class Field_long :public Field_int
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 4; }
void sql_type(String &str) const override;
const Type_limits_int *type_limits_int() const override
{
return type_handler_priv()->type_limits_int();
......@@ -2629,7 +2627,6 @@ class Field_longlong :public Field_int
int cmp(const uchar *,const uchar *) const override;
void sort_string(uchar *buff,uint length) override;
uint32 pack_length() const override { return 8; }
void sql_type(String &str) const override;
const Type_limits_int *type_limits_int() const override
{
return type_handler_priv()->type_limits_int();
......@@ -2731,7 +2728,6 @@ class Field_float :public Field_real {
void sort_string(uchar *buff, uint length) override;
uint32 pack_length() const override { return sizeof(float); }
uint row_pack_length() const override { return pack_length(); }
void sql_type(String &str) const override;
ulonglong get_max_int_value() const override
{
/*
......@@ -2796,7 +2792,6 @@ class Field_double :public Field_real {
void sort_string(uchar *buff, uint length) override;
uint32 pack_length() const override { return sizeof(double); }
uint row_pack_length() const override { return pack_length(); }
void sql_type(String &str) const override;
ulonglong get_max_int_value() const override
{
/*
......
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