List:Commits« Previous MessageNext Message »
From:konstantin Date:January 18 2006 7:50pm
Subject:bk commit into 4.1 tree (konstantin:1.2479) BUG#15613
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.2479 06/01/18 22:50:31 konstantin@stripped +2 -0
  A fix and a test case for Bug#15613 "libmysqlclient API function
   mysql_stmt_prepare returns wrong field length"

  tests/mysql_client_test.c
    1.163 06/01/18 22:50:26 konstantin@stripped +65 -0
    A test case for Bug#15613

  sql/protocol.cc
    1.105 06/01/18 22:50:26 konstantin@stripped +16 -2
    A fix for Bug#15613: make sure that result set column length
    is evaluated correctly for BLOB/TEXT columns.

# 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-15613

--- 1.104/sql/protocol.cc	2005-06-05 21:38:41 +04:00
+++ 1.105/sql/protocol.cc	2006-01-18 22:50:26 +03:00
@@ -565,9 +565,23 @@
       else
       {
         /* With conversion */
+        uint max_char_len;
         int2store(pos, thd_charset->number);
-        uint char_len= field.length / item->collation.collation->mbmaxlen;
-        int4store(pos+2, char_len * thd_charset->mbmaxlen);
+        /*
+          For TEXT/BLOB columns, field_length describes the maximum data
+          length in bytes. There is no limit to the number of characters
+          that a TEXT column can store, as long as the data fits into
+          the designated space.
+          For the rest of textual columns, field_length is evaluated as
+          char_count * mbmaxlen, where character count is taken from the
+          definition of the column. In other words, the maximum number
+          of characters here is limited by the column definition.
+        */
+        max_char_len= (field.type >= (int) MYSQL_TYPE_TINY_BLOB &&
+                      field.type <= (int) MYSQL_TYPE_BLOB) ?
+                      field.length / item->collation.collation->mbminlen :
+                      field.length / item->collation.collation->mbmaxlen;
+        int4store(pos+2, max_char_len * thd_charset->mbmaxlen);
       }
       pos[6]= field.type;
       int2store(pos+7,field.flags);

--- 1.162/tests/mysql_client_test.c	2006-01-17 23:19:39 +03:00
+++ 1.163/tests/mysql_client_test.c	2006-01-18 22:50:26 +03:00
@@ -11773,6 +11773,70 @@
 
 
 /*
+  Bug #15613: "libmysqlclient API function mysql_stmt_prepare returns wrong
+  field length"
+*/
+
+static void test_bug15613()
+{
+  MYSQL_STMT *stmt;
+  const char *stmt_text;
+  MYSQL_RES *metadata;
+  MYSQL_FIELD *field;
+  int rc;
+  myheader("test_bug15613");
+
+  /* I. Prepare the table */
+  rc= mysql_query(mysql, "set names latin1");
+  myquery(rc);
+  mysql_query(mysql, "drop table if exists t1");
+  rc= mysql_query(mysql,
+                  "create table t1 (t text character set utf8, "
+                                   "tt tinytext character set utf8, "
+                                   "mt mediumtext character set utf8, "
+                                   "lt longtext character set utf8, "
+                                   "vl varchar(255) character set latin1,"
+                                   "vb varchar(255) character set binary,"
+                                   "vu varchar(255) character set utf8)");
+  myquery(rc);
+
+  stmt= mysql_stmt_init(mysql);
+
+  /* II. Check SELECT metadata */
+  stmt_text= ("select t, tt, mt, lt, vl, vb, vu from t1");
+  rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+  metadata= mysql_stmt_result_metadata(stmt);
+  field= mysql_fetch_fields(metadata);
+  if (!opt_silent)
+  {
+    printf("Field lengths (client character set is latin1):\n"
+           "text character set utf8:\t\t%lu\n"
+           "tinytext character set utf8:\t\t%lu\n"
+           "mediumtext character set utf8:\t\t%lu\n"
+           "longtext character set utf8:\t\t%lu\n"
+           "varchar(255) character set latin1:\t%lu\n"
+           "varchar(255) character set binary:\t%lu\n"
+           "varchar(255) character set utf8:\t%lu\n",
+           field[0].length, field[1].length, field[2].length, field[3].length,
+           field[4].length, field[5].length, field[6].length);
+  }
+  DIE_UNLESS(field[0].length == 65535);
+  DIE_UNLESS(field[1].length == 255);
+  DIE_UNLESS(field[2].length == 16777215);
+  DIE_UNLESS(field[3].length == 4294967295UL);
+  DIE_UNLESS(field[4].length == 255);
+  DIE_UNLESS(field[5].length == 255);
+  DIE_UNLESS(field[6].length == 255);
+
+  /* III. Cleanup */
+  rc= mysql_query(mysql, "drop table t1");
+  myquery(rc);
+  rc= mysql_query(mysql, "set names default");
+  myquery(rc);
+  mysql_stmt_close(stmt);
+}
+
+/*
   Read and parse arguments and MySQL options from my.cnf
 */
 
@@ -11994,6 +12058,7 @@
   { "test_bug11718", test_bug11718 },
   { "test_bug12925", test_bug12925 },
   { "test_bug16144", test_bug16144 },
+  { "test_bug15613", test_bug15613 },
   { 0, 0 }
 };
 
Thread
bk commit into 4.1 tree (konstantin:1.2479) BUG#15613konstantin18 Jan