1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-29 00:08:14 +03:00

cleanup: data type plugins

simplify type naming (less boilerplate code).
don't force a plugin to specify the name twice.
This commit is contained in:
Sergei Golubchik
2019-10-11 14:12:38 +02:00
parent 779978217c
commit 00c3a28820
15 changed files with 181 additions and 450 deletions

View File

@@ -3111,6 +3111,11 @@ public:
LEX_CSTRING::str= str_arg;
LEX_CSTRING::length= length_arg;
}
Name(const LEX_CSTRING &lcs)
{
LEX_CSTRING::str= lcs.str;
LEX_CSTRING::length= lcs.length;
}
const char *ptr() const { return LEX_CSTRING::str; }
uint length() const { return (uint) LEX_CSTRING::length; }
const LEX_CSTRING &lex_cstring() const { return *this; }
@@ -3291,7 +3296,7 @@ public:
const Column_definition *row_start,
const Column_definition *row_end) const;
};
extern MYSQL_PLUGIN_IMPORT Vers_type_timestamp vers_type_timestamp;
extern Vers_type_timestamp vers_type_timestamp;
class Vers_type_trx: public Vers_type_handler
@@ -3305,11 +3310,12 @@ public:
const Column_definition *row_start,
const Column_definition *row_end) const;
};
extern MYSQL_PLUGIN_IMPORT Vers_type_trx vers_type_trx;
extern Vers_type_trx vers_type_trx;
class Type_handler
{
Name m_name;
protected:
const Name version_mysql56() const;
const Name version_mariadb53() const;
@@ -3320,10 +3326,8 @@ protected:
bool maybe_null, bool null_value,
bool unsigned_flag,
longlong value) const;
bool
Item_func_or_sum_illegal_param(const char *name) const;
bool
Item_func_or_sum_illegal_param(const Item_func_or_sum *) const;
bool Item_func_or_sum_illegal_param(const char *name) const;
bool Item_func_or_sum_illegal_param(const Item_func_or_sum *) const;
bool check_null(const Item *item, st_value *value) const;
bool Item_send_str(Item *item, Protocol *protocol, st_value *buf) const;
bool Item_send_tiny(Item *item, Protocol *protocol, st_value *buf) const;
@@ -3377,7 +3381,9 @@ public:
static void partition_field_type_not_allowed(const LEX_CSTRING &field_name);
static bool partition_field_check_result_type(Item *item,
Item_result expected_type);
virtual const Name name() const= 0;
void set_name(Name n) { DBUG_ASSERT(!m_name.ptr()); m_name= n; }
const Name name() const { return m_name; }
virtual const Name version() const;
virtual const Name &default_value() const= 0;
virtual uint32 flags() const { return 0; }
@@ -3536,6 +3542,7 @@ public:
{
return false;
}
Type_handler() : m_name(0,0) {}
virtual ~Type_handler() {}
/**
Determines MariaDB traditional scalar data types that always present
@@ -4020,7 +4027,6 @@ class Type_handler_row: public Type_handler
{
public:
virtual ~Type_handler_row() {}
const Name name() const override;
const Name &default_value() const override;
bool validate_implicit_default_value(THD *thd,
const Column_definition &def) const
@@ -5179,7 +5185,6 @@ class Type_handler_tiny: public Type_handler_general_purpose_int
{
public:
virtual ~Type_handler_tiny() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_TINY; }
const Type_handler *type_handler_unsigned() const override;
const Type_handler *type_handler_signed() const override;
@@ -5223,7 +5228,6 @@ public:
class Type_handler_utiny: public Type_handler_tiny
{
public:
const Name name() const override;
uint flags() const override { return UNSIGNED_FLAG; }
const Type_limits_int *type_limits_int() const override;
};
@@ -5233,7 +5237,6 @@ class Type_handler_short: public Type_handler_general_purpose_int
{
public:
virtual ~Type_handler_short() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_SHORT; }
const Type_handler *type_handler_unsigned() const override;
const Type_handler *type_handler_signed() const override;
@@ -5277,7 +5280,6 @@ public:
class Type_handler_ushort: public Type_handler_short
{
public:
const Name name() const override;
uint flags() const override { return UNSIGNED_FLAG; }
const Type_limits_int *type_limits_int() const override;
};
@@ -5287,7 +5289,6 @@ class Type_handler_long: public Type_handler_general_purpose_int
{
public:
virtual ~Type_handler_long() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_LONG; }
const Type_handler *type_handler_unsigned() const override;
const Type_handler *type_handler_signed() const override;
@@ -5331,7 +5332,6 @@ public:
class Type_handler_ulong: public Type_handler_long
{
public:
const Name name() const override;
uint flags() const override { return UNSIGNED_FLAG; }
const Type_limits_int *type_limits_int() const override;
};
@@ -5340,7 +5340,6 @@ public:
class Type_handler_bool: public Type_handler_long
{
public:
const Name name() const override;
bool is_bool_type() const override { return true; }
const Type_handler *type_handler_unsigned() const override;
const Type_handler *type_handler_signed() const override;
@@ -5353,7 +5352,6 @@ class Type_handler_longlong: public Type_handler_general_purpose_int
{
public:
virtual ~Type_handler_longlong() {}
const Name name() const override;
enum_field_types field_type() const override{ return MYSQL_TYPE_LONGLONG; }
const Type_handler *type_handler_unsigned() const override;
const Type_handler *type_handler_signed() const override;
@@ -5401,7 +5399,6 @@ public:
class Type_handler_ulonglong: public Type_handler_longlong
{
public:
const Name name() const override;
uint flags() const override { return UNSIGNED_FLAG; }
const Type_limits_int *type_limits_int() const override;
};
@@ -5423,7 +5420,6 @@ class Type_handler_int24: public Type_handler_general_purpose_int
{
public:
virtual ~Type_handler_int24() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_INT24; }
const Type_handler *type_handler_unsigned() const override;
const Type_handler *type_handler_signed() const override;
@@ -5460,7 +5456,6 @@ public:
class Type_handler_uint24: public Type_handler_int24
{
public:
const Name name() const override;
uint flags() const override { return UNSIGNED_FLAG; }
const Type_limits_int *type_limits_int() const override;
};
@@ -5470,7 +5465,6 @@ class Type_handler_year: public Type_handler_int_result
{
public:
virtual ~Type_handler_year() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_YEAR; }
uint flags() const override { return UNSIGNED_FLAG; }
protocol_send_type_t protocol_send_type() const override
@@ -5521,7 +5515,6 @@ class Type_handler_bit: public Type_handler_int_result
{
public:
virtual ~Type_handler_bit() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_BIT; }
uint flags() const override { return UNSIGNED_FLAG; }
protocol_send_type_t protocol_send_type() const override
@@ -5581,7 +5574,6 @@ class Type_handler_float: public Type_handler_real_result
{
public:
virtual ~Type_handler_float() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_FLOAT; }
protocol_send_type_t protocol_send_type() const override
{
@@ -5635,7 +5627,6 @@ class Type_handler_double: public Type_handler_real_result
{
public:
virtual ~Type_handler_double() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_DOUBLE; }
protocol_send_type_t protocol_send_type() const override
{
@@ -5690,7 +5681,6 @@ class Type_handler_time_common: public Type_handler_temporal_result
{
public:
virtual ~Type_handler_time_common() { }
const Name name() const override;
const Name &default_value() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_TIME; }
enum_dynamic_column_type dyncol_type(const Type_all_attributes *attr)
@@ -5894,7 +5884,6 @@ class Type_handler_date_common: public Type_handler_temporal_with_date
{
public:
virtual ~Type_handler_date_common() {}
const Name name() const override;
const Name &default_value() const override;
const Type_handler *type_handler_for_comparison() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_DATE; }
@@ -6020,7 +6009,6 @@ class Type_handler_datetime_common: public Type_handler_temporal_with_date
{
public:
virtual ~Type_handler_datetime_common() {}
const Name name() const override;
const Name &default_value() const override;
const Type_handler *type_handler_for_comparison() const override;
enum_field_types field_type() const override
@@ -6170,7 +6158,6 @@ protected:
bool TIME_to_native(THD *, const MYSQL_TIME *from, Native *to, uint dec) const;
public:
virtual ~Type_handler_timestamp_common() {}
const Name name() const override;
const Name &default_value() const override;
const Type_handler *type_handler_for_comparison() const override;
const Type_handler *type_handler_for_native_format() const override;
@@ -6333,7 +6320,6 @@ class Type_handler_olddecimal: public Type_handler_decimal_result
{
public:
virtual ~Type_handler_olddecimal() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_DECIMAL; }
uint32 max_display_length_for_field(const Conv_source &src) const override;
uint32 calc_pack_length(uint32 length) const override { return length; }
@@ -6368,7 +6354,6 @@ class Type_handler_newdecimal: public Type_handler_decimal_result
{
public:
virtual ~Type_handler_newdecimal() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_NEWDECIMAL; }
uint32 max_display_length_for_field(const Conv_source &src) const override;
uint32 calc_pack_length(uint32 length) const override;
@@ -6411,7 +6396,6 @@ class Type_handler_null: public Type_handler_general_purpose_string
{
public:
virtual ~Type_handler_null() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_NULL; }
enum_dynamic_column_type dyncol_type(const Type_all_attributes *attr)
const override
@@ -6481,7 +6465,6 @@ class Type_handler_string: public Type_handler_longstr
{
public:
virtual ~Type_handler_string() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_STRING; }
ulong KEY_pack_flags(uint column_nr) const override
{
@@ -6536,7 +6519,6 @@ class Type_handler_var_string: public Type_handler_string
{
public:
virtual ~Type_handler_var_string() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_VAR_STRING; }
enum_field_types real_field_type() const override { return MYSQL_TYPE_STRING; }
enum_field_types traditional_merge_field_type() const override
@@ -6567,7 +6549,6 @@ class Type_handler_varchar: public Type_handler_longstr
{
public:
virtual ~Type_handler_varchar() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_VARCHAR; }
ulong KEY_pack_flags(uint column_nr) const override
{
@@ -6640,7 +6621,6 @@ class Type_handler_hex_hybrid: public Type_handler_varchar
{
public:
virtual ~Type_handler_hex_hybrid() {}
const Name name() const override;
const Type_handler *cast_to_int_type_handler() const override;
};
@@ -6761,7 +6741,6 @@ class Type_handler_tiny_blob: public Type_handler_blob_common
public:
virtual ~Type_handler_tiny_blob() {}
uint length_bytes() const override { return 1; }
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_TINY_BLOB; }
uint32 max_display_length_for_field(const Conv_source &src) const override;
uint32 calc_pack_length(uint32 length) const override;
@@ -6779,7 +6758,6 @@ class Type_handler_medium_blob: public Type_handler_blob_common
public:
virtual ~Type_handler_medium_blob() {}
uint length_bytes() const override { return 3; }
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_MEDIUM_BLOB; }
uint32 max_display_length_for_field(const Conv_source &src) const override;
uint32 calc_pack_length(uint32 length) const override;
@@ -6797,7 +6775,6 @@ class Type_handler_long_blob: public Type_handler_blob_common
public:
virtual ~Type_handler_long_blob() {}
uint length_bytes() const override { return 4; }
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_LONG_BLOB; }
uint32 max_display_length_for_field(const Conv_source &src) const override;
uint32 calc_pack_length(uint32 length) const override;
@@ -6817,7 +6794,6 @@ class Type_handler_blob: public Type_handler_blob_common
public:
virtual ~Type_handler_blob() {}
uint length_bytes() const override { return 2; }
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_BLOB; }
uint32 max_display_length_for_field(const Conv_source &src) const override;
uint32 calc_pack_length(uint32 length) const override;
@@ -6896,7 +6872,6 @@ class Type_handler_enum: public Type_handler_typelib
{
public:
virtual ~Type_handler_enum() {}
const Name name() const override;
enum_field_types real_field_type() const override { return MYSQL_TYPE_ENUM; }
enum_field_types traditional_merge_field_type() const override
{
@@ -6939,7 +6914,6 @@ class Type_handler_set: public Type_handler_typelib
{
public:
virtual ~Type_handler_set() {}
const Name name() const override;
enum_field_types real_field_type() const override { return MYSQL_TYPE_SET; }
enum_field_types traditional_merge_field_type() const override
{
@@ -7083,62 +7057,71 @@ public:
const Type_handler *h0, const Type_handler *h1);
};
/*
Helper template to simplify creating builtin types with names.
Plugin types inherit from Type_handler_xxx types that do not set the name in
the constructor, as sql_plugin.cc sets the type name from the plugin name.
*/
template <typename TypeHandler>
class Named_type_handler : public TypeHandler
{
public:
Named_type_handler(const char *n) : TypeHandler()
{ Type_handler::set_name(Name(n, strlen(n))); }
};
extern MYSQL_PLUGIN_IMPORT Type_handler_row type_handler_row;
extern MYSQL_PLUGIN_IMPORT Type_handler_null type_handler_null;
extern Named_type_handler<Type_handler_row> type_handler_row;
extern Named_type_handler<Type_handler_null> type_handler_null;
extern MYSQL_PLUGIN_IMPORT Type_handler_float type_handler_float;
extern MYSQL_PLUGIN_IMPORT Type_handler_double type_handler_double;
extern Named_type_handler<Type_handler_float> type_handler_float;
extern Named_type_handler<Type_handler_double> type_handler_double;
extern MYSQL_PLUGIN_IMPORT Type_handler_bit type_handler_bit;
extern Named_type_handler<Type_handler_bit> type_handler_bit;
extern MYSQL_PLUGIN_IMPORT Type_handler_enum type_handler_enum;
extern MYSQL_PLUGIN_IMPORT Type_handler_set type_handler_set;
extern Named_type_handler<Type_handler_enum> type_handler_enum;
extern Named_type_handler<Type_handler_set> type_handler_set;
extern MYSQL_PLUGIN_IMPORT Type_handler_string type_handler_string;
extern MYSQL_PLUGIN_IMPORT Type_handler_var_string type_handler_var_string;
extern MYSQL_PLUGIN_IMPORT Type_handler_varchar type_handler_varchar;
extern MYSQL_PLUGIN_IMPORT Type_handler_varchar_compressed
type_handler_varchar_compressed;
extern MYSQL_PLUGIN_IMPORT Type_handler_hex_hybrid type_handler_hex_hybrid;
extern Named_type_handler<Type_handler_string> type_handler_string;
extern Named_type_handler<Type_handler_var_string> type_handler_var_string;
extern Named_type_handler<Type_handler_varchar> type_handler_varchar;
extern Named_type_handler<Type_handler_varchar_compressed> type_handler_varchar_compressed;
extern Named_type_handler<Type_handler_hex_hybrid> type_handler_hex_hybrid;
extern MYSQL_PLUGIN_IMPORT Type_handler_tiny_blob type_handler_tiny_blob;
extern MYSQL_PLUGIN_IMPORT Type_handler_medium_blob type_handler_medium_blob;
extern MYSQL_PLUGIN_IMPORT Type_handler_long_blob type_handler_long_blob;
extern MYSQL_PLUGIN_IMPORT Type_handler_blob type_handler_blob;
extern MYSQL_PLUGIN_IMPORT Type_handler_blob_compressed
type_handler_blob_compressed;
extern Named_type_handler<Type_handler_tiny_blob> type_handler_tiny_blob;
extern Named_type_handler<Type_handler_medium_blob> type_handler_medium_blob;
extern Named_type_handler<Type_handler_long_blob> type_handler_long_blob;
extern Named_type_handler<Type_handler_blob> type_handler_blob;
extern Named_type_handler<Type_handler_blob_compressed> type_handler_blob_compressed;
extern MYSQL_PLUGIN_IMPORT Type_handler_bool type_handler_bool;
extern MYSQL_PLUGIN_IMPORT Type_handler_tiny type_handler_stiny;
extern MYSQL_PLUGIN_IMPORT Type_handler_short type_handler_sshort;
extern MYSQL_PLUGIN_IMPORT Type_handler_int24 type_handler_sint24;
extern MYSQL_PLUGIN_IMPORT Type_handler_long type_handler_slong;
extern MYSQL_PLUGIN_IMPORT Type_handler_longlong type_handler_slonglong;
extern Named_type_handler<Type_handler_bool> type_handler_bool;
extern Named_type_handler<Type_handler_tiny> type_handler_stiny;
extern Named_type_handler<Type_handler_short> type_handler_sshort;
extern Named_type_handler<Type_handler_int24> type_handler_sint24;
extern Named_type_handler<Type_handler_long> type_handler_slong;
extern Named_type_handler<Type_handler_longlong> type_handler_slonglong;
extern MYSQL_PLUGIN_IMPORT Type_handler_utiny type_handler_utiny;
extern MYSQL_PLUGIN_IMPORT Type_handler_ushort type_handler_ushort;
extern MYSQL_PLUGIN_IMPORT Type_handler_uint24 type_handler_uint24;
extern MYSQL_PLUGIN_IMPORT Type_handler_ulong type_handler_ulong;
extern MYSQL_PLUGIN_IMPORT Type_handler_ulonglong type_handler_ulonglong;
extern MYSQL_PLUGIN_IMPORT Type_handler_vers_trx_id type_handler_vers_trx_id;
extern Named_type_handler<Type_handler_utiny> type_handler_utiny;
extern Named_type_handler<Type_handler_ushort> type_handler_ushort;
extern Named_type_handler<Type_handler_uint24> type_handler_uint24;
extern Named_type_handler<Type_handler_ulong> type_handler_ulong;
extern Named_type_handler<Type_handler_ulonglong> type_handler_ulonglong;
extern Named_type_handler<Type_handler_vers_trx_id> type_handler_vers_trx_id;
extern MYSQL_PLUGIN_IMPORT Type_handler_newdecimal type_handler_newdecimal;
extern MYSQL_PLUGIN_IMPORT Type_handler_olddecimal type_handler_olddecimal;
extern Named_type_handler<Type_handler_newdecimal> type_handler_newdecimal;
extern Named_type_handler<Type_handler_olddecimal> type_handler_olddecimal;
extern MYSQL_PLUGIN_IMPORT Type_handler_year type_handler_year;
extern MYSQL_PLUGIN_IMPORT Type_handler_year type_handler_year2;
extern MYSQL_PLUGIN_IMPORT Type_handler_newdate type_handler_newdate;
extern MYSQL_PLUGIN_IMPORT Type_handler_date type_handler_date;
extern MYSQL_PLUGIN_IMPORT Type_handler_time type_handler_time;
extern MYSQL_PLUGIN_IMPORT Type_handler_time2 type_handler_time2;
extern MYSQL_PLUGIN_IMPORT Type_handler_datetime type_handler_datetime;
extern MYSQL_PLUGIN_IMPORT Type_handler_datetime2 type_handler_datetime2;
extern MYSQL_PLUGIN_IMPORT Type_handler_timestamp type_handler_timestamp;
extern MYSQL_PLUGIN_IMPORT Type_handler_timestamp2 type_handler_timestamp2;
extern Named_type_handler<Type_handler_year> type_handler_year;
extern Named_type_handler<Type_handler_year> type_handler_year2;
extern Named_type_handler<Type_handler_newdate> type_handler_newdate;
extern Named_type_handler<Type_handler_date> type_handler_date;
extern Named_type_handler<Type_handler_time> type_handler_time;
extern Named_type_handler<Type_handler_time2> type_handler_time2;
extern Named_type_handler<Type_handler_datetime> type_handler_datetime;
extern Named_type_handler<Type_handler_datetime2> type_handler_datetime2;
extern Named_type_handler<Type_handler_timestamp> type_handler_timestamp;
extern Named_type_handler<Type_handler_timestamp2> type_handler_timestamp2;
extern MYSQL_PLUGIN_IMPORT Type_handler_interval_DDhhmmssff
type_handler_interval_DDhhmmssff;
extern Type_handler_interval_DDhhmmssff type_handler_interval_DDhhmmssff;
class Type_aggregator
{
@@ -7229,7 +7212,6 @@ public:
bool init();
};
extern Type_handler_data *type_handler_data;
#endif /* SQL_TYPE_H_INCLUDED */