List:Commits« Previous MessageNext Message »
From:kgeorge Date:November 16 2006 1:14pm
Subject:bk commit into 5.0 tree (gkodinov:1.2305) BUG#11927
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of kgeorge. When kgeorge does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2006-11-16 15:14:37+02:00, gkodinov@stripped +13 -0
  BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
   When implicitly converting string fields to numbers the 
   string-to-number conversion error was not sent to the client.
   Added code to send the conversion error as warning.
   
   We also need to prevent generation of warnings from the places
   where val_xxx() methods are called for the sole purpose of updating
   the Item::null_value flag.
   To achieve that a special function is added (and called) : 
   update_null_value(). This function will set the no_errors flag and
   will call val_xxx(). The warning generation in Field_string::val_xxx()
   will use the flag when generating the conversion warnings. 

  mysql-test/r/compare.result@stripped, 2006-11-16 15:14:23+02:00, gkodinov@stripped +4 -0
    BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
     - non-convertible strings in arithmetic operations

  mysql-test/r/func_gconcat.result@stripped, 2006-11-16 15:14:24+02:00, gkodinov@stripped +38 -0
    BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
     - non-convertible strings in arithmetic operations

  mysql-test/r/func_group.result@stripped, 2006-11-16 15:14:24+02:00, gkodinov@stripped +7 -0
    BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
     - non-convertible strings in arithmetic operations

  mysql-test/r/type_varchar.result@stripped, 2006-11-16 15:14:25+02:00, gkodinov@stripped +35 -0
    BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
     - test case

  mysql-test/t/type_varchar.test@stripped, 2006-11-16 15:14:26+02:00, gkodinov@stripped +9 -0
    BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
     - test case

  sql/field.cc@stripped, 2006-11-16 15:14:26+02:00, gkodinov@stripped +52 -8
    BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
     - send conversion warning to the client 

  sql/item.cc@stripped, 2006-11-16 15:14:27+02:00, gkodinov@stripped +17 -7
    BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
     - send conversion warning to the client 

  sql/item.h@stripped, 2006-11-16 15:14:28+02:00, gkodinov@stripped +6 -0
    BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
     - added a special function to explicitly update the null_value

  sql/item_func.h@stripped, 2006-11-16 15:14:28+02:00, gkodinov@stripped +2 -2
    BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
     - added a special function to explicitly update the null_value

  sql/item_subselect.h@stripped, 2006-11-16 15:14:29+02:00, gkodinov@stripped +1 -1
    BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
     - added a special function to explicitly update the null_value

  sql/item_sum.cc@stripped, 2006-11-16 15:14:30+02:00, gkodinov@stripped +4 -4
    BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
     - added a special function to explicitly update the null_value

  sql/item_sum.h@stripped, 2006-11-16 15:14:31+02:00, gkodinov@stripped +2 -2
    BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
     - added a special function to explicitly update the null_value

  sql/sql_string.h@stripped, 2006-11-16 15:14:31+02:00, gkodinov@stripped +5 -0
    BUG#11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
     - send conversion warning to the client 

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	gkodinov
# Host:	macbook.gmz
# Root:	/Users/kgeorge/mysql/work/B11927-5.0-opt

--- 1.329/sql/field.cc	2006-11-07 19:02:38 +02:00
+++ 1.330/sql/field.cc	2006-11-16 15:14:26 +02:00
@@ -47,6 +47,8 @@ uchar Field_null::null[1]={1};
 const char field_separator=',';
 
 #define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE 320
+#define LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE 128
+#define DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE 128
 #define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \
 ((ulong) ((LL(1) << min(arg, 4) * 8) - LL(1)))
 
@@ -5954,19 +5956,49 @@ int Field_longstr::store_decimal(const m
 
 double Field_string::val_real(void)
 {
-  int not_used;
-  char *end_not_used;
+  int error;
+  char *end;
   CHARSET_INFO *cs= charset();
-  return my_strntod(cs,ptr,field_length,&end_not_used,&not_used);
+  double result;
+  
+  result=  my_strntod(cs,ptr,field_length,&end,&error);
+  if (!table->in_use->no_errors &&
+      (error || (field_length != (uint32)(end - ptr) && 
+                !check_if_only_end_space(cs, end, ptr + field_length))))
+  {
+    char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
+    String tmp(buf, sizeof(buf), cs);
+    tmp.copy(ptr, field_length, cs);
+    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                        ER_TRUNCATED_WRONG_VALUE, 
+                        ER(ER_TRUNCATED_WRONG_VALUE),
+                        "DOUBLE", tmp.c_ptr());
+  }
+  return result;
 }
 
 
 longlong Field_string::val_int(void)
 {
-  int not_used;
-  char *end_not_used;
-  CHARSET_INFO *cs=charset();
-  return my_strntoll(cs,ptr,field_length,10,&end_not_used,&not_used);
+  int error;
+  char *end;
+  CHARSET_INFO *cs= charset();
+  longlong result;
+
+  result= my_strntoll(cs,ptr,field_length,10,&end,&error);
+  if (!table->in_use->no_errors &&
+      (error || (field_length != (uint32)(end - ptr) && 
+                !check_if_only_end_space(cs, end, ptr + field_length))))
+  {
+    char buf[LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE];
+    String tmp(buf, sizeof(buf), cs);
+    tmp.copy(ptr, field_length, cs);
+    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                        ER_TRUNCATED_WRONG_VALUE, 
+                        ER(ER_TRUNCATED_WRONG_VALUE),
+                        "INTEGER", tmp.c_ptr());
+  }
+  return result;
 }
 
 
@@ -5983,8 +6015,20 @@ String *Field_string::val_str(String *va
 
 my_decimal *Field_string::val_decimal(my_decimal *decimal_value)
 {
-  str2my_decimal(E_DEC_FATAL_ERROR, ptr, field_length, charset(),
+  int err= str2my_decimal(E_DEC_FATAL_ERROR, ptr, field_length, charset(),
                  decimal_value);
+  if (!table->in_use->no_errors && err)
+  {
+    char buf[DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE];
+    CHARSET_INFO *cs= charset();
+    String tmp(buf, sizeof(buf), cs);
+    tmp.copy(ptr, field_length, cs);
+    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                        ER_TRUNCATED_WRONG_VALUE, 
+                        ER(ER_TRUNCATED_WRONG_VALUE),
+                        "DECIMAL", tmp.c_ptr());
+  }
+
   return decimal_value;
 }
 

--- 1.241/sql/item.cc	2006-11-09 16:55:36 +02:00
+++ 1.242/sql/item.cc	2006-11-16 15:14:27 +02:00
@@ -2175,12 +2175,6 @@ void Item_string::print(String *str)
 }
 
 
-inline bool check_if_only_end_space(CHARSET_INFO *cs, char *str, char *end)
-{
-  return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;
-}
-
-
 double Item_string::val_real()
 {
   DBUG_ASSERT(fixed == 1);
@@ -4764,6 +4758,22 @@ bool Item_field::send(Protocol *protocol
 }
 
 
+void Item_field::update_null_value() 
+{ 
+  /* 
+    need to set no_errors to prevent warnings about type conversion 
+    popping up.
+  */
+  THD *thd= field->table->in_use;
+  int no_errors;
+
+  no_errors= thd->no_errors;
+  thd->no_errors= 1;
+  Item::update_null_value();
+  thd->no_errors= no_errors;
+}
+
+
 Item_ref::Item_ref(Name_resolution_context *context_arg,
                    Item **item, const char *table_name_arg,
                    const char *field_name_arg)
@@ -6120,7 +6130,7 @@ bool Item_cache_row::null_inside()
     }
     else
     {
-      values[i]->val_int();
+      values[i]->update_null_value();
       if (values[i]->null_value)
 	return 1;
     }

--- 1.211/sql/item.h	2006-11-06 09:09:58 +02:00
+++ 1.212/sql/item.h	2006-11-16 15:14:28 +02:00
@@ -716,6 +716,11 @@ public:
   virtual bool is_null() { return 0; }
 
   /*
+   Make sure the null_value member has a correct value.
+  */
+  virtual void update_null_value () { (void) val_int(); }
+
+  /*
     Inform the item that there will be no distinction between its result
     being FALSE or NULL.
 
@@ -1282,6 +1287,7 @@ public:
   bool get_date_result(TIME *ltime,uint fuzzydate);
   bool get_time(TIME *ltime);
   bool is_null() { return field->is_null(); }
+  void update_null_value();
   Item *get_tmp_table_item(THD *thd);
   bool collect_item_field_processor(byte * arg);
   bool find_item_in_field_list_processor(byte *arg);

--- 1.156/sql/item_func.h	2006-10-31 16:15:30 +02:00
+++ 1.157/sql/item_func.h	2006-11-16 15:14:28 +02:00
@@ -157,7 +157,7 @@ public:
     return (null_value=args[0]->get_time(ltime));
   }
   bool is_null() { 
-    (void) val_int();  /* Discard result. It sets null_value as side-effect. */ 
+    update_null_value();
     return null_value; 
   }
   void signal_divide_by_null();
@@ -241,7 +241,7 @@ public:
   virtual double real_op()= 0;
   virtual my_decimal *decimal_op(my_decimal *)= 0;
   virtual String *str_op(String *)= 0;
-  bool is_null() { (void) val_real(); return null_value; }
+  bool is_null() { update_null_value(); return null_value; }
 };
 
 /* function where type of result detected by first argument */

--- 1.182/sql/item_sum.cc	2006-10-31 11:01:21 +02:00
+++ 1.183/sql/item_sum.cc	2006-11-16 15:14:30 +02:00
@@ -1050,7 +1050,7 @@ bool Item_sum_count::add()
     count++;
   else
   {
-    (void) args[0]->val_int();
+    args[0]->update_null_value();
     if (!args[0]->null_value)
       count++;
   }
@@ -1956,7 +1956,7 @@ void Item_sum_count::reset_field()
     nr=1;
   else
   {
-    (void) args[0]->val_int();
+    args[0]->update_null_value();
     if (!args[0]->null_value)
       nr=1;
   }
@@ -2066,7 +2066,7 @@ void Item_sum_count::update_field()
     nr++;
   else
   {
-    (void) args[0]->val_int();
+    args[0]->update_null_value();
     if (!args[0]->null_value)
       nr++;
   }
@@ -2546,7 +2546,7 @@ bool Item_sum_count_distinct::setup(THD 
       return TRUE;                              // End of memory
     if (item->const_item())
     {
-      (void) item->val_int();
+      item->update_null_value();
       if (item->null_value)
 	always_null=1;
     }

--- 1.104/sql/item_sum.h	2006-10-31 11:01:22 +02:00
+++ 1.105/sql/item_sum.h	2006-11-16 15:14:31 +02:00
@@ -587,7 +587,7 @@ public:
   double val_real();
   longlong val_int();
   my_decimal *val_decimal(my_decimal *);
-  bool is_null() { (void) val_int(); return null_value; }
+  bool is_null() { update_null_value(); return null_value; }
   String *val_str(String*);
   enum_field_types field_type() const
   {
@@ -649,7 +649,7 @@ public:
   { /* can't be fix_fields()ed */ return (longlong) rint(val_real()); }
   String *val_str(String*);
   my_decimal *val_decimal(my_decimal *);
-  bool is_null() { (void) val_int(); return null_value; }
+  bool is_null() { update_null_value(); return null_value; }
   enum_field_types field_type() const
   {
     return hybrid_type == DECIMAL_RESULT ?

--- 1.61/sql/sql_string.h	2006-07-14 02:02:17 +03:00
+++ 1.62/sql/sql_string.h	2006-11-16 15:14:31 +02:00
@@ -355,3 +355,8 @@ public:
     return (s->alloced && Ptr >= s->Ptr && Ptr < s->Ptr + s->str_length);
   }
 };
+
+inline bool check_if_only_end_space(CHARSET_INFO *cs, char *str, char *end)
+{
+  return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end;
+}

--- 1.81/sql/item_subselect.h	2006-11-07 18:44:33 +02:00
+++ 1.82/sql/item_subselect.h	2006-11-16 15:14:29 +02:00
@@ -91,7 +91,7 @@ public:
   enum Type type() const;
   bool is_null()
   {
-    val_int();
+    update_null_value();
     return null_value;
   }
   bool fix_fields(THD *thd, Item **ref);

--- 1.11/mysql-test/r/compare.result	2006-08-15 10:13:11 +03:00
+++ 1.12/mysql-test/r/compare.result	2006-11-16 15:14:23 +02:00
@@ -46,6 +46,10 @@ create table t1 (a tinyint(1),b binary(1
 insert into t1 values (0x01,0x01);
 select * from t1 where a=b;
 a	b
+Warnings:
+Warning	1292	Truncated incorrect DOUBLE value: ''
 select * from t1 where a=b and b=0x01;
 a	b
+Warnings:
+Warning	1292	Truncated incorrect DOUBLE value: ''
 drop table if exists t1;

--- 1.54/mysql-test/r/func_group.result	2006-10-31 11:01:20 +02:00
+++ 1.55/mysql-test/r/func_group.result	2006-11-16 15:14:24 +02:00
@@ -62,6 +62,13 @@ NULL	NULL
 1	7
 2	20.25
 3	45.483163247594
+Warnings:
+Warning	1292	Truncated incorrect DOUBLE value: 'a         '
+Warning	1292	Truncated incorrect DOUBLE value: 'a         '
+Warning	1292	Truncated incorrect DOUBLE value: 'b         '
+Warning	1292	Truncated incorrect DOUBLE value: 'c         '
+Warning	1292	Truncated incorrect DOUBLE value: 'C         '
+Warning	1292	Truncated incorrect DOUBLE value: 'E         '
 create table t2 (grp int, a bigint unsigned, c char(10));
 insert into t2 select grp,max(a)+max(grp),max(c) from t1 group by grp;
 replace into t2 select grp, a, c from t1 limit 2,1;

--- 1.9/mysql-test/r/type_varchar.result	2006-08-29 23:38:53 +03:00
+++ 1.10/mysql-test/r/type_varchar.result	2006-11-16 15:14:25 +02:00
@@ -453,3 +453,38 @@ id	name_id	id	en	cz
 2	3	2	en string 2	cz string 2
 3	3	3	en string 3	cz string 3
 drop table t1, t2, t3;
+CREATE TABLE t1 (a CHAR(2));
+INSERT INTO t1 VALUES (10), (50), (30), ('1a'), (60), ('t');
+SELECT a,(a + 0) FROM t1 ORDER BY a;
+a	(a + 0)
+10	10
+1a	1
+30	30
+50	50
+60	60
+t	0
+Warnings:
+Warning	1292	Truncated incorrect DOUBLE value: '1a'
+Warning	1292	Truncated incorrect DOUBLE value: 't '
+SELECT a,(a DIV 2) FROM t1 ORDER BY a;
+a	(a DIV 2)
+10	5
+1a	0
+30	15
+50	25
+60	30
+t	0
+Warnings:
+Warning	1292	Truncated incorrect INTEGER value: '1a'
+Warning	1292	Truncated incorrect INTEGER value: 't '
+SELECT a,CAST(a AS SIGNED) FROM t1 ORDER BY a;
+a	CAST(a AS SIGNED)
+10	10
+1a	1
+30	30
+50	50
+60	60
+t	0
+Warnings:
+Warning	1292	Truncated incorrect INTEGER value: '1a'
+Warning	1292	Truncated incorrect INTEGER value: 't'

--- 1.9/mysql-test/t/type_varchar.test	2006-08-29 23:38:54 +03:00
+++ 1.10/mysql-test/t/type_varchar.test	2006-11-16 15:14:26 +02:00
@@ -187,3 +187,12 @@ left join t3 on t1.id=t3.id order by t3.
 --disable_metadata
 --enable_ps_protocol
 drop table t1, t2, t3;
+
+#
+# Bug #11927: Warnings shown for CAST( chr as signed) but not (chr + 0)
+#
+CREATE TABLE t1 (a CHAR(2));
+INSERT INTO t1 VALUES (10), (50), (30), ('1a'), (60), ('t');
+SELECT a,(a + 0) FROM t1 ORDER BY a;
+SELECT a,(a DIV 2) FROM t1 ORDER BY a;
+SELECT a,CAST(a AS SIGNED) FROM t1 ORDER BY a;

--- 1.62/mysql-test/r/func_gconcat.result	2006-10-16 13:13:11 +03:00
+++ 1.63/mysql-test/r/func_gconcat.result	2006-11-16 15:14:24 +02:00
@@ -64,11 +64,49 @@ grp	group_concat(a order by a,d+c-ascii(
 1	1
 2	2,3
 3	4,5,6,7,8,9
+Warnings:
+Warning	1292	Truncated incorrect DOUBLE value: 'a         '
+Warning	1292	Truncated incorrect DOUBLE value: 'a         '
+Warning	1292	Truncated incorrect DOUBLE value: 'a         '
+Warning	1292	Truncated incorrect DOUBLE value: 'b         '
+Warning	1292	Truncated incorrect DOUBLE value: 'b         '
+Warning	1292	Truncated incorrect DOUBLE value: 'c         '
+Warning	1292	Truncated incorrect DOUBLE value: 'a         '
+Warning	1292	Truncated incorrect DOUBLE value: 'E         '
+Warning	1292	Truncated incorrect DOUBLE value: 'b         '
+Warning	1292	Truncated incorrect DOUBLE value: 'C         '
+Warning	1292	Truncated incorrect DOUBLE value: 'b         '
+Warning	1292	Truncated incorrect DOUBLE value: 'D         '
+Warning	1292	Truncated incorrect DOUBLE value: 'd         '
+Warning	1292	Truncated incorrect DOUBLE value: 'd         '
+Warning	1292	Truncated incorrect DOUBLE value: 'd         '
+Warning	1292	Truncated incorrect DOUBLE value: 'd         '
+Warning	1292	Truncated incorrect DOUBLE value: 'c         '
+Warning	1292	Truncated incorrect DOUBLE value: 'D         '
 select grp,group_concat(a order by d+c-ascii(c),a) from t1 group by grp;
 grp	group_concat(a order by d+c-ascii(c),a)
 1	1
 2	3,2
 3	7,8,4,6,9,5
+Warnings:
+Warning	1292	Truncated incorrect DOUBLE value: 'a         '
+Warning	1292	Truncated incorrect DOUBLE value: 'a         '
+Warning	1292	Truncated incorrect DOUBLE value: 'a         '
+Warning	1292	Truncated incorrect DOUBLE value: 'b         '
+Warning	1292	Truncated incorrect DOUBLE value: 'b         '
+Warning	1292	Truncated incorrect DOUBLE value: 'c         '
+Warning	1292	Truncated incorrect DOUBLE value: 'a         '
+Warning	1292	Truncated incorrect DOUBLE value: 'E         '
+Warning	1292	Truncated incorrect DOUBLE value: 'b         '
+Warning	1292	Truncated incorrect DOUBLE value: 'C         '
+Warning	1292	Truncated incorrect DOUBLE value: 'b         '
+Warning	1292	Truncated incorrect DOUBLE value: 'D         '
+Warning	1292	Truncated incorrect DOUBLE value: 'd         '
+Warning	1292	Truncated incorrect DOUBLE value: 'd         '
+Warning	1292	Truncated incorrect DOUBLE value: 'd         '
+Warning	1292	Truncated incorrect DOUBLE value: 'd         '
+Warning	1292	Truncated incorrect DOUBLE value: 'c         '
+Warning	1292	Truncated incorrect DOUBLE value: 'D         '
 select grp,group_concat(c order by 1) from t1 group by grp;
 grp	group_concat(c order by 1)
 1	a
Thread
bk commit into 5.0 tree (gkodinov:1.2305) BUG#11927kgeorge16 Nov