Skip to content

Commit ee1497c

Browse files
committed
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.
1 parent 8951f7d commit ee1497c

File tree

5 files changed

+39
-67
lines changed

5 files changed

+39
-67
lines changed

sql/item.cc

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3261,9 +3261,6 @@ LEX_CSTRING Item_ident::full_name_cstring() const
32613261
void Item_ident::print(String *str, enum_query_type query_type)
32623262
{
32633263
THD *thd= current_thd;
3264-
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
3265-
LEX_CSTRING d_name= db_name;
3266-
LEX_CSTRING t_name= table_name;
32673264
bool use_table_name= table_name.str && table_name.str[0];
32683265
bool use_db_name= use_table_name && db_name.str && db_name.str[0] &&
32693266
!alias_name_used;
@@ -3304,32 +3301,18 @@ void Item_ident::print(String *str, enum_query_type query_type)
33043301
return;
33053302
}
33063303

3307-
if (lower_case_table_names== 1 ||
3308-
(lower_case_table_names == 2 && !alias_name_used))
3309-
{
3310-
if (use_table_name)
3311-
{
3312-
strmov(t_name_buff, table_name.str);
3313-
my_casedn_str(files_charset_info, t_name_buff);
3314-
t_name= Lex_cstring_strlen(t_name_buff);
3315-
}
3316-
if (use_db_name)
3317-
{
3318-
strmov(d_name_buff, db_name.str);
3319-
my_casedn_str(files_charset_info, d_name_buff);
3320-
d_name= Lex_cstring_strlen(d_name_buff);
3321-
}
3322-
}
3304+
bool casedn= lower_case_table_names== 1 ||
3305+
(lower_case_table_names == 2 && !alias_name_used);
33233306

33243307
if (use_db_name)
33253308
{
3326-
append_identifier(thd, str, d_name.str, (uint) d_name.length);
3309+
append_identifier_opt_casedn(thd, str, db_name, casedn);
33273310
str->append('.');
33283311
DBUG_ASSERT(use_table_name);
33293312
}
33303313
if (use_table_name)
33313314
{
3332-
append_identifier(thd, str, t_name.str, (uint) t_name.length);
3315+
append_identifier_opt_casedn(thd, str, table_name, casedn);
33333316
str->append('.');
33343317
}
33353318
append_identifier(thd, str, &field_name);

sql/item_func.cc

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7097,14 +7097,24 @@ longlong Item_func_nextval::val_int()
70977097
}
70987098

70997099

7100+
bool Item_func_nextval::print_table_list_identifier(THD *thd, String *to) const
7101+
{
7102+
if (table_list->db.str && table_list->db.str[0])
7103+
{
7104+
if (append_identifier_opt_casedn(thd, to, table_list->db,
7105+
lower_case_table_names) ||
7106+
to->append('.'))
7107+
return true;
7108+
}
7109+
return append_identifier_opt_casedn(thd, to, table_list->table_name,
7110+
lower_case_table_names);
7111+
}
7112+
7113+
71007114
/* Print for nextval and lastval */
71017115

71027116
void Item_func_nextval::print(String *str, enum_query_type query_type)
71037117
{
7104-
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
7105-
LEX_CSTRING d_name= table_list->db;
7106-
LEX_CSTRING t_name= table_list->table_name;
7107-
bool use_db_name= d_name.str && d_name.str[0];
71087118
THD *thd= current_thd; // Don't trust 'table'
71097119

71107120
str->append(func_name_cstring());
@@ -7114,26 +7124,8 @@ void Item_func_nextval::print(String *str, enum_query_type query_type)
71147124
for next_val we assume that table_list has been updated to contain
71157125
the current db.
71167126
*/
7127+
print_table_list_identifier(thd, str);
71177128

7118-
if (lower_case_table_names > 0)
7119-
{
7120-
strmake(t_name_buff, t_name.str, MAX_ALIAS_NAME-1);
7121-
t_name.length= my_casedn_str(files_charset_info, t_name_buff);
7122-
t_name.str= t_name_buff;
7123-
if (use_db_name)
7124-
{
7125-
strmake(d_name_buff, d_name.str, MAX_ALIAS_NAME-1);
7126-
d_name.length= my_casedn_str(files_charset_info, d_name_buff);
7127-
d_name.str= d_name_buff;
7128-
}
7129-
}
7130-
7131-
if (use_db_name)
7132-
{
7133-
append_identifier(thd, str, &d_name);
7134-
str->append('.');
7135-
}
7136-
append_identifier(thd, str, &t_name);
71377129
str->append(')');
71387130
}
71397131

@@ -7225,10 +7217,6 @@ longlong Item_func_setval::val_int()
72257217

72267218
void Item_func_setval::print(String *str, enum_query_type query_type)
72277219
{
7228-
char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
7229-
LEX_CSTRING d_name= table_list->db;
7230-
LEX_CSTRING t_name= table_list->table_name;
7231-
bool use_db_name= d_name.str && d_name.str[0];
72327220
THD *thd= current_thd; // Don't trust 'table'
72337221

72347222
str->append(func_name_cstring());
@@ -7238,26 +7226,8 @@ void Item_func_setval::print(String *str, enum_query_type query_type)
72387226
for next_val we assume that table_list has been updated to contain
72397227
the current db.
72407228
*/
7229+
print_table_list_identifier(thd, str);
72417230

7242-
if (lower_case_table_names > 0)
7243-
{
7244-
strmake(t_name_buff, t_name.str, MAX_ALIAS_NAME-1);
7245-
t_name.length= my_casedn_str(files_charset_info, t_name_buff);
7246-
t_name.str= t_name_buff;
7247-
if (use_db_name)
7248-
{
7249-
strmake(d_name_buff, d_name.str, MAX_ALIAS_NAME-1);
7250-
d_name.length= my_casedn_str(files_charset_info, d_name_buff);
7251-
d_name.str= d_name_buff;
7252-
}
7253-
}
7254-
7255-
if (use_db_name)
7256-
{
7257-
append_identifier(thd, str, &d_name);
7258-
str->append('.');
7259-
}
7260-
append_identifier(thd, str, &t_name);
72617231
str->append(',');
72627232
str->append_longlong(nextval);
72637233
str->append(',');

sql/item_func.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4139,6 +4139,7 @@ class Item_func_nextval :public Item_longlong_func
41394139
protected:
41404140
TABLE_LIST *table_list;
41414141
TABLE *table;
4142+
bool print_table_list_identifier(THD *thd, String *to) const;
41424143
public:
41434144
Item_func_nextval(THD *thd, TABLE_LIST *table_list_arg):
41444145
Item_longlong_func(thd), table_list(table_list_arg) {}

sql/sql_show.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,20 @@ append_identifier(THD *thd, String *packet, const char *name, size_t length)
16301630
}
16311631

16321632

1633+
/**
1634+
Similar to append_identifier(), but with optional casedn conversion.
1635+
*/
1636+
bool append_identifier_opt_casedn(THD *thd, String *to,
1637+
const LEX_CSTRING &ident, bool casedn)
1638+
{
1639+
if (!casedn)
1640+
return append_identifier(thd, to, &ident);
1641+
CharBuffer<MAX_ALIAS_NAME> buff;
1642+
LEX_CSTRING ls= buff.copy_casedn(system_charset_info, ident).to_lex_cstring();
1643+
return append_identifier(thd, to, &ls);
1644+
}
1645+
1646+
16331647
/*
16341648
Get the quote character for displaying an identifier.
16351649

sql/sql_show.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ static inline bool append_identifier(THD *thd, String *packet, const LEX_CSTRING
9696
{
9797
return append_identifier(thd, packet, name->str, name->length);
9898
}
99+
100+
bool append_identifier_opt_casedn(THD *thd, String *to,
101+
const LEX_CSTRING &ident, bool casedn);
102+
99103
void mysqld_list_fields(THD *thd,TABLE_LIST *table, const char *wild);
100104
int mysqld_dump_create_info(THD *thd, TABLE_LIST *table_list, int fd);
101105
bool mysqld_show_create_get_fields(THD *thd, TABLE_LIST *table_list,

0 commit comments

Comments
 (0)