From: Date: June 14 2005 7:31pm Subject: bk commit into 5.0 tree (evgen:1.1934) BUG#11111 List-Archive: http://lists.mysql.com/internals/25978 X-Bug: 11111 Message-Id: <20050614173135.AA37D13EAE8@localhost.moonbone.local> Below is the list of changes that have just been committed into a local 5.0 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.1934 05/06/14 21:31:31 evgen@stripped +3 -0 Fix bug #11111 "fetch from view returns wrong data" Wrong method for creating temporary field was choosen, which results in sending int field with int header but lonlong data. Test case is added to mysql_client_test.c because client library is required to test the bug. tests/mysql_client_test.c 1.123 05/06/14 21:30:27 evgen@stripped +43 -0 Test case for bug#11111 "fetch from view returns wrong data" sql/sql_select.cc 1.334 05/06/14 21:29:30 evgen@stripped +13 -1 Fix bug #11111 "fetch from view returns wrong data" sql/item.h 1.137 05/06/14 21:29:18 evgen@stripped +7 -0 Fix bug #11111 "fetch from view returns wrong data" # 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/mysql-5.0-bug-11111 --- 1.136/sql/item.h 2005-06-07 17:00:28 +04:00 +++ 1.137/sql/item.h 2005-06-14 21:29:18 +04:00 @@ -1357,6 +1357,13 @@ { return (*ref)->walk(processor, arg); } void print(String *str); void cleanup(); + inline bool is_field_ref() { + Item *item= this; + do + item= *((Item_ref *)item)->ref; + while (item->type() == Item::REF_ITEM); + return item->type() == Item::FIELD_ITEM; + } }; --- 1.333/sql/sql_select.cc 2005-06-13 17:28:15 +04:00 +++ 1.334/sql/sql_select.cc 2005-06-14 21:29:30 +04:00 @@ -7957,6 +7957,19 @@ modify_item ? (Item_field*) item : NULL, convert_blob_length); } + case Item::REF_ITEM: + if ( ((Item_ref*)item)->is_field_ref() ) + { + 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 @@ 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, --- 1.122/tests/mysql_client_test.c 2005-06-09 18:17:37 +04:00 +++ 1.123/tests/mysql_client_test.c 2005-06-14 21:30:27 +04:00 @@ -13146,6 +13146,48 @@ } /* + 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 @@ { "test_bug9478", test_bug9478 }, { "test_bug9643", test_bug9643 }, { "test_bug10729", test_bug10729 }, + { "test_bug11111", test_bug11111 }, { 0, 0 } };