Commit 10061029 authored by unknown's avatar unknown
Browse files

Merge sanja.is.com.ua:/home/bell/mysql/bk/mysql-5.0

into sanja.is.com.ua:/home/bell/mysql/bk/work-bug3-5.0

parents e1c2646a 970e20b7
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -1352,7 +1352,13 @@ class Item_ref :public Item_ident
  {
    (*ref)->save_in_field(result_field, no_conversions);
  }
  Item *real_item() { return *ref; }
  Item *real_item() {
    Item *item= this;
    do
      item= *((Item_ref *)item)->ref;
    while (item->type() == Item::REF_ITEM);
    return item;
  }
  bool walk(Item_processor processor, byte *arg)
  { return (*ref)->walk(processor, arg); }
  void print(String *str);
+13 −1
Original line number Diff line number Diff line
@@ -7957,6 +7957,19 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
                                       modify_item ? (Item_field*) item : NULL,
                                       convert_blob_length);
  }
  case Item::REF_ITEM:
    if ( ((Item_ref*)item)->real_item()->type() == Item::FIELD_ITEM)
    {
      Item_field *field= (Item_field*) *((Item_ref*)item)->ref;
      Field *new_field= create_tmp_field_from_field(thd, 
                               (*from_field= field->field),
                               item->name, table,
                               NULL,
                               convert_blob_length);
      if (modify_item)
        item->set_result_field(new_field);
      return new_field;
    }
  case Item::FUNC_ITEM:
  case Item::COND_ITEM:
  case Item::FIELD_AVG_ITEM:
@@ -7968,7 +7981,6 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
  case Item::REAL_ITEM:
  case Item::DECIMAL_ITEM:
  case Item::STRING_ITEM:
  case Item::REF_ITEM:
  case Item::NULL_ITEM:
  case Item::VARBIN_ITEM:
    return create_tmp_field_from_item(thd, item, table, copy_func, modify_item,
+43 −0
Original line number Diff line number Diff line
@@ -13145,6 +13145,48 @@ static void test_bug9643()
  myquery(rc);
}

/*
  Bug#11111: fetch from view returns wrong data
*/

static void test_bug11111()
{
  MYSQL_STMT 	*stmt;
  MYSQL_BIND	bind[2];
  char		buf[2][20];
  long		len[2];
  int i;
  const char * query = "SELECT DISTINCT f1,ff2 FROM v1";

  mysql_query(mysql, "drop table if exists t1, t2, v1");
  mysql_query(mysql, "create table t1 (f1 int, f2 int)");
  mysql_query(mysql, "create table t2 (ff1 int, ff2 int)");
  mysql_query(mysql, "create view v1 as select * from t1, t2 where f1=ff1");
  mysql_query(mysql, "insert into t1 values (1,1), (2,2), (3,3)");
  mysql_query(mysql, "insert into t2 values (1,1), (2,2), (3,3)");

  stmt = mysql_stmt_init(mysql);

  mysql_stmt_prepare(stmt, query, strlen(query));
  mysql_stmt_execute(stmt);

  for (i=0; i < 2; i++) {
    memset(&bind[i], '\0', sizeof(MYSQL_BIND));
    bind[i].buffer_type= MYSQL_TYPE_STRING;
    bind[i].buffer= (gptr *)&buf[i];
    bind[i].buffer_length= 20;
    bind[i].length= &len[i];
  } 

  if (mysql_stmt_bind_result(stmt, bind))
    printf("Error: %s\n", mysql_stmt_error(stmt));

  mysql_stmt_fetch(stmt);
  DIE_UNLESS(!strcmp(buf[1],"1"));	
  mysql_stmt_close(stmt);
  mysql_query(mysql, "drop table t1, t2, v1");
}

/*
  Check that proper cleanups are done for prepared statement when
  fetching thorugh a cursor.
@@ -13439,6 +13481,7 @@ static struct my_tests_st my_tests[]= {
  { "test_bug9478", test_bug9478 },
  { "test_bug9643", test_bug9643 },
  { "test_bug10729", test_bug10729 },
  { "test_bug11111", test_bug11111 },
  { 0, 0 }
};