From: Mayank Prasad Date: June 10 2011 3:21pm Subject: bzr push into mysql-5.5 branch (mayank.prasad:3443 to 3444) Bug#12337762 List-Archive: http://lists.mysql.com/commits/139079 X-Bug: 12337762 Message-Id: <201106101521.p5AFLBr6003266@acsmt357.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 3444 Mayank Prasad 2011-06-10 Bug#12337762 : MYSQL_LIST_FIELDS() RETURNS WRONG CHARSET FOR CHAR/VARCHAR/TEXT COLUMNS IN VIEWS Issue: charset value for a Column, returned by MYSQL_LIST_FIELDS(), was not same for Table and View. This was because, for view, field charset was not being returned. Solution: Added definition of function "charset_for_protocol()" in calss Item_ident_for_show to return field charset value. @ sql/item.h Added definition for charset_for_protocol() function to return field charset. @ tests/mysql_client_test.c Added a test case test_bug12337762 for the changes done. modified: sql/item.h tests/mysql_client_test.c 3443 Daniel Fischer 2011-06-10 RETURN doesn't exactly return from the macro... modified: cmake/plugin.cmake === modified file 'sql/item.h' --- a/sql/item.h 2011-04-08 13:15:23 +0000 +++ b/sql/item.h 2011-06-10 14:26:35 +0000 @@ -1672,6 +1672,8 @@ public: String *val_str(String *str) { return field->val_str(str); } my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); } void make_field(Send_field *tmp_field); + CHARSET_INFO *charset_for_protocol(void) const + { return field->charset_for_protocol(); } }; === modified file 'tests/mysql_client_test.c' --- a/tests/mysql_client_test.c 2011-06-06 10:27:05 +0000 +++ b/tests/mysql_client_test.c 2011-06-10 14:26:35 +0000 @@ -19588,6 +19588,81 @@ static void test_bug11766854() DBUG_VOID_RETURN; } +/** + Bug#12337762: 60075: MYSQL_LIST_FIELDS() RETURNS WRONG CHARSET FOR + CHAR/VARCHAR/TEXT COLUMNS IN VIEWS +*/ +static void test_bug12337762() +{ + int rc,i=0; + MYSQL_RES *result; + MYSQL_FIELD *field; + unsigned int tab_charsetnr[3]= {0}; + + DBUG_ENTER("test_bug12337762"); + myheader("test_bug12337762"); + + /* + Creating table with specific charset. + */ + rc= mysql_query(mysql, "drop table if exists charset_tab"); + rc= mysql_query(mysql, "create table charset_tab("\ + "txt1 varchar(32) character set Latin1,"\ + "txt2 varchar(32) character set Latin1 collate latin1_bin,"\ + "txt3 varchar(32) character set utf8 collate utf8_bin"\ + ")"); + + DIE_UNLESS(rc == 0); + DIE_IF(mysql_errno(mysql)); + + /* + Creating view from table created earlier. + */ + rc= mysql_query(mysql, "drop view if exists charset_view"); + rc= mysql_query(mysql, "create view charset_view as "\ + "select * from charset_tab;"); + DIE_UNLESS(rc == 0); + DIE_IF(mysql_errno(mysql)); + + /* + Checking field information for table. + */ + result= mysql_list_fields(mysql, "charset_tab", NULL); + DIE_IF(mysql_errno(mysql)); + i=0; + while((field= mysql_fetch_field(result))) + { + printf("field name %s\n", field->name); + printf("field table %s\n", field->table); + printf("field type %d\n", field->type); + printf("field charset %d\n", field->charsetnr); + tab_charsetnr[i++]= field->charsetnr; + printf("\n"); + } + mysql_free_result(result); + + /* + Checking field information for view. + */ + result= mysql_list_fields(mysql, "charset_view", NULL); + DIE_IF(mysql_errno(mysql)); + i=0; + while((field= mysql_fetch_field(result))) + { + printf("field name %s\n", field->name); + printf("field table %s\n", field->table); + printf("field type %d\n", field->type); + printf("field charset %d\n", field->charsetnr); + printf("\n"); + /* + charset value for field must be same for both, view and table. + */ + DIE_UNLESS(field->charsetnr == tab_charsetnr[i++]); + } + mysql_free_result(result); + + DBUG_VOID_RETURN; +} /* Read and parse arguments and MySQL options from my.cnf @@ -19933,6 +20008,7 @@ static struct my_tests_st my_tests[]= { { "test_bug57058", test_bug57058 }, { "test_bug56976", test_bug56976 }, { "test_bug11766854", test_bug11766854 }, + { "test_bug12337762", test_bug12337762 }, { 0, 0 } }; @@ -20071,29 +20147,29 @@ int main(int argc, char **argv) if (!argc) { for (fptr= my_tests; fptr->name; fptr++) - (*fptr->function)(); + (*fptr->function)(); } else { for ( ; *argv ; argv++) { - for (fptr= my_tests; fptr->name; fptr++) - { - if (!strcmp(fptr->name, *argv)) - { - (*fptr->function)(); - break; - } - } - if (!fptr->name) - { - fprintf(stderr, "\n\nGiven test not found: '%s'\n", *argv); - fprintf(stderr, "See legal test names with %s -T\n\nAborting!\n", - my_progname); - client_disconnect(mysql, 1); - free_defaults(defaults_argv); - exit(1); - } + for (fptr= my_tests; fptr->name; fptr++) + { + if (!strcmp(fptr->name, *argv)) + { + (*fptr->function)(); + break; + } + } + if (!fptr->name) + { + fprintf(stderr, "\n\nGiven test not found: '%s'\n", *argv); + fprintf(stderr, "See legal test names with %s -T\n\nAborting!\n", + my_progname); + client_disconnect(mysql, 1); + free_defaults(defaults_argv); + exit(1); + } } } No bundle (reason: useless for push emails).