Commit 00c3a288 authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: data type plugins

simplify type naming (less boilerplate code).
don't force a plugin to specify the name twice.
parent 77997821
......@@ -36,7 +36,7 @@
struct st_mariadb_data_type
{
int interface_version;
const class Type_handler *type_handler;
class Type_handler *type_handler;
};
......
......@@ -625,5 +625,5 @@ void thd_wakeup_subsequent_commits(THD* thd, int wakeup_error);
struct st_mariadb_data_type
{
int interface_version;
const class Type_handler *type_handler;
class Type_handler *type_handler;
};
......@@ -176,7 +176,7 @@ maria_declare_plugin(type_inet)
{
MariaDB_DATA_TYPE_PLUGIN, // the plugin type (see include/mysql/plugin.h)
&plugin_descriptor_type_inet6,// pointer to type-specific plugin descriptor
type_handler_inet6.name().ptr(),// plugin name
"inet6", // plugin name
"MariaDB Corporation", // plugin author
"Data type INET6", // the plugin description
PLUGIN_LICENSE_GPL, // the plugin license (see include/mysql/plugin.h)
......
......@@ -318,11 +318,6 @@ class Type_handler_inet6: public Type_handler
public:
~Type_handler_inet6() override {}
const Name name() const override
{
static const Name name(STRING_WITH_LEN("inet6"));
return name;
}
const Type_collection *type_collection() const override;
const Name &default_value() const override
{
......
......@@ -64,11 +64,6 @@ class Field_test_int8 :public Field_longlong
class Type_handler_test_int8: public Type_handler_longlong
{
public:
const Name name() const override
{
static Name name(STRING_WITH_LEN("test_int8"));
return name;
}
const Type_collection *type_collection() const override
{
return &type_collection_test;
......@@ -126,11 +121,6 @@ class Field_test_double :public Field_double
class Type_handler_test_double: public Type_handler_double
{
public:
const Name name() const override
{
static Name name(STRING_WITH_LEN("test_double"));
return name;
}
const Type_collection *type_collection() const override
{
return &type_collection_test;
......@@ -302,7 +292,7 @@ maria_declare_plugin(type_test)
{
MariaDB_DATA_TYPE_PLUGIN, // the plugin type (see include/mysql/plugin.h)
&plugin_descriptor_type_test_int8, // pointer to type-specific plugin descriptor
type_handler_test_int8.name().ptr(), // plugin name
"test_int8", // plugin name
"MariaDB Corporation", // plugin author
"Data type TEST_INT8", // the plugin description
PLUGIN_LICENSE_GPL, // the plugin license (see include/mysql/plugin.h)
......@@ -317,7 +307,7 @@ maria_declare_plugin(type_test)
{
MariaDB_DATA_TYPE_PLUGIN, // the plugin type (see include/mysql/plugin.h)
&plugin_descriptor_type_test_double, // pointer to type-specific plugin descriptor
type_handler_test_double.name().ptr(), // plugin name
"test_double", // plugin name
"MariaDB Corporation", // plugin author
"Data type TEST_DOUBLE", // the plugin description
PLUGIN_LICENSE_GPL, // the plugin license (see include/mysql/plugin.h)
......
......@@ -2421,7 +2421,9 @@ class Field_tiny :public Field_int
{
const Type_handler_general_purpose_int *type_handler_priv() const
{
return is_unsigned() ? &type_handler_utiny : &type_handler_stiny;
if (is_unsigned())
return &type_handler_utiny;
return &type_handler_stiny;
}
public:
Field_tiny(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
......@@ -2476,7 +2478,9 @@ class Field_short :public Field_int
{
const Type_handler_general_purpose_int *type_handler_priv() const
{
return is_unsigned() ? &type_handler_ushort : &type_handler_sshort;
if (is_unsigned())
return &type_handler_ushort;
return &type_handler_sshort;
}
public:
Field_short(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
......@@ -2527,7 +2531,9 @@ class Field_medium :public Field_int
{
const Type_handler_general_purpose_int *type_handler_priv() const
{
return is_unsigned() ? &type_handler_uint24 : &type_handler_sint24;
if (is_unsigned())
return &type_handler_uint24;
return &type_handler_sint24;
}
public:
Field_medium(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
......@@ -2571,7 +2577,9 @@ class Field_long :public Field_int
{
const Type_handler_general_purpose_int *type_handler_priv() const
{
return is_unsigned() ? &type_handler_ulong : &type_handler_slong;
if (is_unsigned())
return &type_handler_ulong;
return &type_handler_slong;
}
public:
Field_long(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
......@@ -2626,7 +2634,9 @@ class Field_longlong :public Field_int
{
const Type_handler_general_purpose_int *type_handler_priv() const
{
return is_unsigned() ? &type_handler_ulonglong : &type_handler_slonglong;
if (is_unsigned())
return &type_handler_ulonglong;
return &type_handler_slonglong;
}
public:
Field_longlong(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
......
......@@ -5423,8 +5423,10 @@ bool Item_func_get_user_var::fix_length_and_dec()
collation.set(&my_charset_numeric, DERIVATION_NUMERIC);
fix_char_length(MAX_BIGINT_WIDTH);
decimals=0;
set_handler(unsigned_flag ? &type_handler_ulonglong :
&type_handler_slonglong);
if (unsigned_flag)
set_handler(&type_handler_ulonglong);
else
set_handler(&type_handler_slonglong);
break;
case STRING_RESULT:
collation.set(m_var_entry->charset(), DERIVATION_IMPLICIT);
......
......@@ -2523,8 +2523,9 @@ class Item_func_udf_int :public Item_udf_func
String *val_str(String *str);
const Type_handler *type_handler() const
{
return unsigned_flag ? &type_handler_ulonglong :
&type_handler_slonglong;
if (unsigned_flag)
return &type_handler_ulonglong;
return &type_handler_slonglong;
}
bool fix_length_and_dec() { decimals= 0; max_length= 21; return FALSE; }
Item *get_copy(THD *thd)
......
......@@ -1649,8 +1649,9 @@ class Item_sum_udf_int :public Item_udf_sum
my_decimal *val_decimal(my_decimal *);
const Type_handler *type_handler() const
{
return unsigned_flag ? &type_handler_ulonglong :
&type_handler_slonglong;
if (unsigned_flag)
return &type_handler_ulonglong;
return &type_handler_slonglong;
}
bool fix_length_and_dec() { decimals=0; max_length=21; return FALSE; }
Item *copy_or_same(THD* thd);
......
......@@ -109,8 +109,9 @@ class Item_proc_int :public Item_proc
{ max_length=11; }
const Type_handler *type_handler() const
{
return unsigned_flag ? &type_handler_ulonglong :
&type_handler_slonglong;
if (unsigned_flag)
return &type_handler_ulonglong;
return &type_handler_slonglong;
}
void set(double nr) { value=(longlong) nr; }
void set(longlong nr) { value=nr; }
......
......@@ -106,6 +106,8 @@ extern int finalize_audit_plugin(st_plugin_int *plugin);
extern int initialize_encryption_plugin(st_plugin_int *plugin);
extern int finalize_encryption_plugin(st_plugin_int *plugin);
extern int initialize_data_type_plugin(st_plugin_int *plugin);
/*
The number of elements in both plugin_type_initialize and
plugin_type_deinitialize should equal to the number of plugins
......@@ -114,8 +116,8 @@ extern int finalize_encryption_plugin(st_plugin_int *plugin);
plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{
0, ha_initialize_handlerton, 0, 0,initialize_schema_table,
initialize_audit_plugin, 0, 0, 0, initialize_encryption_plugin, 0,
0 // FUNCTION
initialize_audit_plugin, 0, 0, 0, initialize_encryption_plugin,
initialize_data_type_plugin, 0
};
plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
......
This diff is collapsed.
This diff is collapsed.
......@@ -23,68 +23,17 @@
#include "sql_type_geom.h"
#include "item_geofunc.h"
const Name Type_handler_geometry::name() const
{
static const Name tmp(STRING_WITH_LEN("geometry"));
return tmp;
}
const Name Type_handler_point::name() const
{
static const Name tmp(STRING_WITH_LEN("point"));
return tmp;
}
const Name Type_handler_linestring::name() const
{
static const Name tmp(STRING_WITH_LEN("linestring"));
return tmp;
}
const Name Type_handler_polygon::name() const
{
static const Name tmp(STRING_WITH_LEN("polygon"));
return tmp;
}
const Name Type_handler_multipoint::name() const
{
static const Name tmp(STRING_WITH_LEN("multipoint"));
return tmp;
}
const Name Type_handler_multilinestring::name() const
{
static const Name tmp(STRING_WITH_LEN("multilinestring"));
return tmp;
}
const Name Type_handler_multipolygon::name() const
{
static const Name tmp(STRING_WITH_LEN("multipolygon"));
return tmp;
}
const Name Type_handler_geometrycollection::name() const
{
static const Name tmp(STRING_WITH_LEN("geometrycollection"));
return tmp;
}
Type_handler_geometry type_handler_geometry;
Type_handler_point type_handler_point;
Type_handler_linestring type_handler_linestring;
Type_handler_polygon type_handler_polygon;
Type_handler_multipoint type_handler_multipoint;
Type_handler_multilinestring type_handler_multilinestring;
Type_handler_multipolygon type_handler_multipolygon;
Type_handler_geometrycollection type_handler_geometrycollection;
Named_type_handler<Type_handler_geometry> type_handler_geometry("geometry");
Named_type_handler<Type_handler_point> type_handler_point("point");
Named_type_handler<Type_handler_linestring> type_handler_linestring("linestring");
Named_type_handler<Type_handler_polygon> type_handler_polygon("polygon");
Named_type_handler<Type_handler_multipoint> type_handler_multipoint("multipoint");
Named_type_handler<Type_handler_multilinestring> type_handler_multilinestring("multilinestring");
Named_type_handler<Type_handler_multipolygon> type_handler_multipolygon("multipolygon");
Named_type_handler<Type_handler_geometrycollection> type_handler_geometrycollection("geometrycollection");
Type_collection_geometry type_collection_geometry;
const Type_handler_geometry *
Type_handler_geometry::type_handler_geom_by_type(uint type)
{
......
......@@ -41,7 +41,6 @@ class Type_handler_geometry: public Type_handler_string_result
static const Type_handler_geometry *type_handler_geom_by_type(uint type);
public:
virtual ~Type_handler_geometry() {}
const Name name() const override;
enum_field_types field_type() const override { return MYSQL_TYPE_GEOMETRY; }
bool is_param_long_data_type() const override { return true; }
uint32 max_display_length_for_field(const Conv_source &src) const override;
......@@ -181,7 +180,6 @@ class Type_handler_point: public Type_handler_geometry
static uint octet_length() { return 25; }
public:
geometry_types geometry_type() const override { return GEOM_POINT; }
const Name name() const override;
Item *make_constructor_item(THD *thd, List<Item> *args) const override;
bool Key_part_spec_init_primary(Key_part_spec *part,
const Column_definition &def,
......@@ -203,7 +201,6 @@ class Type_handler_linestring: public Type_handler_geometry
{
public:
geometry_types geometry_type() const override { return GEOM_LINESTRING; }
const Name name() const override;
Item *make_constructor_item(THD *thd, List<Item> *args) const override;
};
......@@ -212,7 +209,6 @@ class Type_handler_polygon: public Type_handler_geometry
{
public:
geometry_types geometry_type() const override { return GEOM_POLYGON; }
const Name name() const override;
Item *make_constructor_item(THD *thd, List<Item> *args) const override;
};
......@@ -221,7 +217,6 @@ class Type_handler_multipoint: public Type_handler_geometry
{
public:
geometry_types geometry_type() const override { return GEOM_MULTIPOINT; }
const Name name() const override;
Item *make_constructor_item(THD *thd, List<Item> *args) const override;
};
......@@ -230,7 +225,6 @@ class Type_handler_multilinestring: public Type_handler_geometry
{
public:
geometry_types geometry_type() const override { return GEOM_MULTILINESTRING; }
const Name name() const override;
Item *make_constructor_item(THD *thd, List<Item> *args) const override;
};
......@@ -239,7 +233,6 @@ class Type_handler_multipolygon: public Type_handler_geometry
{
public:
geometry_types geometry_type() const override { return GEOM_MULTIPOLYGON; }
const Name name() const override;
Item *make_constructor_item(THD *thd, List<Item> *args) const override;
};
......@@ -248,20 +241,17 @@ class Type_handler_geometrycollection: public Type_handler_geometry
{
public:
geometry_types geometry_type() const override { return GEOM_GEOMETRYCOLLECTION; }
const Name name() const override;
Item *make_constructor_item(THD *thd, List<Item> *args) const override;
};
extern MYSQL_PLUGIN_IMPORT Type_handler_geometry type_handler_geometry;
extern MYSQL_PLUGIN_IMPORT Type_handler_point type_handler_point;
extern MYSQL_PLUGIN_IMPORT Type_handler_linestring type_handler_linestring;
extern MYSQL_PLUGIN_IMPORT Type_handler_polygon type_handler_polygon;
extern MYSQL_PLUGIN_IMPORT Type_handler_multipoint type_handler_multipoint;
extern MYSQL_PLUGIN_IMPORT Type_handler_multilinestring type_handler_multilinestring;
extern MYSQL_PLUGIN_IMPORT Type_handler_multipolygon type_handler_multipolygon;
extern MYSQL_PLUGIN_IMPORT Type_handler_geometrycollection type_handler_geometrycollection;
extern Named_type_handler<Type_handler_geometry> type_handler_geometry;
extern Named_type_handler<Type_handler_point> type_handler_point;
extern Named_type_handler<Type_handler_linestring> type_handler_linestring;
extern Named_type_handler<Type_handler_polygon> type_handler_polygon;
extern Named_type_handler<Type_handler_multipoint> type_handler_multipoint;
extern Named_type_handler<Type_handler_multilinestring> type_handler_multilinestring;
extern Named_type_handler<Type_handler_multipolygon> type_handler_multipolygon;
extern Named_type_handler<Type_handler_geometrycollection> type_handler_geometrycollection;
class Type_collection_geometry: public Type_collection
{
......@@ -314,9 +304,7 @@ class Type_collection_geometry: public Type_collection
}
};
extern MYSQL_PLUGIN_IMPORT Type_collection_geometry type_collection_geometry;
extern Type_collection_geometry type_collection_geometry;
#include "field.h"
......
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