Skip to content
Permalink
Browse files
MDEV-14494 Move set_param_xxx() in sql_prepare.cc to methods in Item_…
…param and Type_handler

- sql_prepare.cc: Moving functions set_param_xxx() as
  methods to Item_param

- Replacing a pointer to a function Item_param::set_param_func
  to Type_handler based implementation:
  Item_param::value now derives from Type_handler_hybrid_field_type.
  Adding new virtual methods Type_handler::Item_param_setup_conversion()
  and Type_handler::Item_param_set_param_func()

- Moving declaration of some Item_param members  from "public:" to "private:"
  (CONVERSION_INFO, value, decimal_value)

- Adding a new method Item_param::set_limit_clause_param(),
  to share duplicate code, as well as to encapsulate
  Item_param::value.

- Adding Item_param::setup_conversion_string() and
  Item_param::setup_conversion_blob() to share
  the code for binding from a client value
  (mysql_stmt_bind_param), and for binding from
  an expression (Item).

- Removing two different functions set_param_str_or_null()
  and set_param_str(). Adding a common method Item_param::set_param_str().
  Item_param::m_empty_string_is_null, used by Item_param::set_param_str().

- Removing the call for setup_one_conversion_function() from
  insert_params_from_actual_params_with_log(). It's not needed,
  because the call for ps_param->save_in_param() makes sure
  to initialized all data type dependent members properly,
  by calling setup_conversion_string() from
  Type_handler_string_result::Item_param_set_from_value()
  and by calling setup_conversion_blob() from
  Type_handler_blob_common::Item_param_set_from_value()

- Cleanup: removing multiplication to MY_CHARSET_BIN_MB_MAXLEN
  in a few places. It's 1 anyway, and will never change.
  • Loading branch information
abarkov committed Nov 24, 2017
1 parent a18f600 commit 6aedbf4
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 186 deletions.
@@ -3708,20 +3708,6 @@ Item *Item_null::clone_item(THD *thd)

/*********************** Item_param related ******************************/

/**
Default function of Item_param::set_param_func, so in case
of malformed packet the server won't SIGSEGV.
*/

static void
default_set_param_func(Item_param *param,
uchar **pos __attribute__((unused)),
ulong len __attribute__((unused)))
{
param->set_null();
}


Item_param::Item_param(THD *thd, const LEX_CSTRING *name_arg,
uint pos_in_query_arg, uint len_in_query_arg):
Item_basic_value(thd),
@@ -3739,8 +3725,8 @@ Item_param::Item_param(THD *thd, const LEX_CSTRING *name_arg,
state(NO_VALUE),
/* Don't pretend to be a literal unless value for this item is set. */
item_type(PARAM_ITEM),
m_empty_string_is_null(false),
indicator(STMT_INDICATOR_NONE),
set_param_func(default_set_param_func),
m_out_param_info(NULL),
/*
Set m_is_settable_routine_parameter to "true" by default.
@@ -4025,9 +4011,8 @@ bool Item_param::set_from_item(THD *thd, Item *item)
else
{
unsigned_flag= item->unsigned_flag;
set_int(val, MY_INT64_NUM_DECIMAL_DIGITS);
set_handler_by_result_type(item->result_type());
DBUG_RETURN(!unsigned_flag && value.integer < 0 ? 1 : 0);
DBUG_RETURN(set_limit_clause_param(val));
}
}
struct st_value tmp;
@@ -4535,7 +4520,6 @@ Item_param::set_param_type_and_swap_value(Item_param *src)
{
Type_std_attributes::set(src);
set_handler(src->type_handler());
set_param_func= src->set_param_func;
item_type= src->item_type;

maybe_null= src->maybe_null;
@@ -4544,6 +4528,7 @@ Item_param::set_param_type_and_swap_value(Item_param *src)
fixed= src->fixed;
value= src->value;

value.set_handler(src->value.type_handler());
decimal_value.swap(src->decimal_value);
str_value.swap(src->str_value);
str_value_ptr.swap(src->str_value_ptr);
@@ -3128,7 +3128,6 @@ class Item_param :public Item_basic_value,

void fix_temporal(uint32 max_length_arg, uint decimals_arg);

public:
struct CONVERSION_INFO
{
/*
@@ -3170,12 +3169,6 @@ class Item_param :public Item_basic_value,
}
};

/*
Used for bulk protocol only.
*/
enum enum_indicator_type indicator;

private:
/*
A buffer for string and long data values. Historically all allocated
values returned from val_str() were treated as eligible to
@@ -3188,15 +3181,30 @@ class Item_param :public Item_basic_value,
*/
String str_value_ptr;

public:
my_decimal decimal_value;
union
bool m_empty_string_is_null;

class PValue: public Type_handler_hybrid_field_type
{
longlong integer;
double real;
CONVERSION_INFO cs_info;
MYSQL_TIME time;
} value;
public:
PValue(): Type_handler_hybrid_field_type(&type_handler_null) {}
union
{
longlong integer;
double real;
CONVERSION_INFO cs_info;
MYSQL_TIME time;
};
};

PValue value;

my_decimal decimal_value;

public:
/*
Used for bulk protocol only.
*/
enum enum_indicator_type indicator;

const Type_handler *type_handler() const
{ return Type_handler_hybrid_field_type::type_handler(); }
@@ -3237,14 +3245,39 @@ class Item_param :public Item_basic_value,
void set_time(const MYSQL_TIME *tm, uint32 max_length_arg, uint decimals_arg);
bool set_from_item(THD *thd, Item *item);
void reset();

void set_param_tiny(uchar **pos, ulong len);
void set_param_short(uchar **pos, ulong len);
void set_param_int32(uchar **pos, ulong len);
void set_param_int64(uchar **pos, ulong len);
void set_param_float(uchar **pos, ulong len);
void set_param_double(uchar **pos, ulong len);
void set_param_decimal(uchar **pos, ulong len);
void set_param_time(uchar **pos, ulong len);
void set_param_datetime(uchar **pos, ulong len);
void set_param_date(uchar **pos, ulong len);
void set_param_str(uchar **pos, ulong len);

void setup_conversion(THD *thd, uchar param_type);
void setup_conversion_blob(THD *thd);
void setup_conversion_string(THD *thd, CHARSET_INFO *fromcs);

/*
Assign placeholder value from bind data.
Note, that 'len' has different semantics in embedded library (as we
don't need to check that packet is not broken there). See
sql_prepare.cc for details.
*/
void (*set_param_func)(Item_param *param, uchar **pos, ulong len);
void set_param_func(uchar **pos, ulong len)
{
value.type_handler()->Item_param_set_param_func(this, pos, len);
}

bool set_limit_clause_param(longlong nr)
{
set_int(nr, MY_INT64_NUM_DECIMAL_DIGITS);
return !unsigned_flag && value.integer < 0;
}
const String *query_val_str(THD *thd, String *str) const;

bool convert_str_value(THD *thd);

0 comments on commit 6aedbf4

Please sign in to comment.