[MDEV-20721] Implement sql_type() for Field_real and Field_int Created: 2019-10-02  Updated: 2019-10-02  Resolved: 2019-10-02

Status: Closed
Project: MariaDB Server
Component/s: Data types
Fix Version/s: 10.5.0

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed
blocks MDEV-20016 Add MariaDB_DATA_TYPE_PLUGIN Closed

 Description   

This change was suggested by Serg during the review of MDEV-20016.

Let's implement sql_type() in abstract classes as much as possible. It will reduce the amout of the code:

  • in the built-in Field_xxx classes
  • in the future plugin Field_xxx classes

Note, this task is limited to Field_real and Field_int only. Other classes will be changed the same way later.

Let's remove sql_type() implementations from:

  • Field_tiny
  • Field_short
  • Field_medium
  • Field_long
  • Field_longlong
  • Field_float
  • Field_double
    The inherited implementations will work for these classes. The exact data type name will be taken from the Type_handler.

The implementation for the abstract classes will look like:

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);
}

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);
}


Generated at Thu Feb 08 09:01:40 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.