Commit 8a882827 authored by Nikita Malyavin's avatar Nikita Malyavin Committed by Oleksandr Byelkin

cleanup: add store_yesno() for fields that can only take "YES"/"NO" values

parent 711b8671
......@@ -5626,6 +5626,14 @@ int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
}
static int store_yesno(Field *field, bool predicate)
{
static const LEX_CSTRING yes{STRING_WITH_LEN("YES")};
static const LEX_CSTRING no {STRING_WITH_LEN("NO")};
return field->store(predicate ? yes : no, system_charset_info);
}
static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
TABLE *table, bool res,
const LEX_CSTRING *db_name,
......@@ -6285,9 +6293,7 @@ static int get_schema_column_record(THD *thd, TABLE_LIST *tables,
table->field[5]->store(type.ptr(), type.length(), cs);
table->field[5]->set_notnull();
}
pos=(uchar*) ((field->flags & NOT_NULL_FLAG) ? "NO" : "YES");
table->field[6]->store((const char*) pos,
strlen((const char*) pos), cs);
store_yesno(table->field[6], (field->flags & NOT_NULL_FLAG) == 0);
store_column_type(table, field, cs, 7);
pos=(uchar*) ((field->flags & PRI_KEY_FLAG) ? "PRI" :
(field->flags & UNIQUE_KEY_FLAG) ? "UNI" :
......@@ -6423,10 +6429,7 @@ static my_bool iter_schema_engines(THD *thd, plugin_ref plugin,
if (!(wild && wild[0] &&
wild_case_compare(scs, name->str,wild)))
{
LEX_CSTRING yesno[2]= {{ STRING_WITH_LEN("NO") },
{ STRING_WITH_LEN("YES") }};
LEX_CSTRING *tmp;
const char *option_name= default_type != hton ? yesno[1].str
const char *option_name= default_type != hton ? "YES"
: "DEFAULT";
restore_record(table, s->default_values);
......@@ -6434,14 +6437,12 @@ static my_bool iter_schema_engines(THD *thd, plugin_ref plugin,
table->field[1]->store(option_name, strlen(option_name), scs);
table->field[2]->store(plugin_decl(plugin)->descr,
strlen(plugin_decl(plugin)->descr), scs);
tmp= &yesno[MY_TEST(hton->commit && !(hton->flags & HTON_NO_ROLLBACK))];
table->field[3]->store(tmp->str, tmp->length, scs);
store_yesno(table->field[3],
hton->commit && !(hton->flags & HTON_NO_ROLLBACK));
table->field[3]->set_notnull();
tmp= &yesno[MY_TEST(hton->prepare)];
table->field[4]->store(tmp->str, tmp->length, scs);
store_yesno(table->field[4], hton->prepare);
table->field[4]->set_notnull();
tmp= &yesno[MY_TEST(hton->savepoint_set)];
table->field[5]->store(tmp->str, tmp->length, scs);
store_yesno(table->field[5], hton->savepoint_set);
table->field[5]->set_notnull();
if (schema_table_store_record(thd, table))
......@@ -7187,8 +7188,7 @@ static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
key_info->comment.length, cs);
// IGNORED column
const char *is_ignored= key_info->is_ignored ? "YES" : "NO";
table->field[16]->store(is_ignored, strlen(is_ignored), cs);
store_yesno(table->field[16], key_info->is_ignored);
table->field[16]->set_notnull();
if (schema_table_store_record(thd, table))
......@@ -7307,10 +7307,7 @@ static int get_schema_views_record(THD *thd, TABLE_LIST *tables,
if (updatable_view && !tables->view->can_be_merged())
updatable_view= 0;
}
if (updatable_view)
table->field[5]->store(STRING_WITH_LEN("YES"), cs);
else
table->field[5]->store(STRING_WITH_LEN("NO"), cs);
store_yesno(table->field[5], updatable_view);
}
definer_len= (uint)(strxmov(definer, tables->definer.user.str, "@",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment