summaryrefslogtreecommitdiff
path: root/sql/sql_view.cc
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2017-04-23 19:39:57 +0300
committerMonty <monty@mariadb.org>2017-04-23 22:35:46 +0300
commit5a759d31f766087d5e135e1d3d3d987693bc9b88 (patch)
tree93c7359e8b211e269bfa73e5f595f34b9dca575a /sql/sql_view.cc
parentcba84469eb96481568a9f4ddf3f2989c49c9294c (diff)
downloadmariadb-git-5a759d31f766087d5e135e1d3d3d987693bc9b88.tar.gz
Changing field::field_name and Item::name to LEX_CSTRING
Benefits of this patch: - Removed a lot of calls to strlen(), especially for field_string - Strings generated by parser are now const strings, less chance of accidently changing a string - Removed a lot of calls with LEX_STRING as parameter (changed to pointer) - More uniform code - Item::name_length was not kept up to date. Now fixed - Several bugs found and fixed (Access to null pointers, access of freed memory, wrong arguments to printf like functions) - Removed a lot of casts from (const char*) to (char*) Changes: - This caused some ABI changes - lex_string_set now uses LEX_CSTRING - Some fucntions are now taking const char* instead of char* - Create_field::change and after changed to LEX_CSTRING - handler::connect_string, comment and engine_name() changed to LEX_CSTRING - Checked printf() related calls to find bugs. Found and fixed several errors in old code. - A lot of changes from LEX_STRING to LEX_CSTRING, especially related to parsing and events. - Some changes from LEX_STRING and LEX_STRING & to LEX_CSTRING* - Some changes for char* to const char* - Added printf argument checking for my_snprintf() - Introduced null_clex_str, star_clex_string, temp_lex_str to simplify code - Added item_empty_name and item_used_name to be able to distingush between items that was given an empty name and items that was not given a name This is used in sql_yacc.yy to know when to give an item a name. - select table_name."*' is not anymore same as table_name.* - removed not used function Item::rename() - Added comparision of item->name_length before some calls to my_strcasecmp() to speed up comparison - Moved Item_sp_variable::make_field() from item.h to item.cc - Some minimal code changes to avoid copying to const char * - Fixed wrong error message in wsrep_mysql_parse() - Fixed wrong code in find_field_in_natural_join() where real_item() was set when it shouldn't - ER_ERROR_ON_RENAME was used with extra arguments. - Removed some (wrong) ER_OUTOFMEMORY, as alloc_root will already give the error. TODO: - Check possible unsafe casts in plugin/auth_examples/qa_auth_interface.c - Change code to not modify LEX_CSTRING for database name (as part of lower_case_table_names)
Diffstat (limited to 'sql/sql_view.cc')
-rw-r--r--sql/sql_view.cc71
1 files changed, 36 insertions, 35 deletions
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 1d6fe38b66b..447d80b8b00 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -39,7 +39,7 @@
#define MD5_BUFF_LENGTH 33
-const LEX_STRING view_type= { C_STRING_WITH_LEN("VIEW") };
+const LEX_CSTRING view_type= { STRING_WITH_LEN("VIEW") };
static int mysql_register_view(THD *, TABLE_LIST *, enum_view_create_mode);
@@ -63,9 +63,9 @@ static void make_unique_view_field_name(THD *thd, Item *target,
List<Item> &item_list,
Item *last_element)
{
- char *name= (target->orig_name ?
- target->orig_name :
- target->name);
+ const char *name= (target->orig_name ?
+ target->orig_name :
+ target->name.str);
size_t name_len;
uint attempt;
char buff[NAME_LEN+1];
@@ -85,7 +85,7 @@ static void make_unique_view_field_name(THD *thd, Item *target,
{
check= itc++;
if (check != target &&
- my_strcasecmp(system_charset_info, buff, check->name) == 0)
+ my_strcasecmp(system_charset_info, buff, check->name.str) == 0)
{
ok= FALSE;
break;
@@ -96,7 +96,7 @@ static void make_unique_view_field_name(THD *thd, Item *target,
itc.rewind();
}
- target->orig_name= target->name;
+ target->orig_name= target->name.str;
target->set_name(thd, buff, name_len, system_charset_info);
}
@@ -140,7 +140,7 @@ bool check_duplicate_names(THD *thd, List<Item> &item_list, bool gen_unique_view
itc.rewind();
while ((check= itc++) && check != item)
{
- if (my_strcasecmp(system_charset_info, item->name, check->name) == 0)
+ if (my_strcasecmp(system_charset_info, item->name.str, check->name.str) == 0)
{
if (!gen_unique_view_name)
goto err;
@@ -178,10 +178,10 @@ void make_valid_column_names(THD *thd, List<Item> &item_list)
for (uint column_no= 1; (item= it++); column_no++)
{
- if (!item->is_autogenerated_name || !check_column_name(item->name))
+ if (!item->is_autogenerated_name || !check_column_name(item->name.str))
continue;
name_len= my_snprintf(buff, NAME_LEN, "Name_exp_%u", column_no);
- item->orig_name= item->name;
+ item->orig_name= item->name.str;
item->set_name(thd, buff, name_len, system_charset_info);
}
@@ -602,7 +602,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
{
Item_field *fld= item->field_for_view_update();
uint priv= (get_column_grant(thd, &view->grant, view->db,
- view->table_name, item->name) &
+ view->table_name, item->name.str) &
VIEW_ANY_ACL);
if (fld && !fld->field->table->s->tmp_table)
@@ -620,7 +620,7 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
{
my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0),
"create view", thd->security_ctx->priv_user,
- thd->security_ctx->priv_host, report_item->name,
+ thd->security_ctx->priv_host, report_item->name.str,
view->table_name);
res= TRUE;
goto err;
@@ -711,11 +711,11 @@ err:
}
-static void make_view_filename(LEX_STRING *dir, char *dir_buff,
+static void make_view_filename(LEX_CSTRING *dir, char *dir_buff,
size_t dir_buff_len,
- LEX_STRING *path, char *path_buff,
+ LEX_CSTRING *path, char *path_buff,
size_t path_buff_len,
- LEX_STRING *file,
+ LEX_CSTRING *file,
TABLE_LIST *view)
{
/* print file name */
@@ -741,37 +741,37 @@ static const int required_view_parameters= 15;
parse()
*/
static File_option view_parameters[]=
-{{{ C_STRING_WITH_LEN("query")},
+{{{ STRING_WITH_LEN("query")},
my_offsetof(TABLE_LIST, select_stmt),
FILE_OPTIONS_ESTRING},
- {{ C_STRING_WITH_LEN("md5")},
+ {{ STRING_WITH_LEN("md5")},
my_offsetof(TABLE_LIST, md5),
FILE_OPTIONS_STRING},
- {{ C_STRING_WITH_LEN("updatable")},
+ {{ STRING_WITH_LEN("updatable")},
my_offsetof(TABLE_LIST, updatable_view),
FILE_OPTIONS_ULONGLONG},
- {{ C_STRING_WITH_LEN("algorithm")},
+ {{ STRING_WITH_LEN("algorithm")},
my_offsetof(TABLE_LIST, algorithm),
FILE_OPTIONS_VIEW_ALGO},
- {{ C_STRING_WITH_LEN("definer_user")},
+ {{ STRING_WITH_LEN("definer_user")},
my_offsetof(TABLE_LIST, definer.user),
FILE_OPTIONS_STRING},
- {{ C_STRING_WITH_LEN("definer_host")},
+ {{ STRING_WITH_LEN("definer_host")},
my_offsetof(TABLE_LIST, definer.host),
FILE_OPTIONS_STRING},
- {{ C_STRING_WITH_LEN("suid")},
+ {{ STRING_WITH_LEN("suid")},
my_offsetof(TABLE_LIST, view_suid),
FILE_OPTIONS_ULONGLONG},
- {{ C_STRING_WITH_LEN("with_check_option")},
+ {{ STRING_WITH_LEN("with_check_option")},
my_offsetof(TABLE_LIST, with_check),
FILE_OPTIONS_ULONGLONG},
- {{ C_STRING_WITH_LEN("timestamp")},
+ {{ STRING_WITH_LEN("timestamp")},
my_offsetof(TABLE_LIST, timestamp),
FILE_OPTIONS_TIMESTAMP},
- {{ C_STRING_WITH_LEN("create-version")},
+ {{ STRING_WITH_LEN("create-version")},
my_offsetof(TABLE_LIST, file_version),
FILE_OPTIONS_ULONGLONG},
- {{ C_STRING_WITH_LEN("source")},
+ {{ STRING_WITH_LEN("source")},
my_offsetof(TABLE_LIST, source),
FILE_OPTIONS_ESTRING},
{{(char*) STRING_WITH_LEN("client_cs_name")},
@@ -783,21 +783,21 @@ static File_option view_parameters[]=
{{(char*) STRING_WITH_LEN("view_body_utf8")},
my_offsetof(TABLE_LIST, view_body_utf8),
FILE_OPTIONS_ESTRING},
- {{ C_STRING_WITH_LEN("mariadb-version")},
+ {{ STRING_WITH_LEN("mariadb-version")},
my_offsetof(TABLE_LIST, mariadb_version),
FILE_OPTIONS_ULONGLONG},
{{NullS, 0}, 0,
FILE_OPTIONS_STRING}
};
-static LEX_STRING view_file_type[]= {{(char*) STRING_WITH_LEN("VIEW") }};
+static LEX_CSTRING view_file_type[]= {{STRING_WITH_LEN("VIEW") }};
int mariadb_fix_view(THD *thd, TABLE_LIST *view, bool wrong_checksum,
bool swap_alg)
{
char dir_buff[FN_REFLEN + 1], path_buff[FN_REFLEN + 1];
- LEX_STRING dir, file, path;
+ LEX_CSTRING dir, file, path;
DBUG_ENTER("mariadb_fix_view");
if (!wrong_checksum && view->mariadb_version)
@@ -912,7 +912,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
char md5[MD5_BUFF_LENGTH];
bool can_be_merged;
char dir_buff[FN_REFLEN + 1], path_buff[FN_REFLEN + 1];
- LEX_STRING dir, file, path;
+ LEX_CSTRING dir, file, path;
int error= 0;
DBUG_ENTER("mysql_register_view");
@@ -1014,7 +1014,7 @@ loop_out:
/* check old .frm */
{
char path_buff[FN_REFLEN];
- LEX_STRING path;
+ LEX_CSTRING path;
File_parser *parser;
path.str= path_buff;
@@ -1333,7 +1333,7 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table,
{
char old_db_buf[SAFE_NAME_LEN+1];
- LEX_STRING old_db= { old_db_buf, sizeof(old_db_buf) };
+ LEX_CSTRING old_db= { old_db_buf, sizeof(old_db_buf) };
bool dbchanged;
Parser_state parser_state;
if (parser_state.init(thd, table->select_stmt.str,
@@ -1344,7 +1344,8 @@ bool mysql_make_view(THD *thd, TABLE_SHARE *share, TABLE_LIST *table,
Use view db name as thread default database, in order to ensure
that the view is parsed and prepared correctly.
*/
- if ((result= mysql_opt_change_db(thd, &table->view_db, &old_db, 1,
+ if ((result= mysql_opt_change_db(thd, &table->view_db,
+ (LEX_STRING*) &old_db, 1,
&dbchanged)))
goto end;
@@ -1772,7 +1773,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
char path[FN_REFLEN + 1];
TABLE_LIST *view;
String non_existant_views;
- char *wrong_object_db= NULL, *wrong_object_name= NULL;
+ const char *wrong_object_db= NULL, *wrong_object_name= NULL;
bool error= FALSE;
bool some_views_deleted= FALSE;
bool something_wrong= FALSE;
@@ -2137,7 +2138,7 @@ mysql_rename_view(THD *thd,
const char *new_name,
TABLE_LIST *view)
{
- LEX_STRING pathstr;
+ LEX_CSTRING pathstr;
File_parser *parser;
char path_buff[FN_REFLEN + 1];
bool error= TRUE;
@@ -2153,7 +2154,7 @@ mysql_rename_view(THD *thd,
{
TABLE_LIST view_def;
char dir_buff[FN_REFLEN + 1];
- LEX_STRING dir, file;
+ LEX_CSTRING dir, file;
/*
To be PS-friendly we should either to restore state of