Commit 851e3cab authored by unknown's avatar unknown

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

parent e9a85134
......@@ -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);
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);
select * from t1 order by gesuchnr;
gesuchnr benutzer_id
......
......@@ -20,7 +20,7 @@ replace into t1 (gesuchnr,benutzer_id) values (1,1);
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);
--error 1022
--error 1062
insert into t1 (gesuchnr,benutzer_id) values (1,1);
replace into t1 (gesuchnr,benutzer_id) values (1,1);
select * from t1 order by gesuchnr;
......
......@@ -144,6 +144,7 @@ static int ndb_to_mysql_error(const NdbError *err)
int ha_ndbcluster::ndb_err(NdbConnection *trans)
{
int res;
const NdbError err= trans->getNdbError();
if (!err.code)
return 0; // Don't log things to DBUG log if no error
......@@ -161,7 +162,13 @@ int ha_ndbcluster::ndb_err(NdbConnection *trans)
default:
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)
if (flag & HA_STATUS_VARIABLE)
DBUG_PRINT("info", ("HA_STATUS_VARIABLE"));
if (flag & HA_STATUS_ERRKEY)
{
DBUG_PRINT("info", ("HA_STATUS_ERRKEY"));
errkey= dupkey;
}
if (flag & HA_STATUS_AUTO)
DBUG_PRINT("info", ("HA_STATUS_AUTO"));
DBUG_VOID_RETURN;
......@@ -2621,7 +2631,7 @@ int ndbcluster_commit(THD *thd, void *ndb_transaction)
const NdbOperation *error_op= trans->getNdbErrorOperation();
ERR_PRINT(err);
res= ndb_to_mysql_error(&err);
if (res != -1)
if (res != -1)
ndbcluster_print_error(res, error_op);
}
ndb->closeTransaction(trans);
......@@ -3126,7 +3136,8 @@ ha_ndbcluster::ha_ndbcluster(TABLE *table_arg):
ops_pending(0),
skip_auto_increment(true),
blobs_buffer(0),
blobs_buffer_size(0)
blobs_buffer_size(0),
dupkey((uint) -1)
{
int i;
......
......@@ -237,6 +237,7 @@ class ha_ndbcluster: public handler
// memory for blobs in one tuple
char *blobs_buffer;
uint32 blobs_buffer_size;
uint dupkey;
};
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