Commit 01546ee4 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-11245 Move prepare_create_field and sp_prepare_create_field() as methods to Column_definition

Some upcoming tasks, e.g.:
- MDEV-10577 sql_mode=ORACLE: %TYPE in variable declarations
- MDEV-10914 ROW data type for stored routine variables

will need to reuse the code implemented in prepare_create_field(),
sp_prepare_create_field(), prepare_blob_field().

Before reusing this code, it's a good idea to move these global functions
as methods to Column_definition.

This patch:
- actually moves prepare_create_field(), sp_prepare_create_field(),
  prepare_blob_field() as methods to Column_definition
- makes sp_prepare_create_field() call prepare_create_field() at the end,
  to avoid duplicate code in MDEV-10577 and MDEV-10914.
- changes the return data type for prepare_create_field() from int to bool,
  to make it consistent with all other functions returning "ok" or "error".
- moves the implementation sp_head::fill_field_definition() from sp_head.cc
  to sp_head.h, as it now uses globally visible Column_definition methods,
  and is very simple, so inlining is now possible.
- removes the unused "LEX*" argument from sp_head::fill_field_definition()
parent 8b4f181c
......@@ -3872,6 +3872,13 @@ class Column_definition: public Sql_alloc
set_if_smaller(length, MAX_FIELD_WIDTH - 1);
DBUG_RETURN(false);
}
bool prepare_blob_field(THD *thd);
bool sp_prepare_create_field(THD *thd, MEM_ROOT *mem_root);
bool prepare_create_field(uint *blob_columns, longlong table_flags);
bool check(THD *thd);
bool stored_in_db() const { return !vcol_info || vcol_info->stored_in_db; }
......
......@@ -23,8 +23,6 @@
#include "probes_mysql.h"
#include "sql_show.h" // append_identifier
#include "sql_db.h" // mysql_opt_change_db, mysql_change_db
#include "sql_table.h" // sp_prepare_create_field,
// prepare_create_field
#include "sql_acl.h" // *_ACL
#include "sql_array.h" // Dynamic_array
#include "log_event.h" // Query_log_event
......@@ -2287,40 +2285,6 @@ sp_head::backpatch(sp_label *lab)
DBUG_VOID_RETURN;
}
/**
Prepare an instance of Column_definition for field creation
(fill all necessary attributes).
@param[in] thd Thread handle
@param[in] lex Yacc parsing context
@param[out] field_def An instance of create_field to be filled
@retval
FALSE on success
@retval
TRUE on error
*/
bool
sp_head::fill_field_definition(THD *thd, LEX *lex,
Column_definition *field_def)
{
uint unused1= 0;
if (field_def->check(thd))
return TRUE;
if (sp_prepare_create_field(thd, mem_root, field_def))
return true;
if (prepare_create_field(field_def, &unused1, HA_CAN_GEOMETRY))
{
return TRUE;
}
return FALSE;
}
int
sp_head::new_cont_backpatch(sp_instr_opt_meta *i)
......
......@@ -417,9 +417,23 @@ class sp_head :private Query_arena
Field *create_result_field(uint field_max_length, const char *field_name,
TABLE *table);
bool fill_field_definition(THD *thd, LEX *lex,
Column_definition *field_def);
/**
Check and prepare an instance of Column_definition for field creation
(fill all necessary attributes).
@param[in] thd Thread handle
@param[in] lex Yacc parsing context
@param[out] field_def An instance of create_field to be filled
@retval false on success
@retval true on error
*/
bool fill_field_definition(THD *thd, Column_definition *field_def)
{
return field_def->check(thd) ||
field_def->sp_prepare_create_field(thd, mem_root);
}
void set_info(longlong created, longlong modified,
st_sp_chistics *chistics, sql_mode_t sql_mode);
......
This diff is collapsed.
......@@ -251,11 +251,6 @@ bool quick_rm_table(THD *thd, handlerton *base, const char *db,
const char *table_name, uint flags,
const char *table_path=0);
void close_cached_table(THD *thd, TABLE *table);
bool sp_prepare_create_field(THD *thd, MEM_ROOT *mem_root,
Column_definition *sql_field);
int prepare_create_field(Column_definition *sql_field,
uint *blob_columns,
longlong table_flags);
CHARSET_INFO* get_sql_field_charset(Create_field *sql_field,
HA_CREATE_INFO *create_info);
bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags);
......
......@@ -3009,7 +3009,7 @@ sp_param_name_and_type:
LEX *lex= Lex;
sp_variable *spvar= $<spvar>2;
if (lex->sphead->fill_field_definition(thd, lex, lex->last_field))
if (lex->sphead->fill_field_definition(thd, lex->last_field))
{
MYSQL_YYABORT;
}
......@@ -3121,8 +3121,7 @@ sp_decl:
spvar->default_value= dflt_value_item;
spvar->field_def.field_name= spvar->name.str;
if (lex->sphead->fill_field_definition(thd, lex,
&spvar->field_def))
if (lex->sphead->fill_field_definition(thd, &spvar->field_def))
{
MYSQL_YYABORT;
}
......@@ -16715,7 +16714,7 @@ sf_tail:
}
type_with_opt_collate /* $11 */
{ /* $12 */
if (Lex->sphead->fill_field_definition(thd, Lex, Lex->last_field))
if (Lex->sphead->fill_field_definition(thd, Lex->last_field))
MYSQL_YYABORT;
}
sp_c_chistics /* $13 */
......
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