mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
reduce code duplication a little
This commit is contained in:
@ -17,6 +17,7 @@
|
||||
#include "sql_priv.h"
|
||||
#include "unireg.h"
|
||||
#include "sql_base.h" // close_thread_tables
|
||||
#include "sql_parse.h"
|
||||
#include "event_db_repository.h"
|
||||
#include "key.h" // key_copy
|
||||
#include "sql_db.h" // get_default_db_collation
|
||||
@ -702,19 +703,17 @@ Event_db_repository::create_event(THD *thd, Event_parse_data *parse_data,
|
||||
|
||||
restore_record(table, s->default_values); // Get default values for fields
|
||||
|
||||
if (system_charset_info->cset->
|
||||
numchars(system_charset_info, parse_data->dbname.str,
|
||||
parse_data->dbname.str + parse_data->dbname.length) >
|
||||
table->field[ET_FIELD_DB]->char_length())
|
||||
if (check_string_char_length(&parse_data->dbname, 0,
|
||||
table->field[ET_FIELD_DB]->char_length(),
|
||||
system_charset_info, 1))
|
||||
{
|
||||
my_error(ER_TOO_LONG_IDENT, MYF(0), parse_data->dbname.str);
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (system_charset_info->cset->
|
||||
numchars(system_charset_info, parse_data->name.str,
|
||||
parse_data->name.str + parse_data->name.length) >
|
||||
table->field[ET_FIELD_NAME]->char_length())
|
||||
if (check_string_char_length(&parse_data->name, 0,
|
||||
table->field[ET_FIELD_NAME]->char_length(),
|
||||
system_charset_info, 1))
|
||||
{
|
||||
my_error(ER_TOO_LONG_IDENT, MYF(0), parse_data->name.str);
|
||||
goto end;
|
||||
|
@ -488,12 +488,8 @@ check_routine_name(LEX_STRING *ident)
|
||||
my_error(ER_SP_WRONG_NAME, MYF(0), ident->str);
|
||||
return TRUE;
|
||||
}
|
||||
if (check_string_char_length(ident, "", NAME_CHAR_LEN,
|
||||
system_charset_info, 1))
|
||||
{
|
||||
my_error(ER_TOO_LONG_IDENT, MYF(0), ident->str);
|
||||
if (check_ident_length(ident))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -4329,11 +4329,8 @@ create_sp_error:
|
||||
}
|
||||
case SQLCOM_SHOW_CREATE_TRIGGER:
|
||||
{
|
||||
if (lex->spname->m_name.length > NAME_LEN)
|
||||
{
|
||||
my_error(ER_TOO_LONG_IDENT, MYF(0), lex->spname->m_name.str);
|
||||
if (check_ident_length(&lex->spname->m_name))
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (show_create_trigger(thd, lex->spname))
|
||||
goto error; /* Error has been already logged. */
|
||||
@ -6019,12 +6016,9 @@ bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum_field_types type,
|
||||
LEX *lex= thd->lex;
|
||||
DBUG_ENTER("add_field_to_list");
|
||||
|
||||
if (check_string_char_length(field_name, "", NAME_CHAR_LEN,
|
||||
system_charset_info, 1))
|
||||
{
|
||||
my_error(ER_TOO_LONG_IDENT, MYF(0), field_name->str); /* purecov: inspected */
|
||||
if (check_ident_length(field_name))
|
||||
DBUG_RETURN(1); /* purecov: inspected */
|
||||
}
|
||||
|
||||
if (type_modifier & PRI_KEY_FLAG)
|
||||
{
|
||||
Key *key;
|
||||
@ -7688,6 +7682,17 @@ bool check_string_char_length(LEX_STRING *str, const char *err_msg,
|
||||
}
|
||||
|
||||
|
||||
bool check_ident_length(LEX_STRING *ident)
|
||||
{
|
||||
if (check_string_char_length(ident, 0, NAME_CHAR_LEN, system_charset_info, 1))
|
||||
{
|
||||
my_error(ER_TOO_LONG_IDENT, MYF(0), ident->str);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Check if path does not contain mysql data home directory
|
||||
|
||||
|
@ -75,6 +75,7 @@ bool check_string_byte_length(LEX_STRING *str, const char *err_msg,
|
||||
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
|
||||
uint max_char_length, CHARSET_INFO *cs,
|
||||
bool no_error);
|
||||
bool check_ident_length(LEX_STRING *ident);
|
||||
CHARSET_INFO* merge_charset_and_collation(CHARSET_INFO *cs, CHARSET_INFO *cl);
|
||||
bool check_host_name(LEX_STRING *str);
|
||||
bool check_identifier_name(LEX_STRING *str, uint max_char_length,
|
||||
|
@ -3312,12 +3312,8 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
|
||||
my_error(ER_TOO_MANY_KEY_PARTS,MYF(0),tmp);
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
if (check_string_char_length(&key->name, "", NAME_CHAR_LEN,
|
||||
system_charset_info, 1))
|
||||
{
|
||||
my_error(ER_TOO_LONG_IDENT, MYF(0), key->name.str);
|
||||
if (check_ident_length(&key->name))
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
key_iterator2.rewind ();
|
||||
if (key->type != Key::FOREIGN_KEY)
|
||||
{
|
||||
|
@ -455,12 +455,8 @@ int mysql_create_function(THD *thd,udf_func *udf)
|
||||
my_message(ER_UDF_NO_PATHS, ER(ER_UDF_NO_PATHS), MYF(0));
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
if (check_string_char_length(&udf->name, "", NAME_CHAR_LEN,
|
||||
system_charset_info, 1))
|
||||
{
|
||||
my_error(ER_TOO_LONG_IDENT, MYF(0), udf->name.str);
|
||||
if (check_ident_length(&udf->name))
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
|
||||
/*
|
||||
Turn off row binlogging of this statement and use statement-based
|
||||
|
@ -4670,12 +4670,8 @@ part_name:
|
||||
{
|
||||
partition_info *part_info= Lex->part_info;
|
||||
partition_element *p_elem= part_info->curr_part_elem;
|
||||
if (check_string_char_length(&$1, "", NAME_CHAR_LEN,
|
||||
system_charset_info, true))
|
||||
{
|
||||
my_error(ER_TOO_LONG_IDENT, MYF(0), $1.str);
|
||||
if (check_ident_length(&$1))
|
||||
MYSQL_YYABORT;
|
||||
}
|
||||
p_elem->partition_name= $1.str;
|
||||
}
|
||||
;
|
||||
@ -4971,12 +4967,8 @@ sub_part_definition:
|
||||
sub_name:
|
||||
ident_or_text
|
||||
{
|
||||
if (check_string_char_length(&$1, "", NAME_CHAR_LEN,
|
||||
system_charset_info, true))
|
||||
{
|
||||
my_error(ER_TOO_LONG_IDENT, MYF(0), $1.str);
|
||||
if (check_ident_length(&$1))
|
||||
MYSQL_YYABORT;
|
||||
}
|
||||
Lex->part_info->curr_part_elem->partition_name= $1.str;
|
||||
}
|
||||
;
|
||||
|
Reference in New Issue
Block a user