From 4d8cbb0c27126b897ce26e53e2287c898004a33c Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 15 Jun 2005 01:57:25 +0300 Subject: [PATCH] fix of BUG#11111 fix sql/item.h: revrited as recursive sql/sql_select.cc: real_type is virtual tests/mysql_client_test.c: check results abd delete views --- sql/item.h | 9 +++------ sql/sql_select.cc | 2 +- tests/mysql_client_test.c | 32 +++++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/sql/item.h b/sql/item.h index 2629f94a903..4a86dfc60f3 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1352,12 +1352,9 @@ public: { (*ref)->save_in_field(result_field, no_conversions); } - Item *real_item() { - Item *item= this; - do - item= *((Item_ref *)item)->ref; - while (item->type() == Item::REF_ITEM); - return item; + Item *real_item() + { + return (*ref)->real_item(); } bool walk(Item_processor processor, byte *arg) { return (*ref)->walk(processor, arg); } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index c416b81bf1b..b5de7313c57 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -7958,7 +7958,7 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type, convert_blob_length); } case Item::REF_ITEM: - if ( ((Item_ref*)item)->real_item()->type() == Item::FIELD_ITEM) + if ( 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, diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index fb18c83b30e..7a683659df6 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -13156,14 +13156,24 @@ static void test_bug11111() char buf[2][20]; long len[2]; int i; + int rc; const char * query = "SELECT DISTINCT f1,ff2 FROM v1"; + myheader("test_bug11111"); - 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)"); + rc= mysql_query(mysql, "drop table if exists t1, t2, v1"); + myquery(rc); + rc= mysql_query(mysql, "drop view if exists t1, t2, v1"); + myquery(rc); + rc= mysql_query(mysql, "create table t1 (f1 int, f2 int)"); + myquery(rc); + rc= mysql_query(mysql, "create table t2 (ff1 int, ff2 int)"); + myquery(rc); + rc= mysql_query(mysql, "create view v1 as select * from t1, t2 where f1=ff1"); + myquery(rc); + rc= mysql_query(mysql, "insert into t1 values (1,1), (2,2), (3,3)"); + myquery(rc); + rc= mysql_query(mysql, "insert into t2 values (1,1), (2,2), (3,3)"); + myquery(rc); stmt = mysql_stmt_init(mysql); @@ -13176,15 +13186,19 @@ static void test_bug11111() 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")); + printf("return: %s", buf[1]); + DIE_UNLESS(!strcmp(buf[1],"1")); mysql_stmt_close(stmt); - mysql_query(mysql, "drop table t1, t2, v1"); + rc= mysql_query(mysql, "drop view v1"); + myquery(rc); + rc= mysql_query(mysql, "drop table t1, t2"); + myquery(rc); } /*