mirror of
https://github.com/MariaDB/server.git
synced 2025-01-15 19:42:28 +01:00
cleanup: engine_option_value::Value::find_in_list() helper
This commit is contained in:
parent
d046aca0c7
commit
115d3e050c
2 changed files with 30 additions and 42 deletions
|
@ -27,6 +27,8 @@
|
|||
|
||||
#define FRM_QUOTED_VALUE 0x8000U
|
||||
|
||||
static const char *bools="NO,OFF,0,YES,ON,1";
|
||||
|
||||
/**
|
||||
Links this item to the given list end
|
||||
|
||||
|
@ -44,8 +46,7 @@ void engine_option_value::link(engine_option_value **start,
|
|||
engine_option_value *opt;
|
||||
/* check duplicates to avoid writing them to frm*/
|
||||
for(opt= *start;
|
||||
opt && ((opt->parsed && !opt->value.str) ||
|
||||
!name.streq(opt->name));
|
||||
opt && ((opt->parsed && !opt->value.str) || !name.streq(opt->name));
|
||||
opt= opt->next) /* no-op */;
|
||||
if (opt)
|
||||
{
|
||||
|
@ -117,16 +118,13 @@ static bool report_unknown_option(THD *thd, engine_option_value *val,
|
|||
|
||||
#define value_ptr(STRUCT,OPT) ((char*)(STRUCT) + (OPT)->offset)
|
||||
|
||||
static bool set_one_value(ha_create_table_option *opt,
|
||||
THD *thd, const engine_option_value::Value *value,
|
||||
void *base,
|
||||
bool suppress_warning,
|
||||
MEM_ROOT *root)
|
||||
static bool set_one_value(ha_create_table_option *opt, THD *thd,
|
||||
const engine_option_value::Value *value, void *base,
|
||||
bool suppress_warning, MEM_ROOT *root)
|
||||
{
|
||||
DBUG_ENTER("set_one_value");
|
||||
DBUG_PRINT("enter", ("opt: %p type: %u name '%s' value: '%s'",
|
||||
opt,
|
||||
opt->type, opt->name,
|
||||
opt, opt->type, opt->name,
|
||||
(value->str ? value->str : "<DEFAULT>")));
|
||||
switch (opt->type)
|
||||
{
|
||||
|
@ -142,10 +140,9 @@ static bool set_one_value(ha_create_table_option *opt,
|
|||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
my_option optp=
|
||||
{ opt->name, 1, 0, (uchar **)val, 0, 0, GET_ULL,
|
||||
my_option optp= { opt->name, 1, 0, (uchar **)val, 0, 0, GET_ULL,
|
||||
REQUIRED_ARG, (longlong)opt->def_value, (longlong)opt->min_value,
|
||||
opt->max_value, 0, (long) opt->block_size, 0};
|
||||
opt->max_value, 0, (long) opt->block_size, 0 };
|
||||
|
||||
ulonglong orig_val= strtoull(value->str, NULL, 10);
|
||||
my_bool unused;
|
||||
|
@ -172,29 +169,17 @@ static bool set_one_value(ha_create_table_option *opt,
|
|||
}
|
||||
case HA_OPTION_TYPE_ENUM:
|
||||
{
|
||||
uint *val= (uint *)value_ptr(base, opt), num;
|
||||
uint *val= (uint *)value_ptr(base, opt);
|
||||
|
||||
*val= (uint) opt->def_value;
|
||||
if (!value->str)
|
||||
DBUG_RETURN(0);
|
||||
|
||||
const char *start= opt->values, *end;
|
||||
|
||||
num= 0;
|
||||
while (*start)
|
||||
uint num= value->find_in_list(opt->values);
|
||||
if (num != UINT_MAX)
|
||||
{
|
||||
for (end=start;
|
||||
*end && *end != ',';
|
||||
end++) /* no-op */;
|
||||
if (value->streq(Lex_cstring(start, end)))
|
||||
{
|
||||
*val= num;
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
if (*end)
|
||||
end++;
|
||||
start= end;
|
||||
num++;
|
||||
*val= num;
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
DBUG_RETURN(report_wrong_value(thd, opt->name, value->str,
|
||||
|
@ -208,20 +193,11 @@ static bool set_one_value(ha_create_table_option *opt,
|
|||
if (!value->str)
|
||||
DBUG_RETURN(0);
|
||||
|
||||
if (value->streq("NO"_LEX_CSTRING) ||
|
||||
value->streq("OFF"_LEX_CSTRING) ||
|
||||
value->streq("0"_LEX_CSTRING))
|
||||
uint num= value->find_in_list(bools);
|
||||
if (num != UINT_MAX)
|
||||
{
|
||||
*val= FALSE;
|
||||
DBUG_RETURN(FALSE);
|
||||
}
|
||||
|
||||
if (value->streq("YES"_LEX_CSTRING) ||
|
||||
value->streq("ON"_LEX_CSTRING) ||
|
||||
value->streq("1"_LEX_CSTRING))
|
||||
{
|
||||
*val= TRUE;
|
||||
DBUG_RETURN(FALSE);
|
||||
*val= num > 2;
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
DBUG_RETURN(report_wrong_value(thd, opt->name, value->str,
|
||||
|
|
|
@ -46,6 +46,18 @@ public:
|
|||
{
|
||||
return my_charset_utf8mb3_general1400_as_ci.streq(*this, rhs);
|
||||
}
|
||||
uint find_in_list(const char *str) const
|
||||
{
|
||||
const char *end= str;
|
||||
for (int num= 0; *end; num++)
|
||||
{
|
||||
for (end=str; *end && *end != ','; end++) /* no-op */;
|
||||
if (streq(Lex_cstring(str, end)))
|
||||
return num;
|
||||
str= end + 1;
|
||||
}
|
||||
return UINT_MAX;
|
||||
}
|
||||
};
|
||||
public:
|
||||
Name name;
|
||||
|
|
Loading…
Reference in a new issue