From 8deafa8037b289d089ffeb8d6bdaee812113a9b0 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 25 Jan 2005 14:30:38 -0800 Subject: [PATCH 1/3] order_by.result, order_by.test: Added a test case for bug #7672. sql_yacc.yy: Fixed bug #7672. Made queries of the form (SELECT ...) ORDER BY ... to be equivalent to SELECT ... ORDER BY ... sql/sql_yacc.yy: Fixed bug #7672. Made queries of the form (SELECT ...) ORDER BY ... to be equivalent to SELECT ... ORDER BY ... mysql-test/t/order_by.test: Added a test case for bug #7672. mysql-test/r/order_by.result: Added a test case for bug #7672. --- mysql-test/r/order_by.result | 17 +++++++++++++++++ mysql-test/t/order_by.test | 13 ++++++++++++- sql/sql_yacc.yy | 13 ++++++++----- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result index 859d9d4cab0..4ea638dbc19 100644 --- a/mysql-test/r/order_by.result +++ b/mysql-test/r/order_by.result @@ -554,3 +554,20 @@ explain select id,t from t1 force index (primary) order by id; table type possible_keys key key_len ref rows Extra t1 index NULL PRIMARY 4 NULL 1000 drop table t1; +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (2), (1), (1), (2), (1); +SELECT a FROM t1 ORDER BY a; +a +1 +1 +1 +2 +2 +(SELECT a FROM t1) ORDER BY a; +a +1 +1 +1 +2 +2 +DROP TABLE t1; diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test index 86ecc4aa70d..d65b2c257a1 100644 --- a/mysql-test/t/order_by.test +++ b/mysql-test/t/order_by.test @@ -363,4 +363,15 @@ while ($1) enable_query_log; explain select id,t from t1 order by id; explain select id,t from t1 force index (primary) order by id; -drop table t1; \ No newline at end of file +drop table t1; + +# +# Bug #7672 - a wrong result for a select query in braces followed by order by +# + +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (2), (1), (1), (2), (1); +SELECT a FROM t1 ORDER BY a; +(SELECT a FROM t1) ORDER BY a; +DROP TABLE t1; + diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 7b72c73a915..6d0237f5615 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -4033,11 +4033,14 @@ optional_order_or_limit: send_error(&lex->thd->net, ER_SYNTAX_ERROR); YYABORT; } - if (mysql_new_select(lex)) - YYABORT; - mysql_init_select(lex); - lex->select->linkage=NOT_A_SELECT; - lex->select->select_limit=lex->thd->variables.select_limit; + if (lex->select != &lex->select_lex) + { + if (mysql_new_select(lex)) + YYABORT; + mysql_init_select(lex); + lex->select->linkage=NOT_A_SELECT; + lex->select->select_limit=lex->thd->variables.select_limit; + } } opt_order_clause limit_clause ; From b8cac714940514879ab3e61eb0d2ee473de9d5dc Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 27 Jan 2005 14:48:26 -0600 Subject: [PATCH 2/3] Bug #5185 mysqldump for windows database gets table names with different case Added the get_actual_table_name function that issues a SHOW TABLES LIKE '%s'. This will get the table name in the proper case. We use this table name rather than the one given on the command line. This will prevent problems when importing SQL on Linux that was generated on a Windows platform where case can be an issue. mysqldump.c: call get_actual_table_name to get the table name in the proper case client/mysqldump.c: call get_actual_table_name to get the table name in the proper case --- client/mysqldump.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 00f5272e3d7..db86a3714c1 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -2082,6 +2082,34 @@ static int dump_all_tables_in_db(char *database) } /* dump_all_tables_in_db */ +/* + get_actual_table_name -- executes a SHOW TABLES LIKE '%s' to get the actual table name + from the server for the table name given on the command line. we do this because + the table name given on the command line may be a different case (e.g. T1 vs t1) + + RETURN + void +*/ +static void get_actual_table_name( const char *old_table_name, char *new_table_name, int buf_size ) +{ + MYSQL_RES *tableRes; + MYSQL_ROW row; + char query[ NAME_LEN*2+3 + 50 ]; + + DBUG_ENTER("get_actual_table_name"); + + sprintf( query, "SHOW TABLES LIKE '%s'", old_table_name ); + if (mysql_query_with_error_report(sock, 0, query)) + { + safe_exit(EX_MYSQLERR); + } + + tableRes = mysql_store_result( sock ); + row = mysql_fetch_row( tableRes ); + strncpy( new_table_name, row[0], buf_size ); + mysql_free_result(tableRes); +} /* get_actual_table_name */ + static int dump_selected_tables(char *db, char **table_names, int tables) { @@ -2116,9 +2144,14 @@ static int dump_selected_tables(char *db, char **table_names, int tables) print_xml_tag1(md_result_file, "", "database name=", db, "\n"); for (; tables > 0 ; tables-- , table_names++) { - numrows = getTableStructure(*table_names, db); + char new_table_name[NAME_LEN*+3]; + + /* the table name passed on commandline may be wrong case */ + get_actual_table_name( *table_names, new_table_name, sizeof(new_table_name) ); + + numrows = getTableStructure(new_table_name, db); if (!dFlag && numrows > 0) - dumpTable(numrows, *table_names); + dumpTable(numrows, new_table_name); my_free(order_by, MYF(MY_ALLOW_ZERO_PTR)); order_by= 0; } From 79016ecb2c068effd0dee57e96c610988825c074 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 29 Jan 2005 09:25:56 -0600 Subject: [PATCH 3/3] Bug #5185 mysqldump for windows database gets table names with different case mysqldump.c: Trimmed some lines to be less than 80 chars. Using just NAME_LEN now for table name buffers client/mysqldump.c: Trimmed some lines to be less than 80 chars. Using just NAME_LEN now for table name buffers --- client/mysqldump.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index db86a3714c1..3a93adf5b36 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -2083,18 +2083,21 @@ static int dump_all_tables_in_db(char *database) /* - get_actual_table_name -- executes a SHOW TABLES LIKE '%s' to get the actual table name - from the server for the table name given on the command line. we do this because - the table name given on the command line may be a different case (e.g. T1 vs t1) + get_actual_table_name -- executes a SHOW TABLES LIKE '%s' to get the actual + table name from the server for the table name given on the command line. + we do this because the table name given on the command line may be a + different case (e.g. T1 vs t1) RETURN void */ -static void get_actual_table_name( const char *old_table_name, char *new_table_name, int buf_size ) +static void get_actual_table_name( const char *old_table_name, + char *new_table_name, + int buf_size ) { MYSQL_RES *tableRes; MYSQL_ROW row; - char query[ NAME_LEN*2+3 + 50 ]; + char query[ NAME_LEN + 50 ]; DBUG_ENTER("get_actual_table_name"); @@ -2144,7 +2147,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) print_xml_tag1(md_result_file, "", "database name=", db, "\n"); for (; tables > 0 ; tables-- , table_names++) { - char new_table_name[NAME_LEN*+3]; + char new_table_name[NAME_LEN]; /* the table name passed on commandline may be wrong case */ get_actual_table_name( *table_names, new_table_name, sizeof(new_table_name) );