diff options
author | Mayank Prasad <mayank.prasad@oracle.com> | 2011-06-10 19:56:35 +0530 |
---|---|---|
committer | Mayank Prasad <mayank.prasad@oracle.com> | 2011-06-10 19:56:35 +0530 |
commit | eecaad9dccd790f82dc2c032d6bb8101feab1fdf (patch) | |
tree | 909ed1b5c60eb44e690847a088e23a71cca97735 /tests | |
parent | f089d2e87095f10785b0b6d8a023fca397674558 (diff) | |
download | mariadb-git-eecaad9dccd790f82dc2c032d6bb8101feab1fdf.tar.gz |
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.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/mysql_client_test.c | 112 |
1 files changed, 94 insertions, 18 deletions
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index e789831b3f2..5401e360f33 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -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); + } } } |