Commit 61413522 authored by unknown's avatar unknown

WL#2247 mysqltest: add option for sorting results

 - Change from "query_sorted <query>" to "sorted_results"


client/mysqltest.c:
  Replace "query_sorted <query>" with the ability to turn
  on "one shot result sorting" with the command "sorted_results"
mysql-test/r/mysqltest.result:
  Update test and result
mysql-test/t/mysqltest.test:
  Update test and result
parent 7e2ba658
...@@ -271,7 +271,7 @@ enum enum_commands { ...@@ -271,7 +271,7 @@ enum enum_commands {
Q_EXEC, Q_DELIMITER, Q_EXEC, Q_DELIMITER,
Q_DISABLE_ABORT_ON_ERROR, Q_ENABLE_ABORT_ON_ERROR, Q_DISABLE_ABORT_ON_ERROR, Q_ENABLE_ABORT_ON_ERROR,
Q_DISPLAY_VERTICAL_RESULTS, Q_DISPLAY_HORIZONTAL_RESULTS, Q_DISPLAY_VERTICAL_RESULTS, Q_DISPLAY_HORIZONTAL_RESULTS,
Q_QUERY_VERTICAL, Q_QUERY_HORIZONTAL, Q_QUERY_SORTED, Q_QUERY_VERTICAL, Q_QUERY_HORIZONTAL, Q_SORTED_RESULTS,
Q_START_TIMER, Q_END_TIMER, Q_START_TIMER, Q_END_TIMER,
Q_CHARACTER_SET, Q_DISABLE_PS_PROTOCOL, Q_ENABLE_PS_PROTOCOL, Q_CHARACTER_SET, Q_DISABLE_PS_PROTOCOL, Q_ENABLE_PS_PROTOCOL,
Q_DISABLE_RECONNECT, Q_ENABLE_RECONNECT, Q_DISABLE_RECONNECT, Q_ENABLE_RECONNECT,
...@@ -341,7 +341,7 @@ const char *command_names[]= ...@@ -341,7 +341,7 @@ const char *command_names[]=
"horizontal_results", "horizontal_results",
"query_vertical", "query_vertical",
"query_horizontal", "query_horizontal",
"query_sorted", "sorted_results",
"start_timer", "start_timer",
"end_timer", "end_timer",
"character_set", "character_set",
...@@ -6161,13 +6161,19 @@ int main(int argc, char **argv) ...@@ -6161,13 +6161,19 @@ int main(int argc, char **argv)
case Q_DISPLAY_HORIZONTAL_RESULTS: case Q_DISPLAY_HORIZONTAL_RESULTS:
display_result_vertically= FALSE; display_result_vertically= FALSE;
break; break;
case Q_SORTED_RESULTS:
/*
Turn on sorting of result set, will be reset after next
command
*/
display_result_sorted= TRUE;
break;
case Q_LET: do_let(command); break; case Q_LET: do_let(command); break;
case Q_EVAL_RESULT: case Q_EVAL_RESULT:
eval_result = 1; break; eval_result = 1; break;
case Q_EVAL: case Q_EVAL:
case Q_QUERY_VERTICAL: case Q_QUERY_VERTICAL:
case Q_QUERY_HORIZONTAL: case Q_QUERY_HORIZONTAL:
case Q_QUERY_SORTED:
if (command->query == command->query_buf) if (command->query == command->query_buf)
{ {
/* Skip the first part of command, i.e query_xxx */ /* Skip the first part of command, i.e query_xxx */
...@@ -6179,7 +6185,6 @@ int main(int argc, char **argv) ...@@ -6179,7 +6185,6 @@ int main(int argc, char **argv)
case Q_REAP: case Q_REAP:
{ {
my_bool old_display_result_vertically= display_result_vertically; my_bool old_display_result_vertically= display_result_vertically;
my_bool old_display_result_sorted= display_result_sorted;
/* Default is full query, both reap and send */ /* Default is full query, both reap and send */
int flags= QUERY_REAP_FLAG | QUERY_SEND_FLAG; int flags= QUERY_REAP_FLAG | QUERY_SEND_FLAG;
...@@ -6196,7 +6201,6 @@ int main(int argc, char **argv) ...@@ -6196,7 +6201,6 @@ int main(int argc, char **argv)
/* Check for special property for this query */ /* Check for special property for this query */
display_result_vertically|= (command->type == Q_QUERY_VERTICAL); display_result_vertically|= (command->type == Q_QUERY_VERTICAL);
display_result_sorted= (command->type == Q_QUERY_SORTED);
if (save_file[0]) if (save_file[0])
{ {
...@@ -6209,7 +6213,6 @@ int main(int argc, char **argv) ...@@ -6209,7 +6213,6 @@ int main(int argc, char **argv)
/* Restore settings */ /* Restore settings */
display_result_vertically= old_display_result_vertically; display_result_vertically= old_display_result_vertically;
display_result_sorted= old_display_result_sorted;
break; break;
} }
...@@ -6366,6 +6369,9 @@ int main(int argc, char **argv) ...@@ -6366,6 +6369,9 @@ int main(int argc, char **argv)
the replace structures should be cleared the replace structures should be cleared
*/ */
free_all_replace(); free_all_replace();
/* Also reset "sorted_results" */
display_result_sorted= FALSE;
} }
last_command_executed= command_executed; last_command_executed= command_executed;
......
...@@ -546,6 +546,12 @@ a b c ...@@ -546,6 +546,12 @@ a b c
2 Part 2 2007-04-05 00:00:00 2 Part 2 2007-04-05 00:00:00
2 Part 3 2007-04-05 00:00:00 2 Part 3 2007-04-05 00:00:00
select * from t1; select * from t1;
a b c
1 Line 1 2007-04-05 00:00:00
2 Part 2 2007-04-05 00:00:00
1 Line 1 2007-04-05 00:00:00
2 Part 3 2007-04-05 00:00:00
select * from t1;
select ''; select '';
...@@ -561,4 +567,50 @@ hep ...@@ -561,4 +567,50 @@ hep
select "hepp"; select "hepp";
hepp hepp
hepp hepp
drop table t1;
SELECT 2 as "my_col"
UNION
SELECT 1;
my_col
1
2
SELECT 2 as "my_col" UNION SELECT 1;
my_col
1
2
SELECT 2 as "my_col"
UNION
SELECT 1;
my_col
1
2
SELECT '2' as "3"
UNION
SELECT '1';
3
1
2
SET @a = 17;
SELECT 2 as "my_col"
UNION
SELECT 1;
my_col
1
2
SELECT 2 as "my_col"
UNION
SELECT 1;
my_col
2
1
SELECT 2 as "my_col"
UNION
SELECT 1;
my_col
1
2
SELECT '2' as "my_col1",2 as "my_col2"
UNION
SELECT '1',1 from t2;
ERROR 42S02: Table 'test.t2' doesn't exist
End of tests End of tests
...@@ -1693,15 +1693,72 @@ create table t1( a int, b char(255), c timestamp); ...@@ -1693,15 +1693,72 @@ create table t1( a int, b char(255), c timestamp);
insert into t1 values(1, 'Line 1', '2007-04-05'), (2, "Part 2", '2007-04-05'); insert into t1 values(1, 'Line 1', '2007-04-05'), (2, "Part 2", '2007-04-05');
insert into t1 values(1, 'Line 1', '2007-04-05'), (2, "Part 3", '2007-04-05'); insert into t1 values(1, 'Line 1', '2007-04-05'), (2, "Part 3", '2007-04-05');
select * from t1; select * from t1;
query_sorted select * from t1; --sorted_results
select * from t1;
# Should not be sorted
select * from t1;
disable_result_log; disable_result_log;
query_sorted select * from t1; sorted_results;
select * from t1;
enable_result_log; enable_result_log;
query_sorted select ''; --sorted_results
query_sorted select "h"; select '';
query_sorted select "he"; sorted_results;
query_sorted select "hep"; select "h";
query_sorted select "hepp"; --sorted_results
select "he";
--sorted_results
select "hep";
--sorted_results
select "hepp";
drop table t1;
# 1. Assignment of result set sorting
sorted_results;
SELECT 2 as "my_col"
UNION
SELECT 1;
--sorted_results
SELECT 2 as "my_col" UNION SELECT 1;
--sorted_results
SELECT 2 as "my_col"
UNION
SELECT 1;
# 2. Ensure that the table header will be not sorted into the result
--sorted_results
SELECT '2' as "3"
UNION
SELECT '1';
# 3. "sorted_results" changes nothing when applied to a non query statement.
sorted_results;
SET @a = 17;
# 4. Show that "--sorted_results" affects the next statement only
--sorted_results
SELECT 2 as "my_col"
UNION
SELECT 1;
SELECT 2 as "my_col"
UNION
SELECT 1;
# 5. Ensure that "sorted_results" in combination with $variables works
let $my_stmt=SELECT 2 as "my_col"
UNION
SELECT 1;
--sorted_results
eval $my_stmt;
# 6. Ensure that "sorted_results " does not change the semantics of "--error ...."
# or the protocol output after such an expected failure
--sorted_results
--error 1146
SELECT '2' as "my_col1",2 as "my_col2"
UNION
SELECT '1',1 from t2;
--echo End of tests --echo End of tests
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment