diff --git a/mysql-test/r/ndb_charset.result b/mysql-test/r/ndb_charset.result index 3763e20e59a..ff9ce7ee1a4 100644 --- a/mysql-test/r/ndb_charset.result +++ b/mysql-test/r/ndb_charset.result @@ -112,9 +112,9 @@ unique key(a) ) engine=ndb; insert into t1 values(1, 'aAa'); insert into t1 values(2, 'aaa'); -ERROR 23000: Duplicate entry '2' for key 1 +ERROR 23000: Duplicate entry '' for key 0 insert into t1 values(3, 'AAA'); -ERROR 23000: Duplicate entry '3' for key 1 +ERROR 23000: Duplicate entry '' for key 0 select * from t1 order by p; p a 1 aAa diff --git a/mysql-test/r/ndb_index_unique.result b/mysql-test/r/ndb_index_unique.result index 7864a5d1354..f2bb5e4ad53 100644 --- a/mysql-test/r/ndb_index_unique.result +++ b/mysql-test/r/ndb_index_unique.result @@ -22,7 +22,7 @@ select * from t1 where b = 4 order by a; a b c 3 4 6 insert into t1 values(8, 2, 3); -ERROR 23000: Duplicate entry '8' for key 1 +ERROR 23000: Duplicate entry '' for key 0 select * from t1 order by a; a b c 1 2 3 @@ -89,7 +89,7 @@ a b c 1 1 1 4 4 NULL insert into t1 values(5,1,1); -ERROR 23000: Duplicate entry '5' for key 1 +ERROR 23000: Duplicate entry '' for key 0 drop table t1; CREATE TABLE t2 ( a int unsigned NOT NULL PRIMARY KEY, @@ -112,7 +112,7 @@ select * from t2 where b = 4 order by a; a b c 3 4 6 insert into t2 values(8, 2, 3); -ERROR 23000: Duplicate entry '8' for key 1 +ERROR 23000: Duplicate entry '' for key 0 select * from t2 order by a; a b c 1 2 3 @@ -177,7 +177,7 @@ pk a 3 NULL 4 4 insert into t1 values (5,0); -ERROR 23000: Duplicate entry '5' for key 1 +ERROR 23000: Duplicate entry '' for key 0 select * from t1 order by pk; pk a -1 NULL @@ -210,7 +210,7 @@ pk a b c 0 NULL 18 NULL 1 3 19 abc insert into t2 values(2,3,19,'abc'); -ERROR 23000: Duplicate entry '2' for key 1 +ERROR 23000: Duplicate entry '' for key 0 select * from t2 order by pk; pk a b c -1 1 17 NULL diff --git a/mysql-test/r/ndb_update.result b/mysql-test/r/ndb_update.result index c2247564e65..164d1bd700c 100644 --- a/mysql-test/r/ndb_update.result +++ b/mysql-test/r/ndb_update.result @@ -18,7 +18,7 @@ pk1 b c 2 2 2 4 1 1 UPDATE t1 set pk1 = 1, c = 2 where pk1 = 4; -ERROR 23000: Duplicate entry '1' for key 1 +ERROR 23000: Duplicate entry '' for key 0 select * from t1 order by pk1; pk1 b c 0 0 0 diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 5a9d1e50fd7..f41e47e1b5d 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -551,7 +551,14 @@ int ha_ndbcluster::ndb_err(NdbTransaction *trans) if (res == HA_ERR_FOUND_DUPP_KEY) { if (m_rows_to_insert == 1) - m_dupkey= table->s->primary_key; + { + /* + We can only distinguish between primary and non-primary + violations here, so we need to return MAX_KEY for non-primary + to signal that key is unknown + */ + m_dupkey= err.code == 630 ? table->s->primary_key : MAX_KEY; + } else { /* We are batching inserts, offending key is not available */ diff --git a/sql/handler.cc b/sql/handler.cc index 4accc746664..c95102c4bc0 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1774,12 +1774,22 @@ void handler::print_error(int error, myf errflag) /* Write the dupplicated key in the error message */ char key[MAX_KEY_LENGTH]; String str(key,sizeof(key),system_charset_info); - key_unpack(&str,table,(uint) key_nr); - uint max_length=MYSQL_ERRMSG_SIZE-(uint) strlen(ER(ER_DUP_ENTRY)); - if (str.length() >= max_length) + + if (key_nr == MAX_KEY) { - str.length(max_length-4); - str.append(STRING_WITH_LEN("...")); + /* Key is unknown */ + str.length(0); + key_nr= -1; + } + else + { + key_unpack(&str,table,(uint) key_nr); + uint max_length=MYSQL_ERRMSG_SIZE-(uint) strlen(ER(ER_DUP_ENTRY)); + if (str.length() >= max_length) + { + str.length(max_length-4); + str.append(STRING_WITH_LEN("...")); + } } my_error(ER_DUP_ENTRY, MYF(0), str.c_ptr(), key_nr+1); DBUG_VOID_RETURN;