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

A patch for MDEV-4912 Add a plugin to field types (column types)

Adding Column_definition::make_field() as a convenience
wrapper for ::make_field.
This commit is contained in:
Alexander Barkov
2015-11-27 20:50:19 +04:00
parent 9d5c9379a6
commit e3fed3b9b4
4 changed files with 41 additions and 54 deletions

View File

@@ -3417,6 +3417,16 @@ public:
extern const LEX_STRING null_lex_str; extern const LEX_STRING null_lex_str;
Field *make_field(TABLE_SHARE *share, MEM_ROOT *mem_root,
uchar *ptr, uint32 field_length,
uchar *null_pos, uchar null_bit,
uint pack_flag, enum_field_types field_type,
CHARSET_INFO *cs,
Field::geometry_type geom_type, uint srid,
Field::utype unireg_check,
TYPELIB *interval, const char *field_name);
/* /*
Create field class for CREATE TABLE Create field class for CREATE TABLE
*/ */
@@ -3505,6 +3515,23 @@ public:
unireg_check == Field::TIMESTAMP_UN_FIELD || unireg_check == Field::TIMESTAMP_UN_FIELD ||
unireg_check == Field::NEXT_NUMBER); unireg_check == Field::NEXT_NUMBER);
} }
Field *make_field(TABLE_SHARE *share, MEM_ROOT *mem_root,
uchar *ptr, uchar *null_pos, uchar null_bit,
const char *field_name_arg) const
{
return ::make_field(share, mem_root, ptr,
length, null_pos, null_bit,
pack_flag, sql_type, charset,
geom_type, srid, unireg_check, interval,
field_name_arg);
}
Field *make_field(TABLE_SHARE *share, MEM_ROOT *mem_root,
const char *field_name_arg)
{
return make_field(share, mem_root, (uchar *) 0, (uchar *) "", 0,
field_name_arg);
}
}; };
@@ -3596,14 +3623,6 @@ public:
}; };
Field *make_field(TABLE_SHARE *share, MEM_ROOT *mem_root,
uchar *ptr, uint32 field_length,
uchar *null_pos, uchar null_bit,
uint pack_flag, enum_field_types field_type,
CHARSET_INFO *cs,
Field::geometry_type geom_type, uint srid,
Field::utype unireg_check,
TYPELIB *interval, const char *field_name);
uint pack_length_to_packflag(uint type); uint pack_length_to_packflag(uint type);
enum_field_types get_blob_type_from_length(ulong length); enum_field_types get_blob_type_from_length(ulong length);
uint32 calc_pack_length(enum_field_types type,uint32 length); uint32 calc_pack_length(enum_field_types type,uint32 length);

View File

@@ -863,27 +863,17 @@ Field *
sp_head::create_result_field(uint field_max_length, const char *field_name, sp_head::create_result_field(uint field_max_length, const char *field_name,
TABLE *table) TABLE *table)
{ {
uint field_length;
Field *field; Field *field;
DBUG_ENTER("sp_head::create_result_field"); DBUG_ENTER("sp_head::create_result_field");
field_length= !m_return_field_def.length ? DBUG_ASSERT(field_max_length <= m_return_field_def.length);
field_max_length : m_return_field_def.length;
field= ::make_field(table->s, /* TABLE_SHARE ptr */ field= m_return_field_def.make_field(table->s, /* TABLE_SHARE ptr */
table->in_use->mem_root, table->in_use->mem_root,
(uchar*) 0, /* field ptr */ field_name ?
field_length, /* field [max] length */ field_name :
(uchar*) "", /* null ptr */ (const char *) m_name.str);
0, /* null bit */
m_return_field_def.pack_flag,
m_return_field_def.sql_type,
m_return_field_def.charset,
m_return_field_def.geom_type, m_return_field_def.srid,
Field::NONE, /* unreg check */
m_return_field_def.interval,
field_name ? field_name : (const char *) m_name.str);
field->vcol_info= m_return_field_def.vcol_info; field->vcol_info= m_return_field_def.vcol_info;
if (field) if (field)

View File

@@ -16981,12 +16981,10 @@ TABLE *create_virtual_tmp_table(THD *thd, List<Column_definition> &field_list)
List_iterator_fast<Column_definition> it(field_list); List_iterator_fast<Column_definition> it(field_list);
while ((cdef= it++)) while ((cdef= it++))
{ {
*field= make_field(share, thd->mem_root, 0, cdef->length, *field= cdef->make_field(share, thd->mem_root, 0,
(uchar*) (f_maybe_null(cdef->pack_flag) ? "" : 0), (uchar*) (f_maybe_null(cdef->pack_flag) ? "" : 0),
f_maybe_null(cdef->pack_flag) ? 1 : 0, f_maybe_null(cdef->pack_flag) ? 1 : 0,
cdef->pack_flag, cdef->sql_type, cdef->charset, cdef->field_name);
cdef->geom_type, cdef->srid, cdef->unireg_check,
cdef->interval, cdef->field_name);
if (!*field) if (!*field)
goto error; goto error;
(*field)->init(table); (*field)->init(table);

View File

@@ -5627,7 +5627,6 @@ bool store_schema_params(THD *thd, TABLE *table, TABLE *proc_table,
if (sp) if (sp)
{ {
Field *field; Field *field;
Column_definition *field_def;
String tmp_string; String tmp_string;
if (routine_type == TYPE_ENUM_FUNCTION) if (routine_type == TYPE_ENUM_FUNCTION)
{ {
@@ -5639,14 +5638,7 @@ bool store_schema_params(THD *thd, TABLE *table, TABLE *proc_table,
get_field(thd->mem_root, proc_table->field[MYSQL_PROC_MYSQL_TYPE], get_field(thd->mem_root, proc_table->field[MYSQL_PROC_MYSQL_TYPE],
&tmp_string); &tmp_string);
table->field[15]->store(tmp_string.ptr(), tmp_string.length(), cs); table->field[15]->store(tmp_string.ptr(), tmp_string.length(), cs);
field_def= &sp->m_return_field_def; field= sp->m_return_field_def.make_field(&share, thd->mem_root, "");
field= make_field(&share, thd->mem_root,
(uchar*) 0, field_def->length,
(uchar*) "", 0, field_def->pack_flag,
field_def->sql_type, field_def->charset,
field_def->geom_type, field_def->srid, Field::NONE,
field_def->interval, "");
field->table= &tbl; field->table= &tbl;
tbl.in_use= thd; tbl.in_use= thd;
store_column_type(table, field, cs, 6); store_column_type(table, field, cs, 6);
@@ -5665,7 +5657,6 @@ bool store_schema_params(THD *thd, TABLE *table, TABLE *proc_table,
{ {
const char *tmp_buff; const char *tmp_buff;
sp_variable *spvar= spcont->find_variable(i); sp_variable *spvar= spcont->find_variable(i);
field_def= &spvar->field_def;
switch (spvar->mode) { switch (spvar->mode) {
case sp_variable::MODE_IN: case sp_variable::MODE_IN:
tmp_buff= "IN"; tmp_buff= "IN";
@@ -5694,12 +5685,8 @@ bool store_schema_params(THD *thd, TABLE *table, TABLE *proc_table,
&tmp_string); &tmp_string);
table->field[15]->store(tmp_string.ptr(), tmp_string.length(), cs); table->field[15]->store(tmp_string.ptr(), tmp_string.length(), cs);
field= make_field(&share, thd->mem_root, (uchar*) 0, field_def->length, field= spvar->field_def.make_field(&share, thd->mem_root,
(uchar*) "", 0, field_def->pack_flag, spvar->name.str);
field_def->sql_type, field_def->charset,
field_def->geom_type, field_def->srid, Field::NONE,
field_def->interval, spvar->name.str);
field->table= &tbl; field->table= &tbl;
tbl.in_use= thd; tbl.in_use= thd;
store_column_type(table, field, cs, 6); store_column_type(table, field, cs, 6);
@@ -5786,18 +5773,11 @@ bool store_schema_proc(THD *thd, TABLE *table, TABLE *proc_table,
TABLE_SHARE share; TABLE_SHARE share;
TABLE tbl; TABLE tbl;
Field *field; Field *field;
Column_definition *field_def= &sp->m_return_field_def;
bzero((char*) &tbl, sizeof(TABLE)); bzero((char*) &tbl, sizeof(TABLE));
(void) build_table_filename(path, sizeof(path), "", "", "", 0); (void) build_table_filename(path, sizeof(path), "", "", "", 0);
init_tmp_table_share(thd, &share, "", 0, "", path); init_tmp_table_share(thd, &share, "", 0, "", path);
field= make_field(&share, thd->mem_root, (uchar*) 0, field= sp->m_return_field_def.make_field(&share, thd->mem_root, "");
field_def->length,
(uchar*) "", 0, field_def->pack_flag,
field_def->sql_type, field_def->charset,
field_def->geom_type, field_def->srid, Field::NONE,
field_def->interval, "");
field->table= &tbl; field->table= &tbl;
tbl.in_use= thd; tbl.in_use= thd;
store_column_type(table, field, cs, 5); store_column_type(table, field, cs, 5);