summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2019-10-02 11:11:12 +0400
committerAlexander Barkov <bar@mariadb.com>2019-10-02 11:11:12 +0400
commit5e356ce707610976e3267b8eada509f993ff8833 (patch)
treeae01f4fd3cb599d79611e7432ecb6585285c8161
parent9c031fc218f633f15f7be13c3c780f3a5760f7f0 (diff)
downloadmariadb-git-5e356ce707610976e3267b8eada509f993ff8833.tar.gz
MDEV-20721 Implement sql_type() for Field_real and Field_int
-rw-r--r--sql/field.cc102
-rw-r--r--sql/field.h9
2 files changed, 31 insertions, 80 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 373e8f51e5a..243d281f4d2 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -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
diff --git a/sql/field.h b/sql/field.h
index 775bb4ad596..187649d42f6 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -2136,6 +2136,7 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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
{
/*