List:Commits« Previous MessageNext Message »
From:ramil Date:April 28 2006 5:38am
Subject:bk commit into 5.1 tree (ramil:1.2371)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of rkalimullin. When rkalimullin 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
  1.2371 06/04/28 07:38:03 ramil@stripped +3 -0
  Merge rkalimullin@stripped:/home/bk/mysql-5.1-new
  into  production.mysql.com:/usersnfs/rkalimullin/5.1.b18014

  sql/field.h
    1.182 06/04/28 07:37:51 ramil@stripped +0 -0
    Auto merged

  sql/field.cc
    1.305 06/04/28 07:37:51 ramil@stripped +0 -0
    Auto merged

  mysql-test/t/type_newdecimal.test
    1.37 06/04/28 07:37:50 ramil@stripped +0 -0
    Auto merged

# 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:	ramil
# Host:	production.mysql.com
# Root:	/usersnfs/rkalimullin/5.1.b18014/RESYNC

--- 1.304/sql/field.cc	2006-03-07 14:10:16 +01:00
+++ 1.305/sql/field.cc	2006-04-28 07:37:51 +02:00
@@ -4249,6 +4249,7 @@
 longlong Field_double::val_int(void)
 {
   double j;
+  longlong res;
 #ifdef WORDS_BIGENDIAN
   if (table->s->db_low_byte_first)
   {
@@ -4257,7 +4258,30 @@
   else
 #endif
     doubleget(j,ptr);
+  /* Check whether we fit into longlong range */
+  if (j <= (double) LONGLONG_MIN)
+  {
+    res= (longlong) LONGLONG_MIN;
+    goto warn;
+  }
+  if (j >= (double) (ulonglong) LONGLONG_MAX)
+  {
+    res= (longlong) LONGLONG_MAX;
+    goto warn;
+  }
   return (longlong) rint(j);
+
+warn:
+  {
+    char buf[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
+    String tmp(buf, sizeof(buf), &my_charset_latin1), *str;
+    str= val_str(&tmp, 0);
+    push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                        ER_TRUNCATED_WRONG_VALUE,
+                        ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER",
+                        str->c_ptr());
+  }
+  return res;
 }
 
 
@@ -5977,7 +6001,7 @@
 
 uint Field::is_equal(create_field *new_field)
 {
-  return (new_field->sql_type == type());
+  return (new_field->sql_type == real_type());
 }
 
 
@@ -5989,7 +6013,7 @@
 	(flags & (BINCMP_FLAG | BINARY_FLAG))))
     return 0; /* One of the fields is binary and the other one isn't */
 
-  return ((new_field->sql_type == type()) &&
+  return ((new_field->sql_type == real_type()) &&
 	  new_field->charset == field_charset &&
 	  new_field->length == max_length());
 }
@@ -6786,7 +6810,7 @@
 
 uint Field_varstring::is_equal(create_field *new_field)
 {
-  if (new_field->sql_type == type() &&
+  if (new_field->sql_type == real_type() &&
       new_field->charset == field_charset)
   {
     if (new_field->length == max_length())
@@ -7945,12 +7969,12 @@
 
 uint Field_num::is_equal(create_field *new_field)
 {
-  return ((new_field->sql_type == type()) &&
+  return ((new_field->sql_type == real_type()) &&
 	  ((new_field->flags & UNSIGNED_FLAG) == (uint) (flags &
 							 UNSIGNED_FLAG)) &&
 	  ((new_field->flags & AUTO_INCREMENT_FLAG) ==
 	   (uint) (flags & AUTO_INCREMENT_FLAG)) &&
-	  (new_field->length >= max_length()));
+	  (new_field->length <= max_length()));
 }
 
 
@@ -7986,9 +8010,10 @@
 Field_bit::Field_bit(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
                      uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg,
                      enum utype unireg_check_arg, const char *field_name_arg)
-  : Field(ptr_arg, len_arg >> 3, null_ptr_arg, null_bit_arg,
+  : Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
           unireg_check_arg, field_name_arg),
-    bit_ptr(bit_ptr_arg), bit_ofs(bit_ofs_arg), bit_len(len_arg & 7)
+    bit_ptr(bit_ptr_arg), bit_ofs(bit_ofs_arg), bit_len(len_arg & 7),
+    bytes_in_rec(len_arg / 8)
 {
   /*
     Ensure that Field::eq() can distinguish between two different bit fields.
@@ -8024,14 +8049,14 @@
   int delta;
 
   for (; length && !*from; from++, length--);          // skip left 0's
-  delta= field_length - length;
+  delta= bytes_in_rec - length;
 
   if (delta < -1 ||
       (delta == -1 && (uchar) *from > ((1 << bit_len) - 1)) ||
       (!bit_len && delta < 0))
   {
     set_rec_bits(0xff, bit_ptr, bit_ofs, bit_len);
-    memset(ptr, 0xff, field_length);
+    memset(ptr, 0xff, bytes_in_rec);
     if (table->in_use->really_abort_on_warning())
       set_warning(MYSQL_ERROR::WARN_LEVEL_ERROR, ER_DATA_TOO_LONG, 1);
     else
@@ -8059,7 +8084,7 @@
       set_rec_bits((uchar) *from, bit_ptr, bit_ofs, bit_len);
       from++;
     }
-    memcpy(ptr, from, field_length);
+    memcpy(ptr, from, bytes_in_rec);
   }
   return 0;
 }
@@ -8100,10 +8125,10 @@
   if (bit_len)
   {
     bits= get_rec_bits(bit_ptr, bit_ofs, bit_len);
-    bits<<= (field_length * 8);
+    bits<<= (bytes_in_rec * 8);
   }
 
-  switch (field_length) {
+  switch (bytes_in_rec) {
   case 0: return bits;
   case 1: return bits | (ulonglong) (uchar) ptr[0];
   case 2: return bits | mi_uint2korr(ptr);
@@ -8112,7 +8137,7 @@
   case 5: return bits | mi_uint5korr(ptr);
   case 6: return bits | mi_uint6korr(ptr);
   case 7: return bits | mi_uint7korr(ptr);
-  default: return mi_uint8korr(ptr + field_length - sizeof(longlong));
+  default: return mi_uint8korr(ptr + bytes_in_rec - sizeof(longlong));
   }
 }  
 
@@ -8194,7 +8219,7 @@
     if ((flag= (int) (bits_a - bits_b)))
       return flag;
   }
-  return memcmp(ptr, ptr + row_offset, field_length);
+  return memcmp(ptr, ptr + row_offset, bytes_in_rec);
 }
 
 
@@ -8206,7 +8231,7 @@
     *buff++= bits;
     length--;
   }
-  memcpy(buff, ptr, min(length, field_length));
+  memcpy(buff, ptr, min(length, bytes_in_rec));
 }
 
 
@@ -8214,22 +8239,22 @@
 {
   CHARSET_INFO *cs= res.charset();
   ulong length= cs->cset->snprintf(cs, (char*) res.ptr(), res.alloced_length(),
-                                   "bit(%d)", 
-                                   (int) field_length * 8 + bit_len);
+                                   "bit(%d)", (int) field_length);
   res.length((uint) length);
 }
 
 
 char *Field_bit::pack(char *to, const char *from, uint max_length)
 {
-  uint length= min(field_length + (bit_len > 0), max_length);
+  DBUG_ASSERT(max_length);
+  uint length;
   if (bit_len)
   {
     uchar bits= get_rec_bits(bit_ptr, bit_ofs, bit_len);
     *to++= bits;
-    length--;
   }
-  memcpy(to, from, length); 
+  length= min(bytes_in_rec, max_length - (bit_len > 0));
+  memcpy(to, from, length);
   return to + length;
 }
 
@@ -8241,8 +8266,8 @@
     set_rec_bits(*from, bit_ptr, bit_ofs, bit_len);
     from++;
   }
-  memcpy(to, from, field_length);
-  return from + field_length;
+  memcpy(to, from, bytes_in_rec);
+  return from + bytes_in_rec;
 }
 
 
@@ -8255,26 +8280,25 @@
                                      enum utype unireg_check_arg,
                                      const char *field_name_arg)
   :Field_bit(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, 0, 0,
-             unireg_check_arg, field_name_arg),
-   create_length(len_arg)
+             unireg_check_arg, field_name_arg)
 {
   bit_len= 0;
-  field_length= ((len_arg + 7) & ~7) / 8;
+  bytes_in_rec= (len_arg + 7) / 8;
 }
 
 
 int Field_bit_as_char::store(const char *from, uint length, CHARSET_INFO *cs)
 {
   int delta;
-  uchar bits= create_length & 7;
+  uchar bits= field_length & 7;
 
   for (; length && !*from; from++, length--);          // skip left 0's
-  delta= field_length - length;
+  delta= bytes_in_rec - length;
 
   if (delta < 0 ||
       (delta == 0 && bits && (uint) (uchar) *from >= (uint) (1 << bits)))
   {
-    memset(ptr, 0xff, field_length);
+    memset(ptr, 0xff, bytes_in_rec);
     if (bits)
       *ptr&= ((1 << bits) - 1); /* set first byte */
     if (table->in_use->really_abort_on_warning())
@@ -8293,7 +8317,7 @@
 {
   CHARSET_INFO *cs= res.charset();
   ulong length= cs->cset->snprintf(cs, (char*) res.ptr(), res.alloced_length(),
-                                   "bit(%d)", (int) create_length);
+                                   "bit(%d)", (int) field_length);
   res.length((uint) length);
 }
 
@@ -9021,11 +9045,6 @@
     geom_type= ((Field_geom*)old_field)->geom_type;
     break;
 #endif
-  case FIELD_TYPE_BIT:
-    length= (old_field->key_type() == HA_KEYTYPE_BIT) ?
-            ((Field_bit *) old_field)->bit_len + length * 8 :
-            ((Field_bit_as_char *) old_field)->create_length;
-    break;
   default:
     break;
   }

--- 1.181/sql/field.h	2006-03-07 14:10:16 +01:00
+++ 1.182/sql/field.h	2006-04-28 07:37:51 +02:00
@@ -350,6 +350,12 @@
   /* convert decimal to longlong with overflow check */
   longlong convert_decimal2longlong(const my_decimal *val, bool unsigned_flag,
                                     int *err);
+  /* The max. number of characters */
+  inline uint32 char_length() const
+  {
+    return field_length / charset()->mbmaxlen;
+  }
+
   friend bool reopen_table(THD *,struct st_table *,bool);
   friend int cre_myisam(my_string name, register TABLE *form, uint options,
 			ulonglong auto_increment_value);
@@ -995,20 +1001,23 @@
 
 class Field_string :public Field_longstr {
 public:
+  bool can_alter_field_type;
   Field_string(char *ptr_arg, uint32 len_arg,uchar *null_ptr_arg,
 	       uchar null_bit_arg,
 	       enum utype unireg_check_arg, const char *field_name_arg,
 	       CHARSET_INFO *cs)
     :Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
-                   unireg_check_arg, field_name_arg, cs) {};
+                   unireg_check_arg, field_name_arg, cs),
+     can_alter_field_type(1) {};
   Field_string(uint32 len_arg,bool maybe_null_arg, const char *field_name_arg,
                CHARSET_INFO *cs)
     :Field_longstr((char*) 0, len_arg, maybe_null_arg ? (uchar*) "": 0, 0,
-                   NONE, field_name_arg, cs) {};
+                   NONE, field_name_arg, cs),
+     can_alter_field_type(1) {};
 
   enum_field_types type() const
   {
-    return ((orig_table &&
+    return ((can_alter_field_type && orig_table &&
              orig_table->s->db_create_options & HA_OPTION_PACK_RECORD &&
 	     field_length >= 4) &&
             orig_table->s->frm_version < FRM_VER_TRUE_VARCHAR ?
@@ -1338,16 +1347,17 @@
   uchar *bit_ptr;     // position in record where 'uneven' bits store
   uchar bit_ofs;      // offset to 'uneven' high bits
   uint bit_len;       // number of 'uneven' high bits
+  uint bytes_in_rec;
   Field_bit(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
             uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg,
             enum utype unireg_check_arg, const char *field_name_arg);
   enum_field_types type() const { return FIELD_TYPE_BIT; }
   enum ha_base_keytype key_type() const { return HA_KEYTYPE_BIT; }
-  uint32 key_length() const { return (uint32) field_length + (bit_len > 0); }
-  uint32 max_length() { return (uint32) field_length * 8 + bit_len; }
+  uint32 key_length() const { return (uint32) (field_length + 7) / 8; }
+  uint32 max_length() { return field_length; }
   uint size_of() const { return sizeof(*this); }
   Item_result result_type () const { return INT_RESULT; }
-  void reset(void) { bzero(ptr, field_length); }
+  void reset(void) { bzero(ptr, bytes_in_rec); }
   int store(const char *to, uint length, CHARSET_INFO *charset);
   int store(double nr);
   int store(longlong nr, bool unsigned_val);
@@ -1370,9 +1380,8 @@
   { Field_bit::store(buff, length, &my_charset_bin); }
   void sort_string(char *buff, uint length)
   { get_key_image(buff, length, itRAW); }
-  uint32 pack_length() const 
-  { return (uint32) field_length + (bit_len > 0); }
-  uint32 pack_length_in_rec() const { return field_length; }
+  uint32 pack_length() const { return (uint32) (field_length + 7) / 8; }
+  uint32 pack_length_in_rec() const { return bytes_in_rec; }
   void sql_type(String &str) const;
   char *pack(char *to, const char *from, uint max_length=~(uint) 0);
   const char *unpack(char* to, const char *from);
@@ -1394,12 +1403,10 @@
 
 class Field_bit_as_char: public Field_bit {
 public:
-  uchar create_length;
   Field_bit_as_char(char *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
                     uchar null_bit_arg,
                     enum utype unireg_check_arg, const char *field_name_arg);
   enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
-  uint32 max_length() { return (uint32) create_length; }
   uint size_of() const { return sizeof(*this); }
   int store(const char *to, uint length, CHARSET_INFO *charset);
   int store(double nr) { return Field_bit::store(nr); }

--- 1.36/mysql-test/t/type_newdecimal.test	2006-03-07 14:10:16 +01:00
+++ 1.37/mysql-test/t/type_newdecimal.test	2006-04-28 07:37:50 +02:00
@@ -1050,6 +1050,10 @@
 }
 SELECT my_float, my_double, my_varchar FROM t1;
 
+# Expected result   0.000000000011754943372854760000
+# On windows we get 0.000000000011754943372854770000
+# use replace_result to correct it
+--replace_result 0.000000000011754943372854770000 0.000000000011754943372854760000
 SELECT CAST(my_float   AS DECIMAL(65,30)), my_float FROM t1;
 SELECT CAST(my_double  AS DECIMAL(65,30)), my_double FROM t1;
 SELECT CAST(my_varchar AS DECIMAL(65,30)), my_varchar FROM t1;
@@ -1061,7 +1065,13 @@
 
 --disable_warnings
 UPDATE t1 SET my_decimal = my_float;
+
+# Expected result   0.000000000011754943372854760000
+# On windows we get 0.000000000011754943372854770000
+# use replace_result to correct it
+--replace_result 0.000000000011754943372854770000 0.000000000011754943372854760000
 SELECT my_decimal, my_float   FROM t1;
+
 UPDATE t1 SET my_decimal = my_double;
 SELECT my_decimal, my_double  FROM t1;
 --enable_warnings
Thread
bk commit into 5.1 tree (ramil:1.2371)ramil28 Apr