MCPcopy Create free account
hub / github.com/MariaDB/server / check

Method check

sql/table.cc:5553–5742  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5551*/
5552
5553bool
5554Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def)
5555{
5556 uint i;
5557 my_bool error= FALSE;
5558 const TABLE_FIELD_TYPE *field_def= table_def->field;
5559 DBUG_ENTER("table_check_intact");
5560 DBUG_PRINT("info",("table: %s expected_count: %d",
5561 table->alias.c_ptr(), table_def->count));
5562
5563 /* Whether the table definition has already been validated. */
5564 if (table->s->table_field_def_cache == table_def)
5565 goto end;
5566
5567 if (table->s->fields != table_def->count)
5568 {
5569 THD *thd= current_thd;
5570 DBUG_PRINT("info", ("Column count has changed, checking the definition"));
5571
5572 /* previous MySQL version */
5573 if (MYSQL_VERSION_ID > table->s->mysql_version)
5574 {
5575 report_error(ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE,
5576 ER_THD(thd, ER_COL_COUNT_DOESNT_MATCH_PLEASE_UPDATE),
5577 table->alias.c_ptr(), table_def->count, table->s->fields,
5578 static_cast<int>(table->s->mysql_version),
5579 MYSQL_VERSION_ID);
5580 DBUG_RETURN(TRUE);
5581 }
5582 else if (MYSQL_VERSION_ID == table->s->mysql_version)
5583 {
5584 report_error(ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2,
5585 ER_THD(thd, ER_COL_COUNT_DOESNT_MATCH_CORRUPTED_V2),
5586 table->s->db.str, table->s->table_name.str,
5587 table_def->count, table->s->fields);
5588 DBUG_RETURN(TRUE);
5589 }
5590 /*
5591 Something has definitely changed, but we're running an older
5592 version of MySQL with new system tables.
5593 Let's check column definitions. If a column was added at
5594 the end of the table, then we don't care much since such change
5595 is backward compatible.
5596 */
5597 }
5598 else
5599 {
5600 StringBuffer<1024> sql_type(system_charset_info);
5601 sql_type.extra_allocation(256); // Allocate min 256 characters at once
5602 for (i=0 ; i < table_def->count; i++, field_def++)
5603 {
5604 sql_type.length(0);
5605 if (i < table->s->fields)
5606 {
5607 Field *field= table->field[i];
5608
5609 if (strncmp(field->field_name.str, field_def->name.str,
5610 field_def->name.length))

Callers 15

ha_checkMethod · 0.45
vers_init_sys_fieldFunction · 0.45
do_checkMethod · 0.45
open_stat_tablesFunction · 0.45
fill_schema_eventsMethod · 0.45
open_event_tableMethod · 0.45
load_named_eventMethod · 0.45
check_system_tablesMethod · 0.45
check_accessFunction · 0.45

Calls 11

report_errorFunction · 0.85
extra_allocationMethod · 0.80
sql_print_warningFunction · 0.70
c_ptrMethod · 0.45
lengthMethod · 0.45
sql_typeMethod · 0.45
c_ptr_safeMethod · 0.45
has_charsetMethod · 0.45
charsetMethod · 0.45
typeMethod · 0.45
typelibMethod · 0.45

Tested by

no test coverage detected