MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:konstantin Date:February 21 2006 4:52pm
Subject:bk commit into 4.1 tree (konstantin:1.2471) BUG#13134
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of kostja. When kostja 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.2471 06/02/21 19:52:20 konstantin@stripped +6 -0
  A fix and a test case for Bug#13134 "Length of VARCHAR() utf8 
  column is increasing when table is recreated with PS/SP":
  make use of create_field::char_length more consistent in the code.
  Reinit create_field::length from create_field::char_length
  for every execution of a prepared statement (actually fixes the 
  bug).

  sql/sql_table.cc
    1.305 06/02/21 19:52:15 konstantin@stripped +7 -1
    Reinit length from char_length for every field in 
    mysql_prepare_table. This is not needed if we're executing
    a statement for the first time, however, at subsequent executions
    length contains the number of bytes, not characters (as it's expected 
    to).

  sql/sql_parse.cc
    1.476 06/02/21 19:52:15 konstantin@stripped +2 -0
    Initialize char_length in add_field_to_list. This function
    effectively works as another create_field constructor.

  sql/field.h
    1.131 06/02/21 19:52:15 konstantin@stripped +1 -1
    Rename chars_length to char_length (to be consistent with
    how this term is used throughout the rest of the code).

  sql/field.cc
    1.229 06/02/21 19:52:15 konstantin@stripped +2 -3
    Move initialization of create_field::char_length to the constructor
    of create_field.

  mysql-test/t/ps.test
    1.47 06/02/21 19:52:15 konstantin@stripped +23 -1
    A test case for Bug#13134 "Length of VARCHAR() utf8 column is 
    increasing when table is recreated with PS/SP"

  mysql-test/r/ps.result
    1.46 06/02/21 19:52:14 konstantin@stripped +17 -0
    Test results fixed (Bug#13134)

# 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:	konstantin
# Host:	dragonfly.local
# Root:	/opt/local/work/mysql-4.1-13134

--- 1.228/sql/field.cc	2005-12-19 14:28:38 +03:00
+++ 1.229/sql/field.cc	2006-02-21 19:52:15 +03:00
@@ -6516,13 +6516,11 @@
     create_field::create_length_to_internal_length()
   
   DESCRIPTION
-    Convert create_field::length from number of characters to number of bytes,
-    save original value in chars_length.
+    Convert create_field::length from number of characters to number of bytes.
 */
 
 void create_field::create_length_to_internal_length(void)
 {
-  chars_length= length;
   switch (sql_type) {
   case MYSQL_TYPE_TINY_BLOB:
   case MYSQL_TYPE_MEDIUM_BLOB:
@@ -6775,6 +6773,7 @@
       break;
   }
 
+  char_length= length;
   decimals= old_field->decimals();
   if (sql_type == FIELD_TYPE_STRING)
   {

--- 1.130/sql/field.h	2005-10-26 00:56:10 +04:00
+++ 1.131/sql/field.h	2006-02-21 19:52:15 +03:00
@@ -1188,7 +1188,7 @@
   /*
     The value of 'length' before a call to create_length_to_internal_length
   */
-  uint32 chars_length;
+  uint32 char_length;
   uint decimals,flags,pack_length;
   Field::utype unireg_check;
   TYPELIB *interval;			// Which interval to use

--- 1.475/sql/sql_parse.cc	2006-01-26 13:47:59 +03:00
+++ 1.476/sql/sql_parse.cc	2006-02-21 19:52:15 +03:00
@@ -4480,6 +4480,7 @@
 						  NOT_FIXED_DEC-1) : 0;
   new_field->sql_type=type;
   new_field->length=0;
+  new_field->char_length= 0;
   new_field->change=change;
   new_field->interval=0;
   new_field->pack_length=0;
@@ -4750,6 +4751,7 @@
 					    FIELD_TYPE_STRING :
 					    new_field->sql_type,
 					    new_field->length);
+  new_field->char_length= new_field->length;
   lex->create_list.push_back(new_field);
   lex->last_field=new_field;
   DBUG_RETURN(0);

--- 1.304/sql/sql_table.cc	2006-01-16 18:21:39 +03:00
+++ 1.305/sql/sql_table.cc	2006-02-21 19:52:15 +03:00
@@ -488,6 +488,12 @@
 
   for (field_no=0; (sql_field=it++) ; field_no++)
   {
+    /*
+      Initialize length from its original value (number of characters),
+      which was set in the parser. This is necessary if we're
+      executing a prepared statement for the second time.
+    */
+    sql_field->length= sql_field->char_length;
     if (!sql_field->charset)
       sql_field->charset= create_info->default_table_charset;
     /*
@@ -665,7 +671,7 @@
 	  sql_field->charset=		(dup_field->charset ?
 					 dup_field->charset :
 					 create_info->default_table_charset);
-	  sql_field->length=		dup_field->chars_length;
+	  sql_field->length=		dup_field->char_length;
           sql_field->pack_length=	dup_field->pack_length;
 	  sql_field->create_length_to_internal_length();
 	  sql_field->decimals=		dup_field->decimals;

--- 1.45/mysql-test/r/ps.result	2006-01-17 01:02:57 +03:00
+++ 1.46/mysql-test/r/ps.result	2006-02-21 19:52:14 +03:00
@@ -733,3 +733,20 @@
 5
 deallocate prepare stmt;
 drop table t1;
+drop table if exists t1;
+Warnings:
+Note	1051	Unknown table 't1'
+prepare stmt from 'create table t1 (a varchar(10) character set utf8)';
+execute stmt;
+insert into t1 (a) values (repeat('a', 20));
+select length(a) from t1;
+length(a)
+10
+drop table t1;
+execute stmt;
+insert into t1 (a) values (repeat('a', 20));
+select length(a) from t1;
+length(a)
+10
+drop table t1;
+deallocate prepare stmt;

--- 1.46/mysql-test/t/ps.test	2006-01-17 01:02:57 +03:00
+++ 1.47/mysql-test/t/ps.test	2006-02-21 19:52:15 +03:00
@@ -763,5 +763,27 @@
 deallocate prepare stmt;
 drop table t1;
 
-# End of 4.1 tests
 
+#
+# Bug#13134 "Length of VARCHAR() utf8 column is increasing when table is
+# recreated with PS/SP"
+#
+
+drop table if exists t1;
+prepare stmt from 'create table t1 (a varchar(10) character set utf8)';
+execute stmt;
+--disable_warnings
+insert into t1 (a) values (repeat('a', 20));
+--enable_warnings
+select length(a) from t1;
+drop table t1;
+execute stmt;
+--disable_warnings
+insert into t1 (a) values (repeat('a', 20));
+--enable_warnings
+# Check that the data is truncated to the same length
+select length(a) from t1;
+drop table t1;
+deallocate prepare stmt;
+
+# End of 4.1 tests
Thread
bk commit into 4.1 tree (konstantin:1.2471) BUG#13134konstantin21 Feb