MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:eugene Date:August 17 2005 7:53pm
Subject:bk commit into 4.1 tree (evgen:1.2383) BUG#11718
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of evgen. When evgen 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.2383 05/08/17 23:53:12 evgen@stripped +2 -0
  Fix bug #11718 query with function, join and order by returns wrong type.
  
  create_tmp_field_from_item() was creating tmp field without regard to
  original field type of Item. This results in wrong type being reported to
  client.
  
  To create_tmp_field_from_item() added special handling for Items with 
  DATE/TIME field types to preserve their type.

  tests/mysql_client_test.c
    1.156 05/08/17 23:38:42 evgen@stripped +35 -0
    Test case for bug #11718: query with function, join and order by returns wrong type

  sql/sql_select.cc
    1.431 05/08/17 23:33:38 evgen@stripped +9 -1
    Fix bug #11718 query with function, join and order by returns wrong type.

# 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:	evgen
# Host:	moonbone.local
# Root:	/work/11718-bug-4.1-mysql

--- 1.430/sql/sql_select.cc	2005-08-16 08:26:07 +04:00
+++ 1.431/sql/sql_select.cc	2005-08-17 23:33:38 +04:00
@@ -4899,7 +4899,15 @@
 				   item->name, table, item->unsigned_flag);
     break;
   case STRING_RESULT:
-    if (item->max_length > 255)
+    enum enum_field_types type;
+    /*
+      DATE/TIME fields have STRING_RESULT result type. To preserve
+      type they needed to be handled separately.
+    */
+    if ((type= item->field_type()) == MYSQL_TYPE_DATETIME ||
+        type == MYSQL_TYPE_TIME || type == MYSQL_TYPE_DATE)
+      new_field= item->tmp_table_field_from_field_type(table);
+    else if (item->max_length > 255)
     {
       if (convert_blob_length)
         new_field= new Field_varstring(convert_blob_length, maybe_null,

--- 1.155/tests/mysql_client_test.c	2005-07-28 22:24:03 +04:00
+++ 1.156/tests/mysql_client_test.c	2005-08-17 23:38:42 +04:00
@@ -11797,6 +11797,40 @@
 }
 
 /*
+  Bug#11718: query with function, join and order by returns wrong type
+*/
+
+static void test_bug11718()
+{
+  MYSQL_RES	*res;
+  int rc;
+  const char *query= "select str_to_date(concat(f3),'%Y%m%d') from t1,t2 "
+                     "where f1=f2 order by f1";
+
+  myheader("test_bug11718");
+
+  rc= mysql_query(mysql, "drop table if exists t1, t2");
+  myquery(rc);
+  rc= mysql_query(mysql, "create table t1 (f1 int)");
+  myquery(rc);
+  rc= mysql_query(mysql, "create table t2 (f2 int, f3 numeric(8))");
+  myquery(rc);
+  rc= mysql_query(mysql, "insert into t1 values (1), (2)");
+  myquery(rc);
+  rc= mysql_query(mysql, "insert into t2 values (1,20050101), (2,20050202)");
+  myquery(rc);
+  rc= mysql_query(mysql, query);
+  myquery(rc);
+  res = mysql_store_result(mysql);
+
+  if (!opt_silent)
+    printf("return type: %s", (res->fields[0].type == MYSQL_TYPE_DATE)?"DATE":
+           "not DATE");
+  DIE_UNLESS(res->fields[0].type == MYSQL_TYPE_DATE);
+  rc= mysql_query(mysql, "drop table t1, t2");
+  myquery(rc);
+}
+/*
   Read and parse arguments and MySQL options from my.cnf
 */
 
@@ -12013,6 +12047,7 @@
   { "test_bug9735", test_bug9735 },
   { "test_bug11183", test_bug11183 },
   { "test_bug12001", test_bug12001 },
+  { "test_bug11718", test_bug11718 },
   { 0, 0 }
 };
 
Thread
bk commit into 4.1 tree (evgen:1.2383) BUG#11718eugene17 Aug