mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-16630: Ambiguous error message when check constraint matches table name
One can create table with the same name for `field` and `table` `check` constraint. For example: `create table t(a int check(a>0), constraint a check(a>10));` But when inserting new rows same error is always raised. For example with ```insert into t values (-1);``` and ```insert into t values (10);``` same error `ER_CONSTRAINT_FAILED` is obtained and it is not clear which constraint is violated. This patch solve this error so that in case if field constraint is violated the first parameter in the error message is `table.field_name` and if table constraint is violated the first parameter in error message is `constraint_name`.
This commit is contained in:
committed by
Vicențiu-Marian Ciorbaru
parent
b71c9ae030
commit
8639e28808
12
sql/table.cc
12
sql/table.cc
@@ -5142,8 +5142,18 @@ int TABLE::verify_constraints(bool ignore_failure)
|
||||
if (((*chk)->expr->val_int() == 0 && !(*chk)->expr->null_value) ||
|
||||
in_use->is_error())
|
||||
{
|
||||
StringBuffer<MAX_FIELD_WIDTH> field_error(system_charset_info);
|
||||
enum_vcol_info_type vcol_type= (*chk)->get_vcol_type();
|
||||
DBUG_ASSERT(vcol_type == VCOL_CHECK_TABLE ||
|
||||
vcol_type == VCOL_CHECK_FIELD);
|
||||
if (vcol_type == VCOL_CHECK_FIELD)
|
||||
{
|
||||
field_error.append(s->table_name.str);
|
||||
field_error.append(".");
|
||||
}
|
||||
field_error.append((*chk)->name.str);
|
||||
my_error(ER_CONSTRAINT_FAILED,
|
||||
MYF(ignore_failure ? ME_JUST_WARNING : 0), (*chk)->name.str,
|
||||
MYF(ignore_failure ? ME_JUST_WARNING : 0), field_error.c_ptr(),
|
||||
s->db.str, s->table_name.str);
|
||||
return ignore_failure ? VIEW_CHECK_SKIP : VIEW_CHECK_ERROR;
|
||||
}
|
||||
|
Reference in New Issue
Block a user