summaryrefslogtreecommitdiff
path: root/sql/sql_base.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_base.cc')
-rw-r--r--sql/sql_base.cc107
1 files changed, 53 insertions, 54 deletions
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index b0d42be6ad3..5e13d7cd759 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -502,7 +502,7 @@ err_with_reopen:
struct close_cached_connection_tables_arg
{
THD *thd;
- LEX_STRING *connection;
+ LEX_CSTRING *connection;
TABLE_LIST *tables;
};
@@ -547,7 +547,7 @@ end:
}
-bool close_cached_connection_tables(THD *thd, LEX_STRING *connection)
+bool close_cached_connection_tables(THD *thd, LEX_CSTRING *connection)
{
close_cached_connection_tables_arg argument;
DBUG_ENTER("close_cached_connections");
@@ -1481,7 +1481,7 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
TABLE *table;
const char *key;
uint key_length;
- char *alias= table_list->alias;
+ const char *alias= table_list->alias;
uint flags= ot_ctx->get_flags();
MDL_ticket *mdl_ticket;
TABLE_SHARE *share;
@@ -4174,8 +4174,9 @@ handle_routine(THD *thd, Query_tables_list *prelocking_ctx,
@note this can be changed to use a hash, instead of scanning the linked
list, if the performance of this function will ever become an issue
*/
-static bool table_already_fk_prelocked(TABLE_LIST *tl, LEX_STRING *db,
- LEX_STRING *table, thr_lock_type lock_type)
+static bool table_already_fk_prelocked(TABLE_LIST *tl, LEX_CSTRING *db,
+ LEX_CSTRING *table,
+ thr_lock_type lock_type)
{
for (; tl; tl= tl->next_global )
{
@@ -5246,7 +5247,7 @@ find_field_in_view(THD *thd, TABLE_LIST *table_list,
for (; !field_it.end_of_fields(); field_it.next())
{
- if (!my_strcasecmp(system_charset_info, field_it.name(), name))
+ if (!my_strcasecmp(system_charset_info, field_it.name()->str, name))
{
// in PS use own arena or data will be freed after prepare
if (register_tree_change &&
@@ -5270,7 +5271,7 @@ find_field_in_view(THD *thd, TABLE_LIST *table_list,
the replacing item.
*/
if (*ref && !(*ref)->is_autogenerated_name)
- item->set_name(thd, (*ref)->name, (*ref)->name_length,
+ item->set_name(thd, (*ref)->name.str, (*ref)->name.length,
system_charset_info);
if (register_tree_change)
thd->change_item_tree(ref, item);
@@ -5331,7 +5332,7 @@ find_field_in_natural_join(THD *thd, TABLE_LIST *table_ref, const char *name,
for (nj_col= NULL, curr_nj_col= field_it++; curr_nj_col;
curr_nj_col= field_it++)
{
- if (!my_strcasecmp(system_charset_info, curr_nj_col->name(), name))
+ if (!my_strcasecmp(system_charset_info, curr_nj_col->name()->str, name))
{
if (nj_col)
{
@@ -5358,15 +5359,10 @@ find_field_in_natural_join(THD *thd, TABLE_LIST *table_ref, const char *name,
*ref != NULL means that *ref contains the item that we need to
replace. If the item was aliased by the user, set the alias to
the replacing item.
- We need to set alias on both ref itself and on ref real item.
*/
if (*ref && !(*ref)->is_autogenerated_name)
- {
- item->set_name(thd, (*ref)->name, (*ref)->name_length,
+ item->set_name(thd, (*ref)->name.str, (*ref)->name.length,
system_charset_info);
- item->real_item()->set_name(thd, (*ref)->name, (*ref)->name_length,
- system_charset_info);
- }
if (register_tree_change && arena)
thd->restore_active_arena(arena, &backup);
@@ -5403,7 +5399,7 @@ find_field_in_natural_join(THD *thd, TABLE_LIST *table_ref, const char *name,
nj_col->table_field->fix_fields(thd, &ref))
{
DBUG_PRINT("info", ("column '%s' was dropped by the concurrent connection",
- nj_col->table_field->name));
+ nj_col->table_field->name.str));
DBUG_RETURN(NULL);
}
DBUG_ASSERT(ref == 0); // Should not have changed
@@ -5451,7 +5447,7 @@ find_field_in_table(THD *thd, TABLE *table, const char *name, uint length,
/* We assume here that table->field < NO_CACHED_FIELD_INDEX = UINT_MAX */
if (cached_field_index < table->s->fields &&
!my_strcasecmp(system_charset_info,
- table->field[cached_field_index]->field_name, name))
+ table->field[cached_field_index]->field_name.str, name))
field_ptr= table->field + cached_field_index;
else if (table->s->name_hash.records)
{
@@ -5471,7 +5467,8 @@ find_field_in_table(THD *thd, TABLE *table, const char *name, uint length,
if (!(field_ptr= table->field))
DBUG_RETURN((Field *)0);
for (; *field_ptr; ++field_ptr)
- if (!my_strcasecmp(system_charset_info, (*field_ptr)->field_name, name))
+ if (!my_strcasecmp(system_charset_info, (*field_ptr)->field_name.str,
+ name))
break;
}
@@ -5734,7 +5731,8 @@ Field *find_field_in_table_sef(TABLE *table, const char *name)
if (!(field_ptr= table->field))
return (Field *)0;
for (; *field_ptr; ++field_ptr)
- if (!my_strcasecmp(system_charset_info, (*field_ptr)->field_name, name))
+ if (!my_strcasecmp(system_charset_info, (*field_ptr)->field_name.str,
+ name))
break;
}
if (field_ptr)
@@ -5787,8 +5785,8 @@ find_field_in_tables(THD *thd, Item_ident *item,
Field *found=0;
const char *db= item->db_name;
const char *table_name= item->table_name;
- const char *name= item->field_name;
- uint length=(uint) strlen(name);
+ const char *name= item->field_name.str;
+ uint length= item->field_name.length;
char name_buff[SAFE_NAME_LEN+1];
TABLE_LIST *cur_table= first_table;
TABLE_LIST *actual_table;
@@ -5835,7 +5833,7 @@ find_field_in_tables(THD *thd, Item_ident *item,
#endif
}
else
- found= find_field_in_table_ref(thd, table_ref, name, length, item->name,
+ found= find_field_in_table_ref(thd, table_ref, name, length, item->name.str,
NULL, NULL, ref, check_privileges,
TRUE, &(item->cached_field_index),
register_tree_change,
@@ -5903,7 +5901,7 @@ find_field_in_tables(THD *thd, Item_ident *item,
cur_table= cur_table->next_name_resolution_table)
{
Field *cur_field= find_field_in_table_ref(thd, cur_table, name, length,
- item->name, db, table_name, ref,
+ item->name.str, db, table_name, ref,
(thd->lex->sql_command ==
SQLCOM_SHOW_FIELDS)
? false : check_privileges,
@@ -5920,7 +5918,7 @@ find_field_in_tables(THD *thd, Item_ident *item,
thd->clear_error();
cur_field= find_field_in_table_ref(thd, cur_table, name, length,
- item->name, db, table_name, ref,
+ item->name.str, db, table_name, ref,
false,
allow_rowid,
&(item->cached_field_index),
@@ -5929,7 +5927,7 @@ find_field_in_tables(THD *thd, Item_ident *item,
if (cur_field)
{
Field *nf=new Field_null(NULL,0,Field::NONE,
- cur_field->field_name,
+ &cur_field->field_name,
&my_charset_bin);
nf->init(cur_table->table);
cur_field= nf;
@@ -6045,7 +6043,7 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
uint n_items= limit == 0 ? items.elements : limit;
Item **found=0, **found_unaliased= 0, *item;
const char *db_name=0;
- const char *field_name=0;
+ const LEX_CSTRING *field_name= 0;
const char *table_name=0;
bool found_unaliased_non_uniq= 0;
/*
@@ -6061,7 +6059,7 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
find->type() == Item::REF_ITEM);
if (is_ref_by_name)
{
- field_name= ((Item_ident*) find)->field_name;
+ field_name= &((Item_ident*) find)->field_name;
table_name= ((Item_ident*) find)->table_name;
db_name= ((Item_ident*) find)->db_name;
}
@@ -6069,7 +6067,7 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
for (uint i= 0; i < n_items; i++)
{
item= li++;
- if (field_name &&
+ if (field_name && field_name->str &&
(item->real_item()->type() == Item::FIELD_ITEM ||
((item->type() == Item::REF_ITEM) &&
(((Item_ref *)item)->ref_type() == Item_ref::VIEW_REF))))
@@ -6082,7 +6080,7 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
(if this field created from expression argument of group_concat()),
=> we have to check presence of name before compare
*/
- if (!item_field->name)
+ if (!item_field->name.str)
continue;
if (table_name)
@@ -6103,9 +6101,9 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
item_field->field_name and item_field->table_name can be 0x0 if
item is not fix_field()'ed yet.
*/
- if (item_field->field_name && item_field->table_name &&
- !my_strcasecmp(system_charset_info, item_field->field_name,
- field_name) &&
+ if (item_field->field_name.str && item_field->table_name &&
+ !my_strcasecmp(system_charset_info, item_field->field_name.str,
+ field_name->str) &&
!my_strcasecmp(table_alias_charset, item_field->table_name,
table_name) &&
(!db_name || (item_field->db_name &&
@@ -6135,10 +6133,10 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
else
{
int fname_cmp= my_strcasecmp(system_charset_info,
- item_field->field_name,
- field_name);
+ item_field->field_name.str,
+ field_name->str);
if (!my_strcasecmp(system_charset_info,
- item_field->name,field_name))
+ item_field->name.str,field_name->str))
{
/*
If table name was not given we should scan through aliases
@@ -6182,8 +6180,9 @@ find_item_in_list(Item *find, List<Item> &items, uint *counter,
}
else if (!table_name)
{
- if (is_ref_by_name && find->name && item->name &&
- !my_strcasecmp(system_charset_info,item->name,find->name))
+ if (is_ref_by_name && find->name.str && item->name.str &&
+ find->name.length == item->name.length &&
+ !my_strcasecmp(system_charset_info,item->name.str, find->name.str))
{
found= li.ref();
*counter= i;
@@ -6357,17 +6356,17 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
for (it_1.set(table_ref_1); !it_1.end_of_fields(); it_1.next())
{
bool found= FALSE;
- const char *field_name_1;
+ const LEX_CSTRING *field_name_1;
/* true if field_name_1 is a member of using_fields */
bool is_using_column_1;
if (!(nj_col_1= it_1.get_or_create_column_ref(thd, leaf_1)))
goto err;
field_name_1= nj_col_1->name();
is_using_column_1= using_fields &&
- test_if_string_in_list(field_name_1, using_fields);
+ test_if_string_in_list(field_name_1->str, using_fields);
DBUG_PRINT ("info", ("field_name_1=%s.%s",
nj_col_1->table_name() ? nj_col_1->table_name() : "",
- field_name_1));
+ field_name_1->str));
/*
Find a field with the same name in table_ref_2.
@@ -6380,14 +6379,14 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
for (it_2.set(table_ref_2); !it_2.end_of_fields(); it_2.next())
{
Natural_join_column *cur_nj_col_2;
- const char *cur_field_name_2;
+ const LEX_CSTRING *cur_field_name_2;
if (!(cur_nj_col_2= it_2.get_or_create_column_ref(thd, leaf_2)))
goto err;
cur_field_name_2= cur_nj_col_2->name();
DBUG_PRINT ("info", ("cur_field_name_2=%s.%s",
cur_nj_col_2->table_name() ?
cur_nj_col_2->table_name() : "",
- cur_field_name_2));
+ cur_field_name_2->str));
/*
Compare the two columns and check for duplicate common fields.
@@ -6400,13 +6399,14 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
here. These columns must be checked only on unqualified reference
by name (e.g. in SELECT list).
*/
- if (!my_strcasecmp(system_charset_info, field_name_1, cur_field_name_2))
+ if (!my_strcasecmp(system_charset_info, field_name_1->str,
+ cur_field_name_2->str))
{
DBUG_PRINT ("info", ("match c1.is_common=%d", nj_col_1->is_common));
if (cur_nj_col_2->is_common ||
(found && (!using_fields || is_using_column_1)))
{
- my_error(ER_NON_UNIQ_ERROR, MYF(0), field_name_1, thd->where);
+ my_error(ER_NON_UNIQ_ERROR, MYF(0), field_name_1->str, thd->where);
goto err;
}
nj_col_2= cur_nj_col_2;
@@ -6497,10 +6497,10 @@ mark_common_columns(THD *thd, TABLE_LIST *table_ref_1, TABLE_LIST *table_ref_2,
DBUG_PRINT ("info", ("%s.%s and %s.%s are common",
nj_col_1->table_name() ?
nj_col_1->table_name() : "",
- nj_col_1->name(),
+ nj_col_1->name()->str,
nj_col_2->table_name() ?
nj_col_2->table_name() : "",
- nj_col_2->name()));
+ nj_col_2->name()->str));
if (field_1)
{
@@ -6638,7 +6638,7 @@ store_natural_using_join_columns(THD *thd, TABLE_LIST *natural_using_join,
goto err;
}
if (!my_strcasecmp(system_charset_info,
- common_field->name(), using_field_name_ptr))
+ common_field->name()->str, using_field_name_ptr))
break; // Found match
}
}
@@ -6965,8 +6965,7 @@ int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields,
while (wild_num && (item= it++))
{
if (item->type() == Item::FIELD_ITEM &&
- ((Item_field*) item)->field_name &&
- ((Item_field*) item)->field_name[0] == '*' &&
+ ((Item_field*) item)->field_name.str == star_clex_str.str &&
!((Item_field*) item)->field)
{
uint elem= fields.elements;
@@ -7584,7 +7583,7 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
!(fld->have_privileges=
(get_column_grant(thd, field_iterator.grant(),
field_iterator.get_db_name(),
- field_table_name, fld->field_name) &
+ field_table_name, fld->field_name.str) &
VIEW_ANY_ACL)))
{
my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), "ANY",
@@ -7913,7 +7912,7 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
fld= (Item_field*)f++;
if (!(field= fld->field_for_view_update()))
{
- my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), fld->name);
+ my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), fld->name.str);
goto err;
}
DBUG_ASSERT(field->field->table == table_arg);
@@ -7925,7 +7924,7 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
{
if (!(field= fld->field_for_view_update()))
{
- my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), fld->name);
+ my_error(ER_NONUPDATEABLE_COLUMN, MYF(0), fld->name.str);
goto err;
}
value=v++;
@@ -7943,7 +7942,7 @@ fill_record(THD *thd, TABLE *table_arg, List<Item> &fields, List<Item> &values,
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN,
ER_THD(thd, ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN),
- rfield->field_name, table->s->table_name.str);
+ rfield->field_name.str, table->s->table_name.str);
}
if (rfield->stored_in_db() &&
(value->save_in_field(rfield, 0)) < 0 && !ignore_errors)
@@ -8188,7 +8187,7 @@ fill_record(THD *thd, TABLE *table, Field **ptr, List<Item> &values,
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN,
ER_THD(thd, ER_WARNING_NON_DEFAULT_VALUE_FOR_VIRTUAL_COLUMN),
- field->field_name, table->s->table_name.str);
+ field->field_name.str, table->s->table_name.str);
}
}
@@ -8452,7 +8451,7 @@ int init_ftfuncs(THD *thd, SELECT_LEX *select_lex, bool no_order)
}
-bool is_equal(const LEX_STRING *a, const LEX_STRING *b)
+bool is_equal(const LEX_CSTRING *a, const LEX_CSTRING *b)
{
return a->length == b->length && !strncmp(a->str, b->str, a->length);
}