Polishing: use constants instead of magic numbers.
include/my_global.h: Introduce constants to be used instead of magic numbers. sql/field.cc: Polishing: use contants instead of magic numbers. sql/ha_innodb.cc: Polishing: use contants instead of magic numbers. sql/handler.cc: Polishing: use contants instead of magic numbers. sql/item.cc: Polishing: use contants instead of magic numbers. sql/item.h: Polishing: use contants instead of magic numbers. sql/item_func.cc: Polishing: use contants instead of magic numbers. sql/item_subselect.cc: Polishing: use contants instead of magic numbers. sql/log_event.cc: Polishing: use contants instead of magic numbers. sql/sql_base.cc: Polishing: use contants instead of magic numbers. sql/sql_select.cc: Polishing: use contants instead of magic numbers. sql/sql_show.cc: Polishing: use contants instead of magic numbers. sql/sql_table.cc: Polishing: use contants instead of magic numbers.
This commit is contained in:
parent
980569877a
commit
a0521cd749
@ -1357,4 +1357,13 @@ do { doubleget_union _tmp; \
|
||||
#define NO_EMBEDDED_ACCESS_CHECKS
|
||||
#endif
|
||||
|
||||
|
||||
/* Length of decimal number represented by INT32. */
|
||||
|
||||
#define MY_INT32_NUM_DECIMAL_DIGITS 11
|
||||
|
||||
/* Length of decimal number represented by INT64. */
|
||||
|
||||
#define MY_INT64_NUM_DECIMAL_DIGITS 21
|
||||
|
||||
#endif /* my_global_h */
|
||||
|
@ -1203,12 +1203,12 @@ static bool test_if_real(const char *str,int length, CHARSET_INFO *cs)
|
||||
String *Field::val_int_as_str(String *val_buffer, my_bool unsigned_val)
|
||||
{
|
||||
CHARSET_INFO *cs= &my_charset_bin;
|
||||
uint length= 21;
|
||||
uint length;
|
||||
longlong value= val_int();
|
||||
if (val_buffer->alloc(length))
|
||||
if (val_buffer->alloc(MY_INT64_NUM_DECIMAL_DIGITS))
|
||||
return 0;
|
||||
length= (uint) (*cs->cset->longlong10_to_str)(cs, (char*) val_buffer->ptr(),
|
||||
length,
|
||||
MY_INT64_NUM_DECIMAL_DIGITS,
|
||||
unsigned_val ? 10 : -10,
|
||||
value);
|
||||
val_buffer->length(length);
|
||||
|
@ -6391,16 +6391,16 @@ innodb_mutex_show_status(
|
||||
#ifdef UNIV_DEBUG
|
||||
field_list.push_back(new Item_empty_string("Mutex", FN_REFLEN));
|
||||
field_list.push_back(new Item_empty_string("Module", FN_REFLEN));
|
||||
field_list.push_back(new Item_uint("Count", 21));
|
||||
field_list.push_back(new Item_uint("Spin_waits", 21));
|
||||
field_list.push_back(new Item_uint("Spin_rounds", 21));
|
||||
field_list.push_back(new Item_uint("OS_waits", 21));
|
||||
field_list.push_back(new Item_uint("OS_yields", 21));
|
||||
field_list.push_back(new Item_uint("OS_waits_time", 21));
|
||||
field_list.push_back(new Item_uint("Count", MY_INT64_NUM_DECIMAL_DIGITS));
|
||||
field_list.push_back(new Item_uint("Spin_waits", MY_INT64_NUM_DECIMAL_DIGITS));
|
||||
field_list.push_back(new Item_uint("Spin_rounds", MY_INT64_NUM_DECIMAL_DIGITS));
|
||||
field_list.push_back(new Item_uint("OS_waits", MY_INT64_NUM_DECIMAL_DIGITS));
|
||||
field_list.push_back(new Item_uint("OS_yields", MY_INT64_NUM_DECIMAL_DIGITS));
|
||||
field_list.push_back(new Item_uint("OS_waits_time", MY_INT64_NUM_DECIMAL_DIGITS));
|
||||
#else /* UNIV_DEBUG */
|
||||
field_list.push_back(new Item_empty_string("File", FN_REFLEN));
|
||||
field_list.push_back(new Item_uint("Line", 21));
|
||||
field_list.push_back(new Item_uint("OS_waits", 21));
|
||||
field_list.push_back(new Item_uint("Line", MY_INT64_NUM_DECIMAL_DIGITS));
|
||||
field_list.push_back(new Item_uint("OS_waits", MY_INT64_NUM_DECIMAL_DIGITS));
|
||||
#endif /* UNIV_DEBUG */
|
||||
|
||||
if (protocol->send_fields(&field_list,
|
||||
|
@ -1082,9 +1082,9 @@ bool mysql_xa_recover(THD *thd)
|
||||
XID_STATE *xs;
|
||||
DBUG_ENTER("mysql_xa_recover");
|
||||
|
||||
field_list.push_back(new Item_int("formatID",0,11));
|
||||
field_list.push_back(new Item_int("gtrid_length",0,11));
|
||||
field_list.push_back(new Item_int("bqual_length",0,11));
|
||||
field_list.push_back(new Item_int("formatID", 0, MY_INT32_NUM_DECIMAL_DIGITS));
|
||||
field_list.push_back(new Item_int("gtrid_length", 0, MY_INT32_NUM_DECIMAL_DIGITS));
|
||||
field_list.push_back(new Item_int("bqual_length", 0, MY_INT32_NUM_DECIMAL_DIGITS));
|
||||
field_list.push_back(new Item_empty_string("data",XIDDATASIZE));
|
||||
|
||||
if (protocol->send_fields(&field_list,
|
||||
|
@ -148,7 +148,7 @@ void
|
||||
Hybrid_type_traits_integer::fix_length_and_dec(Item *item, Item *arg) const
|
||||
{
|
||||
item->decimals= 0;
|
||||
item->max_length= 21;
|
||||
item->max_length= MY_INT64_NUM_DECIMAL_DIGITS;
|
||||
item->unsigned_flag= 0;
|
||||
}
|
||||
|
||||
@ -2491,7 +2491,7 @@ bool Item_param::set_from_user_var(THD *thd, const user_var_entry *entry)
|
||||
item_result_type= REAL_RESULT;
|
||||
break;
|
||||
case INT_RESULT:
|
||||
set_int(*(longlong*)entry->value, 21);
|
||||
set_int(*(longlong*)entry->value, MY_INT64_NUM_DECIMAL_DIGITS);
|
||||
item_type= Item::INT_ITEM;
|
||||
item_result_type= INT_RESULT;
|
||||
break;
|
||||
@ -6535,7 +6535,7 @@ uint32 Item_type_holder::display_length(Item *item)
|
||||
case MYSQL_TYPE_SHORT:
|
||||
return 6;
|
||||
case MYSQL_TYPE_LONG:
|
||||
return 11;
|
||||
return MY_INT32_NUM_DECIMAL_DIGITS;
|
||||
case MYSQL_TYPE_FLOAT:
|
||||
return 25;
|
||||
case MYSQL_TYPE_DOUBLE:
|
||||
|
@ -1494,11 +1494,14 @@ class Item_int :public Item_num
|
||||
{
|
||||
public:
|
||||
longlong value;
|
||||
Item_int(int32 i,uint length=11) :value((longlong) i)
|
||||
Item_int(int32 i,uint length= MY_INT32_NUM_DECIMAL_DIGITS)
|
||||
:value((longlong) i)
|
||||
{ max_length=length; fixed= 1; }
|
||||
Item_int(longlong i,uint length=21) :value(i)
|
||||
Item_int(longlong i,uint length= MY_INT64_NUM_DECIMAL_DIGITS)
|
||||
:value(i)
|
||||
{ max_length=length; fixed= 1; }
|
||||
Item_int(ulonglong i, uint length= 21) :value((longlong)i)
|
||||
Item_int(ulonglong i, uint length= MY_INT64_NUM_DECIMAL_DIGITS)
|
||||
:value((longlong)i)
|
||||
{ max_length=length; fixed= 1; unsigned_flag= 1; }
|
||||
Item_int(const char *str_arg,longlong i,uint length) :value(i)
|
||||
{ max_length=length; name=(char*) str_arg; fixed= 1; }
|
||||
|
@ -426,7 +426,7 @@ Field *Item_func::tmp_table_field(TABLE *t_arg)
|
||||
|
||||
switch (result_type()) {
|
||||
case INT_RESULT:
|
||||
if (max_length > 11)
|
||||
if (max_length > MY_INT32_NUM_DECIMAL_DIGITS)
|
||||
res= new Field_longlong(max_length, maybe_null, name, t_arg,
|
||||
unsigned_flag);
|
||||
else
|
||||
@ -2316,7 +2316,8 @@ longlong Item_func_coercibility::val_int()
|
||||
|
||||
void Item_func_locate::fix_length_and_dec()
|
||||
{
|
||||
maybe_null=0; max_length=11;
|
||||
maybe_null= 0;
|
||||
max_length= MY_INT32_NUM_DECIMAL_DIGITS;
|
||||
agg_arg_charsets(cmp_collation, args, 2, MY_COLL_CMP_CONV, 1);
|
||||
}
|
||||
|
||||
|
@ -1037,7 +1037,8 @@ Item_in_subselect::single_value_transformer(JOIN *join,
|
||||
Item *having= item, *orig_item= item;
|
||||
select_lex->item_list.empty();
|
||||
select_lex->item_list.push_back(new Item_int("Not_used",
|
||||
(longlong) 1, 21));
|
||||
(longlong) 1,
|
||||
MY_INT64_NUM_DECIMAL_DIGITS));
|
||||
select_lex->ref_pointer_array[0]= select_lex->item_list.head();
|
||||
|
||||
item= func->create(expr, item);
|
||||
|
@ -541,12 +541,13 @@ int Log_event::net_send(Protocol *protocol, const char* log_name, my_off_t pos)
|
||||
void Log_event::init_show_field_list(List<Item>* field_list)
|
||||
{
|
||||
field_list->push_back(new Item_empty_string("Log_name", 20));
|
||||
field_list->push_back(new Item_return_int("Pos", 11,
|
||||
field_list->push_back(new Item_return_int("Pos", MY_INT32_NUM_DECIMAL_DIGITS,
|
||||
MYSQL_TYPE_LONGLONG));
|
||||
field_list->push_back(new Item_empty_string("Event_type", 20));
|
||||
field_list->push_back(new Item_return_int("Server_id", 10,
|
||||
MYSQL_TYPE_LONG));
|
||||
field_list->push_back(new Item_return_int("End_log_pos", 11,
|
||||
field_list->push_back(new Item_return_int("End_log_pos",
|
||||
MY_INT32_NUM_DECIMAL_DIGITS,
|
||||
MYSQL_TYPE_LONGLONG));
|
||||
field_list->push_back(new Item_empty_string("Info", 20));
|
||||
}
|
||||
|
@ -4559,7 +4559,8 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
|
||||
|
||||
Item_int do not need fix_fields() because it is basic constant.
|
||||
*/
|
||||
it.replace(new Item_int("Not_used", (longlong) 1, 21));
|
||||
it.replace(new Item_int("Not_used", (longlong) 1,
|
||||
MY_INT64_NUM_DECIMAL_DIGITS));
|
||||
}
|
||||
else if (insert_fields(thd, ((Item_field*) item)->context,
|
||||
((Item_field*) item)->db_name,
|
||||
|
@ -8491,7 +8491,7 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value)
|
||||
if ((new_cond= new Item_func_eq(args[0],
|
||||
new Item_int("last_insert_id()",
|
||||
thd->current_insert_id,
|
||||
21))))
|
||||
MY_INT64_NUM_DECIMAL_DIGITS))))
|
||||
{
|
||||
/*
|
||||
Set THD::last_insert_id_used_bin_log manually, as this
|
||||
@ -8757,7 +8757,7 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
|
||||
break;
|
||||
case INT_RESULT:
|
||||
/* Select an integer type with the minimal fit precision */
|
||||
if (item->max_length > 11)
|
||||
if (item->max_length > MY_INT32_NUM_DECIMAL_DIGITS)
|
||||
new_field=new Field_longlong(item->max_length, maybe_null,
|
||||
item->name, table, item->unsigned_flag);
|
||||
else
|
||||
@ -14964,7 +14964,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
|
||||
/* Add "rows" field to item_list. */
|
||||
item_list.push_back(new Item_int((longlong) (ulonglong)
|
||||
join->best_positions[i]. records_read,
|
||||
21));
|
||||
MY_INT64_NUM_DECIMAL_DIGITS));
|
||||
/* Build "Extra" field and add it to item_list. */
|
||||
my_bool key_read=table->key_read;
|
||||
if ((tab->type == JT_NEXT || tab->type == JT_CONST) &&
|
||||
|
@ -205,7 +205,8 @@ bool mysqld_show_column_types(THD *thd)
|
||||
DBUG_ENTER("mysqld_show_column_types");
|
||||
|
||||
field_list.push_back(new Item_empty_string("Type",30));
|
||||
field_list.push_back(new Item_int("Size",(longlong) 1,21));
|
||||
field_list.push_back(new Item_int("Size",(longlong) 1,
|
||||
MY_INT64_NUM_DECIMAL_DIGITS));
|
||||
field_list.push_back(new Item_empty_string("Min_Value",20));
|
||||
field_list.push_back(new Item_empty_string("Max_Value",20));
|
||||
field_list.push_back(new Item_return_int("Prec", 4, MYSQL_TYPE_SHORT));
|
||||
@ -1284,7 +1285,7 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
|
||||
Protocol *protocol= thd->protocol;
|
||||
DBUG_ENTER("mysqld_list_processes");
|
||||
|
||||
field_list.push_back(new Item_int("Id",0,11));
|
||||
field_list.push_back(new Item_int("Id", 0, MY_INT32_NUM_DECIMAL_DIGITS));
|
||||
field_list.push_back(new Item_empty_string("User",16));
|
||||
field_list.push_back(new Item_empty_string("Host",LIST_PROCESS_HOST_LEN));
|
||||
field_list.push_back(field=new Item_empty_string("db",NAME_LEN));
|
||||
@ -4038,20 +4039,25 @@ ST_FIELD_INFO tables_fields_info[]=
|
||||
{"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Name"},
|
||||
{"TABLE_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
|
||||
{"ENGINE", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, "Engine"},
|
||||
{"VERSION", 21 , MYSQL_TYPE_LONG, 0, 1, "Version"},
|
||||
{"VERSION", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONG, 0, 1, "Version"},
|
||||
{"ROW_FORMAT", 10, MYSQL_TYPE_STRING, 0, 1, "Row_format"},
|
||||
{"TABLE_ROWS", 21 , MYSQL_TYPE_LONG, 0, 1, "Rows"},
|
||||
{"AVG_ROW_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, "Avg_row_length"},
|
||||
{"DATA_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, "Data_length"},
|
||||
{"MAX_DATA_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, "Max_data_length"},
|
||||
{"INDEX_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, "Index_length"},
|
||||
{"DATA_FREE", 21 , MYSQL_TYPE_LONG, 0, 1, "Data_free"},
|
||||
{"AUTO_INCREMENT", 21 , MYSQL_TYPE_LONG, 0, 1, "Auto_increment"},
|
||||
{"TABLE_ROWS", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONG, 0, 1, "Rows"},
|
||||
{"AVG_ROW_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONG, 0, 1,
|
||||
"Avg_row_length"},
|
||||
{"DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONG, 0, 1,
|
||||
"Data_length"},
|
||||
{"MAX_DATA_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONG, 0, 1,
|
||||
"Max_data_length"},
|
||||
{"INDEX_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONG, 0, 1,
|
||||
"Index_length"},
|
||||
{"DATA_FREE", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONG, 0, 1, "Data_free"},
|
||||
{"AUTO_INCREMENT", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONG, 0, 1,
|
||||
"Auto_increment"},
|
||||
{"CREATE_TIME", 0, MYSQL_TYPE_TIMESTAMP, 0, 1, "Create_time"},
|
||||
{"UPDATE_TIME", 0, MYSQL_TYPE_TIMESTAMP, 0, 1, "Update_time"},
|
||||
{"CHECK_TIME", 0, MYSQL_TYPE_TIMESTAMP, 0, 1, "Check_time"},
|
||||
{"TABLE_COLLATION", 64, MYSQL_TYPE_STRING, 0, 1, "Collation"},
|
||||
{"CHECKSUM", 21 , MYSQL_TYPE_LONG, 0, 1, "Checksum"},
|
||||
{"CHECKSUM", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONG, 0, 1, "Checksum"},
|
||||
{"CREATE_OPTIONS", 255, MYSQL_TYPE_STRING, 0, 1, "Create_options"},
|
||||
{"TABLE_COMMENT", 80, MYSQL_TYPE_STRING, 0, 0, "Comment"},
|
||||
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
|
||||
@ -4064,14 +4070,15 @@ ST_FIELD_INFO columns_fields_info[]=
|
||||
{"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
|
||||
{"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
|
||||
{"COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Field"},
|
||||
{"ORDINAL_POSITION", 21 , MYSQL_TYPE_LONG, 0, 0, 0},
|
||||
{"ORDINAL_POSITION", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONG, 0, 0, 0},
|
||||
{"COLUMN_DEFAULT", MAX_FIELD_VARCHARLENGTH, MYSQL_TYPE_STRING, 0, 1, "Default"},
|
||||
{"IS_NULLABLE", 3, MYSQL_TYPE_STRING, 0, 0, "Null"},
|
||||
{"DATA_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
|
||||
{"CHARACTER_MAXIMUM_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0},
|
||||
{"CHARACTER_OCTET_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0},
|
||||
{"NUMERIC_PRECISION", 21 , MYSQL_TYPE_LONG, 0, 1, 0},
|
||||
{"NUMERIC_SCALE", 21 , MYSQL_TYPE_LONG, 0, 1, 0},
|
||||
{"CHARACTER_MAXIMUM_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONG, 0, 1,
|
||||
0},
|
||||
{"CHARACTER_OCTET_LENGTH", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONG, 0, 1, 0},
|
||||
{"NUMERIC_PRECISION", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONG, 0, 1, 0},
|
||||
{"NUMERIC_SCALE", MY_INT64_NUM_DECIMAL_DIGITS , MYSQL_TYPE_LONG, 0, 1, 0},
|
||||
{"CHARACTER_SET_NAME", 64, MYSQL_TYPE_STRING, 0, 1, 0},
|
||||
{"COLLATION_NAME", 64, MYSQL_TYPE_STRING, 0, 1, "Collation"},
|
||||
{"COLUMN_TYPE", 65535, MYSQL_TYPE_STRING, 0, 0, "Type"},
|
||||
@ -4097,7 +4104,7 @@ ST_FIELD_INFO collation_fields_info[]=
|
||||
{
|
||||
{"COLLATION_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Collation"},
|
||||
{"CHARACTER_SET_NAME", 64, MYSQL_TYPE_STRING, 0, 0, "Charset"},
|
||||
{"ID", 11, MYSQL_TYPE_LONG, 0, 0, "Id"},
|
||||
{"ID", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Id"},
|
||||
{"IS_DEFAULT", 3, MYSQL_TYPE_STRING, 0, 0, "Default"},
|
||||
{"IS_COMPILED", 3, MYSQL_TYPE_STRING, 0, 0, "Compiled"},
|
||||
{"SORTLEN", 3 ,MYSQL_TYPE_LONG, 0, 0, "Sortlen"},
|
||||
@ -4150,7 +4157,7 @@ ST_FIELD_INFO stat_fields_info[]=
|
||||
{"SEQ_IN_INDEX", 2, MYSQL_TYPE_LONG, 0, 0, "Seq_in_index"},
|
||||
{"COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Column_name"},
|
||||
{"COLLATION", 1, MYSQL_TYPE_STRING, 0, 1, "Collation"},
|
||||
{"CARDINALITY", 21, MYSQL_TYPE_LONG, 0, 1, "Cardinality"},
|
||||
{"CARDINALITY", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 1, "Cardinality"},
|
||||
{"SUB_PART", 3, MYSQL_TYPE_LONG, 0, 1, "Sub_part"},
|
||||
{"PACKED", 10, MYSQL_TYPE_STRING, 0, 1, "Packed"},
|
||||
{"NULLABLE", 3, MYSQL_TYPE_STRING, 0, 0, "Null"},
|
||||
|
@ -4146,7 +4146,8 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables, HA_CHECK_OPT *check_opt)
|
||||
|
||||
field_list.push_back(item = new Item_empty_string("Table", NAME_LEN*2));
|
||||
item->maybe_null= 1;
|
||||
field_list.push_back(item=new Item_int("Checksum",(longlong) 1,21));
|
||||
field_list.push_back(item= new Item_int("Checksum", (longlong) 1,
|
||||
MY_INT64_NUM_DECIMAL_DIGITS));
|
||||
item->maybe_null= 1;
|
||||
if (protocol->send_fields(&field_list,
|
||||
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
|
||||
|
Loading…
x
Reference in New Issue
Block a user