[MDEV-19125] Change Send_field::type from enum_field_types to Type_handler* Created: 2019-04-01  Updated: 2019-04-02  Resolved: 2019-04-02

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

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

 Description   

protocol.cc has various tests for MYSQL_TYPE_XXX, for example:

bool Protocol_text::store(const char *from, size_t length,
                          CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
{
#ifndef DBUG_OFF
  DBUG_ASSERT(field_types == 0 ||
	      field_types[field_pos] == MYSQL_TYPE_DECIMAL ||
              field_types[field_pos] == MYSQL_TYPE_BIT ||
              field_types[field_pos] == MYSQL_TYPE_NEWDECIMAL ||
	      (field_types[field_pos] >= MYSQL_TYPE_ENUM &&
	       field_types[field_pos] <= MYSQL_TYPE_GEOMETRY));
  field_pos++;
#endif
  return store_string_aux(from, length, fromcs, tocs);
}

This is not friendly to new/pluggable data types.

To fix this problem, we'll do the following changes:

  • change Send_field::type from enum_field_type to const Type_handler *
  • add a new enum:

    enum protocol_send_type_t
    {
      PROTOCOL_SEND_STRING,
      PROTOCOL_SEND_FLOAT,
      PROTOCOL_SEND_DOUBLE,
      PROTOCOL_SEND_TINY,
      PROTOCOL_SEND_SHORT,
      PROTOCOL_SEND_LONG,
      PROTOCOL_SEND_LONGLONG,
      PROTOCOL_SEND_DATETIME,
      PROTOCOL_SEND_DATE,
      PROTOCOL_SEND_TIME
    };
    

  • add a new virtual method in Type_handler:

    virtual protocol_send_type_t protocol_send_type() const= 0;
    

So the ::store() method implementations will simplify to something like:

bool Protocol_text::store(const char *from, size_t length,
                          CHARSET_INFO *fromcs, CHARSET_INFO *tocs)
{
#ifndef DBUG_OFF
  DBUG_ASSERT(valid_handler(field_pos, PROTOCOL_SEND_STRING));
  field_pos++;
#endif
  return store_string_aux(from, length, fromcs, tocs);
}

New data types will just need to implement a proper virtual implementation of Type_handler_xxx::protocol_send_type().


Generated at Thu Feb 08 08:49:14 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.