diff options
author | unknown <kroki/tomash@moonlight.intranet> | 2006-11-22 13:58:00 +0300 |
---|---|---|
committer | unknown <kroki/tomash@moonlight.intranet> | 2006-11-22 13:58:00 +0300 |
commit | 18770d2fe4956e9be33a73cfc790129c19c6305a (patch) | |
tree | 39c6df66fba0d7fb2e327bab5949bc349cb8e3a1 | |
parent | 2886e07d3fa72d8aac8091c581adccb7a666a411 (diff) | |
download | mariadb-git-18770d2fe4956e9be33a73cfc790129c19c6305a.tar.gz |
BUG#21635: MYSQL_FIELD struct's member strings seem to misbehave for
expression cols.
The problem was that MYSQL_FIELD::org_name was set for MIN() and MAX()
functions (COUNT() is also mentioned in the bug report but was already
fixed).
After this patch for expressions MYSQL_FIELD::name is set to either
expression itself or its alias, and other data origin fields of
MYSQL_FILED (db, org_table, table, org_name) are empty strings.
sql/item_sum.cc:
For expressions only col_name should be non-empty string.
tests/mysql_client_test.c:
Add test case for bug#21635: MYSQL_FIELD struct's member strings seem
to misbehave for expression cols.
-rw-r--r-- | sql/item_sum.cc | 10 | ||||
-rw-r--r-- | tests/mysql_client_test.c | 68 |
2 files changed, 75 insertions, 3 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 5fd65fecbfc..87c768e9383 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -71,9 +71,13 @@ void Item_sum::make_field(Send_field *tmp_field) if (args[0]->type() == Item::FIELD_ITEM && keep_field_type()) { ((Item_field*) args[0])->field->make_field(tmp_field); - tmp_field->db_name=(char*)""; - tmp_field->org_table_name=tmp_field->table_name=(char*)""; - tmp_field->org_col_name=tmp_field->col_name=name; + /* For expressions only col_name should be non-empty string. */ + char *empty_string= (char*)""; + tmp_field->db_name= empty_string; + tmp_field->org_table_name= empty_string; + tmp_field->table_name= empty_string; + tmp_field->org_col_name= empty_string; + tmp_field->col_name= name; if (maybe_null) tmp_field->flags&= ~NOT_NULL_FLAG; } diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 6ae9dcb9476..eb9559499bf 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -11946,6 +11946,73 @@ static void test_bug21726() /* + BUG#21635: MYSQL_FIELD struct's member strings seem to misbehave for + expression cols + + Check that for MIN(), MAX(), COUNT() only MYSQL_FIELD::name is set + to either expression or its alias, and db, org_table, table, + org_name fields are empty strings. +*/ +static void test_bug21635() +{ + const char *expr[]= + { + "MIN(i)", "MIN(i)", + "MIN(i) AS A1", "A1", + "MAX(i)", "MAX(i)", + "MAX(i) AS A2", "A2", + "COUNT(i)", "COUNT(i)", + "COUNT(i) AS A3", "A3", + }; + const char *query_end; + MYSQL_RES *result; + MYSQL_FIELD *field; + unsigned int field_count, i; + int rc; + + DBUG_ENTER("test_bug21635"); + myheader("test_bug21635"); + + query_end= strxmov(query, "SELECT ", NullS); + for (i= 0; i < sizeof(expr) / sizeof(*expr) / 2; ++i) + query_end= strxmov(query_end, expr[i * 2], ", ", NullS); + query_end= strxmov(query_end - 2, " FROM t1 GROUP BY i", NullS); + DIE_UNLESS(query_end - query < MAX_TEST_QUERY_LENGTH); + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + myquery(rc); + rc= mysql_query(mysql, "CREATE TABLE t1 (i INT)"); + myquery(rc); + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)"); + myquery(rc); + + rc= mysql_real_query(mysql, query, query_end - query); + myquery(rc); + + result= mysql_use_result(mysql); + DIE_UNLESS(result); + + field_count= mysql_field_count(mysql); + for (i= 0; i < field_count; ++i) + { + field= mysql_fetch_field_direct(result, i); + printf("%s -> %s ... ", expr[i * 2], field->name); + fflush(stdout); + DIE_UNLESS(field->db[0] == 0 && field->org_table[0] == 0 && + field->table[0] == 0 && field->org_name[0] == 0); + DIE_UNLESS(strcmp(field->name, expr[i * 2 + 1]) == 0); + puts("OK"); + } + + mysql_free_result(result); + rc= mysql_query(mysql, "DROP TABLE t1"); + myquery(rc); + + DBUG_VOID_RETURN; +} + + +/* Read and parse arguments and MySQL options from my.cnf */ @@ -12172,6 +12239,7 @@ static struct my_tests_st my_tests[]= { { "test_bug15613", test_bug15613 }, { "test_bug20152", test_bug20152 }, { "test_bug21726", test_bug21726 }, + { "test_bug21635", test_bug21635 }, { 0, 0 } }; |