Skip to content

Commit

Permalink
cleanup: add store_yesno() for fields that can only take "YES"/"NO" v…
Browse files Browse the repository at this point in the history
…alues
  • Loading branch information
FooBarrior authored and sanja-byelkin committed Feb 12, 2024
1 parent 711b867 commit 8a88282
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions sql/sql_show.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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" :
Expand Down Expand Up @@ -6423,25 +6429,20 @@ 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);

table->field[0]->store(name->str, name->length, scs);
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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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, "@",
Expand Down

0 comments on commit 8a88282

Please sign in to comment.