summaryrefslogtreecommitdiff
path: root/sql/sql_show.cc
diff options
context:
space:
mode:
authorAnel Husakovic <anel@mariadb.org>2018-04-03 12:41:13 +0000
committerVicențiu Ciorbaru <vicentiu@mariadb.org>2018-08-25 17:03:20 +0300
commitd526679efd108478cc2af07578a15434fb46ed85 (patch)
tree0551593e16f022706d78d480cc5c0a099959c2ac /sql/sql_show.cc
parent7f73f5e4e5bdae80561ff2596f5142965397a1b1 (diff)
downloadmariadb-git-d526679efd108478cc2af07578a15434fb46ed85.tar.gz
MDEV-14474 information_schema.check_constraints
Implement according to standard SQL specification 2008. The check_constraints table is used for fetching metadata about the constraints defined for tables in all databases.
Diffstat (limited to 'sql/sql_show.cc')
-rw-r--r--sql/sql_show.cc50
1 files changed, 50 insertions, 0 deletions
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 05a1cce4175..6feaafbe0c7 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -6788,6 +6788,42 @@ store_constraints(THD *thd, TABLE *table, const LEX_CSTRING *db_name,
return schema_table_store_record(thd, table);
}
+static int get_check_constraints_record(THD *thd, TABLE_LIST *tables,
+ TABLE *table, bool res,
+ const LEX_CSTRING *db_name,
+ const LEX_CSTRING *table_name)
+{
+ DBUG_ENTER("get_check_constraints_record");
+ if (res)
+ {
+ if (thd->is_error())
+ push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
+ thd->get_stmt_da()->sql_errno(),
+ thd->get_stmt_da()->message());
+ thd->clear_error();
+ DBUG_RETURN(0);
+ }
+ else if (!tables->view)
+ {
+ if (tables->table->s->table_check_constraints)
+ {
+ for (uint i= 0; i < tables->table->s->table_check_constraints; i++)
+ {
+ StringBuffer<MAX_FIELD_WIDTH> str(system_charset_info);
+ Virtual_column_info *check= tables->table->check_constraints[i];
+ restore_record(table, s->default_values);
+ table->field[0]->store(STRING_WITH_LEN("def"), system_charset_info);
+ table->field[1]->store(db_name->str, db_name->length, system_charset_info);
+ table->field[2]->store(check->name.str, check->name.length, system_charset_info);
+ table->field[3]->store(table_name->str, table_name->length, system_charset_info);
+ check->print(&str);
+ table->field[4]->store(str.ptr(), str.length(), system_charset_info);
+ schema_table_store_record(thd, table);
+ }
+ }
+ }
+ DBUG_RETURN(res);
+}
static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables,
TABLE *table, bool res,
@@ -9708,6 +9744,18 @@ ST_FIELD_INFO spatial_ref_sys_fields_info[]=
#endif /*HAVE_SPATIAL*/
+ST_FIELD_INFO check_constraints_fields_info[]=
+{
+ {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
+ {"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
+ OPEN_FULL_TABLE},
+ {"CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
+ OPEN_FULL_TABLE},
+ {"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
+ {"CHECK_CLAUSE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
+ OPEN_FULL_TABLE},
+ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
+};
/*
Description of ST_FIELD_INFO in table.h
@@ -9723,6 +9771,8 @@ ST_SCHEMA_TABLE schema_tables[]=
fill_schema_applicable_roles, 0, 0, -1, -1, 0, 0},
{"CHARACTER_SETS", charsets_fields_info, 0,
fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0, 0},
+ {"CHECK_CONSTRAINTS", check_constraints_fields_info, 0,
+ get_all_tables, 0, get_check_constraints_record, 1, 2, 0, OPTIMIZE_I_S_TABLE|OPEN_TABLE_ONLY},
{"COLLATIONS", collation_fields_info, 0,
fill_schema_collation, make_old_format, 0, -1, -1, 0, 0},
{"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,