Commit 84196617 authored by mskold@mysql.com's avatar mskold@mysql.com

Fix for bug#5312 Ndb Cluster returns wrong error code for duplicate key at insert

parent b0bac7d1
...@@ -11,7 +11,7 @@ insert into t1 (gesuchnr, benutzer_id) value (3,2); ...@@ -11,7 +11,7 @@ insert into t1 (gesuchnr, benutzer_id) value (3,2);
replace into t1 (gesuchnr,benutzer_id) values (1,1); replace into t1 (gesuchnr,benutzer_id) values (1,1);
replace into t1 (gesuchnr,benutzer_id) values (1,1); replace into t1 (gesuchnr,benutzer_id) values (1,1);
insert into t1 (gesuchnr,benutzer_id) values (1,1); insert into t1 (gesuchnr,benutzer_id) values (1,1);
ERROR 23000: Can't write; duplicate key in table 't1' ERROR 23000: Duplicate entry '1-1' for key 1
replace into t1 (gesuchnr,benutzer_id) values (1,1); replace into t1 (gesuchnr,benutzer_id) values (1,1);
select * from t1 order by gesuchnr; select * from t1 order by gesuchnr;
gesuchnr benutzer_id gesuchnr benutzer_id
......
...@@ -20,7 +20,7 @@ replace into t1 (gesuchnr,benutzer_id) values (1,1); ...@@ -20,7 +20,7 @@ replace into t1 (gesuchnr,benutzer_id) values (1,1);
insert into t1 (gesuchnr, benutzer_id) value (3,2); insert into t1 (gesuchnr, benutzer_id) value (3,2);
replace into t1 (gesuchnr,benutzer_id) values (1,1); replace into t1 (gesuchnr,benutzer_id) values (1,1);
replace into t1 (gesuchnr,benutzer_id) values (1,1); replace into t1 (gesuchnr,benutzer_id) values (1,1);
--error 1022 --error 1062
insert into t1 (gesuchnr,benutzer_id) values (1,1); insert into t1 (gesuchnr,benutzer_id) values (1,1);
replace into t1 (gesuchnr,benutzer_id) values (1,1); replace into t1 (gesuchnr,benutzer_id) values (1,1);
select * from t1 order by gesuchnr; select * from t1 order by gesuchnr;
......
...@@ -144,6 +144,7 @@ static int ndb_to_mysql_error(const NdbError *err) ...@@ -144,6 +144,7 @@ static int ndb_to_mysql_error(const NdbError *err)
int ha_ndbcluster::ndb_err(NdbConnection *trans) int ha_ndbcluster::ndb_err(NdbConnection *trans)
{ {
int res;
const NdbError err= trans->getNdbError(); const NdbError err= trans->getNdbError();
if (!err.code) if (!err.code)
return 0; // Don't log things to DBUG log if no error return 0; // Don't log things to DBUG log if no error
...@@ -161,7 +162,13 @@ int ha_ndbcluster::ndb_err(NdbConnection *trans) ...@@ -161,7 +162,13 @@ int ha_ndbcluster::ndb_err(NdbConnection *trans)
default: default:
break; break;
} }
DBUG_RETURN(ndb_to_mysql_error(&err)); res= ndb_to_mysql_error(&err);
DBUG_PRINT("info", ("transformed ndbcluster error %d to mysql error %d",
err.code, res));
if (res == HA_ERR_FOUND_DUPP_KEY)
dupkey= table->primary_key;
DBUG_RETURN(res);
} }
...@@ -2167,7 +2174,10 @@ void ha_ndbcluster::info(uint flag) ...@@ -2167,7 +2174,10 @@ void ha_ndbcluster::info(uint flag)
if (flag & HA_STATUS_VARIABLE) if (flag & HA_STATUS_VARIABLE)
DBUG_PRINT("info", ("HA_STATUS_VARIABLE")); DBUG_PRINT("info", ("HA_STATUS_VARIABLE"));
if (flag & HA_STATUS_ERRKEY) if (flag & HA_STATUS_ERRKEY)
{
DBUG_PRINT("info", ("HA_STATUS_ERRKEY")); DBUG_PRINT("info", ("HA_STATUS_ERRKEY"));
errkey= dupkey;
}
if (flag & HA_STATUS_AUTO) if (flag & HA_STATUS_AUTO)
DBUG_PRINT("info", ("HA_STATUS_AUTO")); DBUG_PRINT("info", ("HA_STATUS_AUTO"));
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
...@@ -2621,7 +2631,7 @@ int ndbcluster_commit(THD *thd, void *ndb_transaction) ...@@ -2621,7 +2631,7 @@ int ndbcluster_commit(THD *thd, void *ndb_transaction)
const NdbOperation *error_op= trans->getNdbErrorOperation(); const NdbOperation *error_op= trans->getNdbErrorOperation();
ERR_PRINT(err); ERR_PRINT(err);
res= ndb_to_mysql_error(&err); res= ndb_to_mysql_error(&err);
if (res != -1) if (res != -1)
ndbcluster_print_error(res, error_op); ndbcluster_print_error(res, error_op);
} }
ndb->closeTransaction(trans); ndb->closeTransaction(trans);
...@@ -3126,7 +3136,8 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg): ...@@ -3126,7 +3136,8 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg):
ops_pending(0), ops_pending(0),
skip_auto_increment(true), skip_auto_increment(true),
blobs_buffer(0), blobs_buffer(0),
blobs_buffer_size(0) blobs_buffer_size(0),
dupkey((uint) -1)
{ {
int i; int i;
......
...@@ -237,6 +237,7 @@ class ha_ndbcluster: public handler ...@@ -237,6 +237,7 @@ class ha_ndbcluster: public handler
// memory for blobs in one tuple // memory for blobs in one tuple
char *blobs_buffer; char *blobs_buffer;
uint32 blobs_buffer_size; uint32 blobs_buffer_size;
uint dupkey;
}; };
bool ndbcluster_init(void); bool ndbcluster_init(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment