summaryrefslogtreecommitdiff
path: root/sql/table.cc
diff options
context:
space:
mode:
authorAnel Husakovic <anelhusakovic88@gmail.com>2018-04-20 07:06:25 +0000
committerVicențiu-Marian Ciorbaru <cvicentiu@gmail.com>2018-07-01 22:32:55 +0300
commit8639e288086247ce39917f4cb55191c8bb5b5a8c (patch)
tree76e2ad53723f2507da133e2855033f8d2de2a3be /sql/table.cc
parentb71c9ae030ecafb31bc0b424a19d1354f2dd424b (diff)
downloadmariadb-git-8639e288086247ce39917f4cb55191c8bb5b5a8c.tar.gz
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`.
Diffstat (limited to 'sql/table.cc')
-rw-r--r--sql/table.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/sql/table.cc b/sql/table.cc
index 917d194047c..7cb84bcc5ea 100644
--- a/sql/table.cc
+++ b/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;
}