MDEV-32002 Remove my_casedn_str() in append_identifier() context
- Adding a helper function append_identifier_opt_casedn() - Reusing it in: Item_ident::print() Item_func_nextval::print() Item_func_setval::print() This change remove six my_casedn_str() calls and reduces the code size.
This commit is contained in:
parent
8951f7d940
commit
ee1497c068
25
sql/item.cc
25
sql/item.cc
@ -3261,9 +3261,6 @@ LEX_CSTRING Item_ident::full_name_cstring() const
|
|||||||
void Item_ident::print(String *str, enum_query_type query_type)
|
void Item_ident::print(String *str, enum_query_type query_type)
|
||||||
{
|
{
|
||||||
THD *thd= current_thd;
|
THD *thd= current_thd;
|
||||||
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
|
|
||||||
LEX_CSTRING d_name= db_name;
|
|
||||||
LEX_CSTRING t_name= table_name;
|
|
||||||
bool use_table_name= table_name.str && table_name.str[0];
|
bool use_table_name= table_name.str && table_name.str[0];
|
||||||
bool use_db_name= use_table_name && db_name.str && db_name.str[0] &&
|
bool use_db_name= use_table_name && db_name.str && db_name.str[0] &&
|
||||||
!alias_name_used;
|
!alias_name_used;
|
||||||
@ -3304,32 +3301,18 @@ void Item_ident::print(String *str, enum_query_type query_type)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lower_case_table_names== 1 ||
|
bool casedn= lower_case_table_names== 1 ||
|
||||||
(lower_case_table_names == 2 && !alias_name_used))
|
(lower_case_table_names == 2 && !alias_name_used);
|
||||||
{
|
|
||||||
if (use_table_name)
|
|
||||||
{
|
|
||||||
strmov(t_name_buff, table_name.str);
|
|
||||||
my_casedn_str(files_charset_info, t_name_buff);
|
|
||||||
t_name= Lex_cstring_strlen(t_name_buff);
|
|
||||||
}
|
|
||||||
if (use_db_name)
|
|
||||||
{
|
|
||||||
strmov(d_name_buff, db_name.str);
|
|
||||||
my_casedn_str(files_charset_info, d_name_buff);
|
|
||||||
d_name= Lex_cstring_strlen(d_name_buff);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (use_db_name)
|
if (use_db_name)
|
||||||
{
|
{
|
||||||
append_identifier(thd, str, d_name.str, (uint) d_name.length);
|
append_identifier_opt_casedn(thd, str, db_name, casedn);
|
||||||
str->append('.');
|
str->append('.');
|
||||||
DBUG_ASSERT(use_table_name);
|
DBUG_ASSERT(use_table_name);
|
||||||
}
|
}
|
||||||
if (use_table_name)
|
if (use_table_name)
|
||||||
{
|
{
|
||||||
append_identifier(thd, str, t_name.str, (uint) t_name.length);
|
append_identifier_opt_casedn(thd, str, table_name, casedn);
|
||||||
str->append('.');
|
str->append('.');
|
||||||
}
|
}
|
||||||
append_identifier(thd, str, &field_name);
|
append_identifier(thd, str, &field_name);
|
||||||
|
@ -7097,14 +7097,24 @@ longlong Item_func_nextval::val_int()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Item_func_nextval::print_table_list_identifier(THD *thd, String *to) const
|
||||||
|
{
|
||||||
|
if (table_list->db.str && table_list->db.str[0])
|
||||||
|
{
|
||||||
|
if (append_identifier_opt_casedn(thd, to, table_list->db,
|
||||||
|
lower_case_table_names) ||
|
||||||
|
to->append('.'))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return append_identifier_opt_casedn(thd, to, table_list->table_name,
|
||||||
|
lower_case_table_names);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Print for nextval and lastval */
|
/* Print for nextval and lastval */
|
||||||
|
|
||||||
void Item_func_nextval::print(String *str, enum_query_type query_type)
|
void Item_func_nextval::print(String *str, enum_query_type query_type)
|
||||||
{
|
{
|
||||||
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
|
|
||||||
LEX_CSTRING d_name= table_list->db;
|
|
||||||
LEX_CSTRING t_name= table_list->table_name;
|
|
||||||
bool use_db_name= d_name.str && d_name.str[0];
|
|
||||||
THD *thd= current_thd; // Don't trust 'table'
|
THD *thd= current_thd; // Don't trust 'table'
|
||||||
|
|
||||||
str->append(func_name_cstring());
|
str->append(func_name_cstring());
|
||||||
@ -7114,26 +7124,8 @@ void Item_func_nextval::print(String *str, enum_query_type query_type)
|
|||||||
for next_val we assume that table_list has been updated to contain
|
for next_val we assume that table_list has been updated to contain
|
||||||
the current db.
|
the current db.
|
||||||
*/
|
*/
|
||||||
|
print_table_list_identifier(thd, str);
|
||||||
|
|
||||||
if (lower_case_table_names > 0)
|
|
||||||
{
|
|
||||||
strmake(t_name_buff, t_name.str, MAX_ALIAS_NAME-1);
|
|
||||||
t_name.length= my_casedn_str(files_charset_info, t_name_buff);
|
|
||||||
t_name.str= t_name_buff;
|
|
||||||
if (use_db_name)
|
|
||||||
{
|
|
||||||
strmake(d_name_buff, d_name.str, MAX_ALIAS_NAME-1);
|
|
||||||
d_name.length= my_casedn_str(files_charset_info, d_name_buff);
|
|
||||||
d_name.str= d_name_buff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (use_db_name)
|
|
||||||
{
|
|
||||||
append_identifier(thd, str, &d_name);
|
|
||||||
str->append('.');
|
|
||||||
}
|
|
||||||
append_identifier(thd, str, &t_name);
|
|
||||||
str->append(')');
|
str->append(')');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7225,10 +7217,6 @@ longlong Item_func_setval::val_int()
|
|||||||
|
|
||||||
void Item_func_setval::print(String *str, enum_query_type query_type)
|
void Item_func_setval::print(String *str, enum_query_type query_type)
|
||||||
{
|
{
|
||||||
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
|
|
||||||
LEX_CSTRING d_name= table_list->db;
|
|
||||||
LEX_CSTRING t_name= table_list->table_name;
|
|
||||||
bool use_db_name= d_name.str && d_name.str[0];
|
|
||||||
THD *thd= current_thd; // Don't trust 'table'
|
THD *thd= current_thd; // Don't trust 'table'
|
||||||
|
|
||||||
str->append(func_name_cstring());
|
str->append(func_name_cstring());
|
||||||
@ -7238,26 +7226,8 @@ void Item_func_setval::print(String *str, enum_query_type query_type)
|
|||||||
for next_val we assume that table_list has been updated to contain
|
for next_val we assume that table_list has been updated to contain
|
||||||
the current db.
|
the current db.
|
||||||
*/
|
*/
|
||||||
|
print_table_list_identifier(thd, str);
|
||||||
|
|
||||||
if (lower_case_table_names > 0)
|
|
||||||
{
|
|
||||||
strmake(t_name_buff, t_name.str, MAX_ALIAS_NAME-1);
|
|
||||||
t_name.length= my_casedn_str(files_charset_info, t_name_buff);
|
|
||||||
t_name.str= t_name_buff;
|
|
||||||
if (use_db_name)
|
|
||||||
{
|
|
||||||
strmake(d_name_buff, d_name.str, MAX_ALIAS_NAME-1);
|
|
||||||
d_name.length= my_casedn_str(files_charset_info, d_name_buff);
|
|
||||||
d_name.str= d_name_buff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (use_db_name)
|
|
||||||
{
|
|
||||||
append_identifier(thd, str, &d_name);
|
|
||||||
str->append('.');
|
|
||||||
}
|
|
||||||
append_identifier(thd, str, &t_name);
|
|
||||||
str->append(',');
|
str->append(',');
|
||||||
str->append_longlong(nextval);
|
str->append_longlong(nextval);
|
||||||
str->append(',');
|
str->append(',');
|
||||||
|
@ -4139,6 +4139,7 @@ class Item_func_nextval :public Item_longlong_func
|
|||||||
protected:
|
protected:
|
||||||
TABLE_LIST *table_list;
|
TABLE_LIST *table_list;
|
||||||
TABLE *table;
|
TABLE *table;
|
||||||
|
bool print_table_list_identifier(THD *thd, String *to) const;
|
||||||
public:
|
public:
|
||||||
Item_func_nextval(THD *thd, TABLE_LIST *table_list_arg):
|
Item_func_nextval(THD *thd, TABLE_LIST *table_list_arg):
|
||||||
Item_longlong_func(thd), table_list(table_list_arg) {}
|
Item_longlong_func(thd), table_list(table_list_arg) {}
|
||||||
|
@ -1630,6 +1630,20 @@ append_identifier(THD *thd, String *packet, const char *name, size_t length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Similar to append_identifier(), but with optional casedn conversion.
|
||||||
|
*/
|
||||||
|
bool append_identifier_opt_casedn(THD *thd, String *to,
|
||||||
|
const LEX_CSTRING &ident, bool casedn)
|
||||||
|
{
|
||||||
|
if (!casedn)
|
||||||
|
return append_identifier(thd, to, &ident);
|
||||||
|
CharBuffer<MAX_ALIAS_NAME> buff;
|
||||||
|
LEX_CSTRING ls= buff.copy_casedn(system_charset_info, ident).to_lex_cstring();
|
||||||
|
return append_identifier(thd, to, &ls);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Get the quote character for displaying an identifier.
|
Get the quote character for displaying an identifier.
|
||||||
|
|
||||||
|
@ -96,6 +96,10 @@ static inline bool append_identifier(THD *thd, String *packet, const LEX_CSTRING
|
|||||||
{
|
{
|
||||||
return append_identifier(thd, packet, name->str, name->length);
|
return append_identifier(thd, packet, name->str, name->length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool append_identifier_opt_casedn(THD *thd, String *to,
|
||||||
|
const LEX_CSTRING &ident, bool casedn);
|
||||||
|
|
||||||
void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
|
void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
|
||||||
int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd);
|
int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd);
|
||||||
bool mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list,
|
bool mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user