Skip to content

Commit

Permalink
MDEV-11245 Move prepare_create_field and sp_prepare_create_field() as…
Browse files Browse the repository at this point in the history
… 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()
  • Loading branch information
Alexander Barkov committed Dec 6, 2016
1 parent 9ea0658 commit b9768dd
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 176 deletions.
7 changes: 7 additions & 0 deletions sql/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -3846,6 +3846,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; }
Expand Down
36 changes: 0 additions & 36 deletions sql/sp_head.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 16 additions & 2 deletions sql/sp_head.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b9768dd

Please sign in to comment.