[Groonga-mysql-commit] mroonga/mroonga [master] upgrade error message for duplicated key error.

Back to archive index

null+****@clear***** null+****@clear*****
2011年 1月 13日 (木) 14:48:19 JST


Tetsuro IKEDA	2011-01-13 05:48:19 +0000 (Thu, 13 Jan 2011)

  New Revision: 3290f8ef97751a842b8086b7ad7572d43936dc3c

  Log:
    upgrade error message for duplicated key error.

  Modified files:
    ha_mroonga.cc
    ha_mroonga.h
    test/sql/r/insert.result
    test/sql/t/insert.test

  Modified: ha_mroonga.cc (+11 -4)
===================================================================
--- ha_mroonga.cc    2011-01-13 03:56:37 +0000 (1c5e0c3)
+++ ha_mroonga.cc    2011-01-13 05:48:19 +0000 (2be2a77)
@@ -875,7 +875,8 @@ ulonglong ha_mroonga_table_flags =
     HA_NO_AUTO_INCREMENT |
     HA_CAN_INSERT_DELAYED |
     HA_BINLOG_FLAGS |
-    HA_CAN_BIT_FIELD;
+    HA_CAN_BIT_FIELD |
+    HA_DUPLICATE_POS;
     //HA_HAS_RECORDS;
 
 ulonglong ha_mroonga::table_flags() const
@@ -1339,6 +1340,11 @@ int ha_mroonga::info(uint flag)
   DBUG_ENTER("ha_mroonga::info");
   ha_rows rows = grn_table_size(ctx, tbl);
   stats.records = rows;
+
+  if (flag & (HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK)) {
+    errkey = dup_key;
+  }
+
   DBUG_RETURN(0);
 }
 
@@ -1476,9 +1482,10 @@ int ha_mroonga::write_row(uchar *buf)
 #ifndef DBUG_OFF
     dbug_tmp_restore_column_map(table->read_set, tmp_map);
 #endif
+    memcpy(dup_ref, &row_id, sizeof(grn_id));
+    dup_key = pkeynr;
     GRN_LOG(ctx, GRN_LOG_ERROR, "duplicated _id on insert");
-    my_message(ER_DUP_UNIQUE, "duplicated _id on insert", MYF(0));
-    DBUG_RETURN(ER_DUP_UNIQUE);
+    DBUG_RETURN(HA_ERR_FOUND_DUPP_KEY);
   }
 
   grn_obj colbuf;
@@ -2536,7 +2543,7 @@ void ha_mroonga::store_fields_from_primary_table(uchar *buf, grn_id rid)
 
 int ha_mroonga::reset()
 {
-  DBUG_ENTER("ha_mroonga::reset()");
+  DBUG_ENTER("ha_mroonga::reset");
   if (sort_keys != NULL) {
     free(sort_keys);
     sort_keys = NULL;

  Modified: ha_mroonga.h (+1 -0)
===================================================================
--- ha_mroonga.h    2011-01-13 03:56:37 +0000 (737e3b9)
+++ ha_mroonga.h    2011-01-13 05:48:19 +0000 (311075e)
@@ -90,6 +90,7 @@ class ha_mroonga: public handler
   char **key_max;
   int *key_min_len;
   int *key_max_len;
+  uint dup_key;
 
   longlong limit;
   grn_table_sort_key *sort_keys;

  Modified: test/sql/r/insert.result (+11 -0)
===================================================================
--- test/sql/r/insert.result    2011-01-13 03:56:37 +0000 (8145920)
+++ test/sql/r/insert.result    2011-01-13 05:48:19 +0000 (80257b2)
@@ -90,3 +90,14 @@ c1	_id	_score
 2	2	0
 3	3	0
 drop table t1;
+create table t1 (c1 int primary key, c2 int);
+insert into t1 values(1,100);
+select * from t1;
+c1	c2
+1	100
+insert into t1 values(1,200);
+ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
+select * from t1;
+c1	c2
+1	100
+drop table t1;

  Modified: test/sql/t/insert.test (+10 -0)
===================================================================
--- test/sql/t/insert.test    2011-01-13 03:56:37 +0000 (65f8650)
+++ test/sql/t/insert.test    2011-01-13 05:48:19 +0000 (feec3ec)
@@ -96,4 +96,14 @@ insert into t1 (c1,_id,_score) values (6,1,2);
 select * from t1;
 drop table t1;
 
+
+# duplicated key error
+create table t1 (c1 int primary key, c2 int);
+insert into t1 values(1,100);
+select * from t1;
+--error 1062
+insert into t1 values(1,200);
+select * from t1;
+drop table t1;
+
 --source suite/groonga/include/groonga_deinit.inc




Groonga-mysql-commit メーリングリストの案内
Back to archive index