From dec0720a80fc4f72a067c2916b119321b4e87a9d Mon Sep 17 00:00:00 2001
From: "holyfoot@deer.(none)" <>
Date: Thu, 15 Dec 2005 16:20:56 +0400
Subject: [PATCH] bug #15524 (partitioning range/list violation error message
 is insufficient)

---
 include/my_base.h                   | 3 ++-
 mysql-test/r/partition_error.result | 5 +++++
 mysql-test/t/partition_error.test   | 8 ++++++++
 sql/ha_partition.cc                 | 8 ++++++--
 sql/share/errmsg.txt                | 2 ++
 5 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/include/my_base.h b/include/my_base.h
index c688591e1d..5ea3795f71 100644
--- a/include/my_base.h
+++ b/include/my_base.h
@@ -343,8 +343,9 @@ enum ha_base_keytype {
 #define HA_ERR_NO_CONNECTION     157  /* Could not connect to storage engine */
 #define HA_ERR_NULL_IN_SPATIAL   158  /* NULLs are not supported in spatial index */
 #define HA_ERR_TABLE_DEF_CHANGED 159  /* The table changed in storage engine */
+#define HA_ERR_NO_PARTITION_FOUND 160  /* There's no partition in table for given value */
 
-#define HA_ERR_LAST              159  /*Copy last error nr.*/
+#define HA_ERR_LAST              160  /*Copy last error nr.*/
 /* Add error numbers before HA_ERR_LAST and change it accordingly. */
 #define HA_ERR_ERRORS            (HA_ERR_LAST - HA_ERR_FIRST + 1)
 
diff --git a/mysql-test/r/partition_error.result b/mysql-test/r/partition_error.result
index 58c42888ae..90faa3b20b 100644
--- a/mysql-test/r/partition_error.result
+++ b/mysql-test/r/partition_error.result
@@ -544,3 +544,8 @@ partitions 2
 partition x2 values in (5));
 ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '4,
 partition x2 values in (5))' at line 8
+CREATE TABLE t1(a int)
+PARTITION BY RANGE (a) (PARTITION p1 VALUES LESS THAN(5));
+insert into t1 values (10);
+ERROR HY000: Table has no partition for value 10
+drop table t1;
diff --git a/mysql-test/t/partition_error.test b/mysql-test/t/partition_error.test
index b4851dcf8c..ea12bbc520 100644
--- a/mysql-test/t/partition_error.test
+++ b/mysql-test/t/partition_error.test
@@ -727,3 +727,11 @@ partitions 2
 (partition x1 values in 4,
  partition x2 values in (5));
 
+#
+# No partition for the given value
+#
+CREATE TABLE t1(a int)
+  PARTITION BY RANGE (a) (PARTITION p1 VALUES LESS THAN(5));
+--error ER_NO_PARTITION_FOR_GIVEN_VALUE
+insert into t1 values (10);
+drop table t1;
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index 650830832c..b0b4ac3fdc 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -1174,7 +1174,7 @@ int ha_partition::write_row(byte * buf)
   }
 #endif
   if (unlikely(error))
-    DBUG_RETURN(error);
+    DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND);
   m_last_part= part_id;
   DBUG_PRINT("info", ("Insert in partition %d", part_id));
   DBUG_RETURN(m_file[part_id]->write_row(buf));
@@ -2973,7 +2973,11 @@ void ha_partition::print_error(int error, myf errflag)
   DBUG_ENTER("ha_partition::print_error");
   /* Should probably look for my own errors first */
   /* monty: needs to be called for the last used partition ! */
-  m_file[0]->print_error(error, errflag);
+  if (error == HA_ERR_NO_PARTITION_FOUND)
+    my_error(ER_NO_PARTITION_FOR_GIVEN_VALUE, MYF(0),
+             m_part_info->part_expr->val_int());
+  else
+    m_file[0]->print_error(error, errflag);
   DBUG_VOID_RETURN;
 }
 
diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt
index d6be040586..35b6b17efa 100644
--- a/sql/share/errmsg.txt
+++ b/sql/share/errmsg.txt
@@ -5725,3 +5725,5 @@ ER_PLUGIN_IS_NOT_LOADED
 	eng "Plugin '%-.64s' is not loaded"
 ER_WRONG_VALUE
 	eng "Incorrect %-.32s value: '%-.128s'"
+ER_NO_PARTITION_FOR_GIVEN_VALUE
+	eng "Table has no partition for value %d"
-- 
2.30.9