1
-- source include/have_log_bin.inc
3
# This test should work in embedded server after mysqltest is fixed
4
-- source include/not_embedded.inc
6
# This test uses chmod, can't be run with root permissions
7
-- source include/not_as_root.inc
9
# ============================================================================
11
# Test of mysqltest itself
13
# There are three rules that determines what belong to each command
14
# 1. A normal command is delimited by the <delimiter> which by default is
20
# Command: "select * from t1"
22
# 2. Special case is a line that starts with "--", this is a comment
23
# ended when the new line character is reached. But the first word
24
# in the comment may contain a valid command, which then will be
25
# executed. This can be useful when sending commands that
26
# contains <delimiter>
28
# 3. Special case is also a line that starts with '#' which is treated
29
# as a comment and will be ended by new line character
31
# ============================================================================
33
# ----------------------------------------------------------------------------
34
# $mysql_errno contains the return code of the last command
36
# ----------------------------------------------------------------------------
37
# get $mysql_errno before the first statement
38
# $mysql_errno should be -1
39
eval select $mysql_errno as "before_use_test" ;
42
# ----------------------------------------------------------------------------
43
# Positive case(statement)
44
# ----------------------------------------------------------------------------
46
select otto from (select 1 as otto) as t1;
47
# expectation = response
49
select otto from (select 1 as otto) as t1;
51
# ----------------------------------------------------------------------------
52
# Negative case(statement):
53
# The derived table t1 does not contain a column named 'friedrich' .
54
# --> ERROR 42S22: Unknown column 'friedrich' in 'field list and
55
# --> 1054: Unknown column 'friedrich' in 'field list'
56
# ----------------------------------------------------------------------------
58
# expectation <> response
60
#select friedrich from (select 1 as otto) as t1
62
--exec echo "select friedrich from (select 1 as otto) as t1;" | $MYSQL_TEST 2>&1
64
# expectation = response
66
select friedrich from (select 1 as otto) as t1;
68
# The following unmasked unsuccessful statement must give
69
# 1. mysqltest gives a 'failed'
70
# 2. does not produce a r/<test case>.reject file !!!
71
# PLEASE uncomment it and check its effect
72
#select friedrich from (select 1 as otto) as t1;
75
# ----------------------------------------------------------------------------
76
# Tests for the new feature - SQLSTATE error code matching
77
# Positive case(statement)
78
# ----------------------------------------------------------------------------
80
# This syntax not allowed anymore, use --error S00000, see below
81
# expectation = response
82
#!S00000 select otto from (select 1 as otto) as t1;
85
select otto from (select 1 as otto) as t1;
87
# expectation <> response
88
#!S42S22 select otto from (select 1 as otto) as t1;
90
#select otto from (select 1 as otto) as t1;
92
--exec echo "error S42S22; select otto from (select 1 as otto) as t1;" | $MYSQL_TEST 2>&1
96
# ----------------------------------------------------------------------------
97
# Negative case(statement)
98
# ----------------------------------------------------------------------------
100
# This syntax not allowed anymore, use --error S42S22, see below
101
# expectation = response
102
#!S42S22 select friedrich from (select 1 as otto) as t1;
104
select friedrich from (select 1 as otto) as t1;
106
# expectation !=response
107
#!S00000 select friedrich from (select 1 as otto) as t1;
109
#select friedrich from (select 1 as otto) as t1;
111
--exec echo "error S00000; select friedrich from (select 1 as otto) as t1;" | $MYSQL_TEST 2>&1
113
# ----------------------------------------------------------------------------
114
# test cases for $mysql_errno
116
# $mysql_errno is a builtin variable of mysqltest and contains the return code
117
# of the last command sent to the server.
119
# The following test cases often initialize $mysql_errno to 1064 by
120
# a command with wrong syntax.
121
# Example: --error 1064 To prevent the abort after the error.
123
# ----------------------------------------------------------------------------
125
# ----------------------------------------------------------------------------
126
# check mysql_errno = 0 after successful statement
127
# ----------------------------------------------------------------------------
128
select otto from (select 1 as otto) as t1;
129
eval select $mysql_errno as "after_successful_stmt_errno" ;
131
#----------------------------------------------------------------------------
132
# check mysql_errno = 1064 after statement with wrong syntax
133
# ----------------------------------------------------------------------------
136
eval select $mysql_errno as "after_wrong_syntax_errno" ;
138
# ----------------------------------------------------------------------------
139
# check if let $my_var= 'abc' ; affects $mysql_errno
140
# ----------------------------------------------------------------------------
144
eval select $mysql_errno as "after_let_var_equal_value" ;
146
# ----------------------------------------------------------------------------
147
# check if set @my_var= 'abc' ; affects $mysql_errno
148
# ----------------------------------------------------------------------------
152
eval select $mysql_errno as "after_set_var_equal_value" ;
154
# ----------------------------------------------------------------------------
155
# check if the setting of --disable-warnings itself affects $mysql_errno
156
# (May be --<whatever> modifies $mysql_errno.)
157
# ----------------------------------------------------------------------------
161
eval select $mysql_errno as "after_disable_warnings_command" ;
163
# ----------------------------------------------------------------------------
164
# check if --disable-warnings + command with warning affects the errno
165
# stored within $mysql_errno
166
# (May be disabled warnings affect $mysql_errno.)
167
# ----------------------------------------------------------------------------
168
drop table if exists t1 ;
171
drop table if exists t1 ;
172
eval select $mysql_errno as "after_disable_warnings" ;
175
# ----------------------------------------------------------------------------
176
# check if masked errors affect $mysql_errno
177
# ----------------------------------------------------------------------------
182
eval select $mysql_errno as "after_minus_masked" ;
187
eval select $mysql_errno as "after_!_masked" ;
189
# ----------------------------------------------------------------------------
190
# Will manipulations of $mysql_errno be possible and visible ?
191
# ----------------------------------------------------------------------------
194
let $mysql_errno= -1;
195
eval select $mysql_errno as "after_let_errno_equal_value" ;
197
# ----------------------------------------------------------------------------
198
# How affect actions on prepared statements $mysql_errno ?
199
# ----------------------------------------------------------------------------
204
prepare stmt from "select 3 from t1" ;
205
eval select $mysql_errno as "after_failing_prepare" ;
206
create table t1 ( f1 char(10));
211
prepare stmt from "select 3 from t1" ;
212
eval select $mysql_errno as "after_successful_prepare" ;
218
eval select $mysql_errno as "after_successful_execute" ;
220
# failing execute (table has been dropped)
226
eval select $mysql_errno as "after_failing_execute" ;
228
# failing execute (unknown statement)
233
eval select $mysql_errno as "after_failing_execute" ;
235
# successful deallocate
238
deallocate prepare stmt;
239
eval select $mysql_errno as "after_successful_deallocate" ;
241
# failing deallocate ( statement handle does not exist )
245
deallocate prepare __stmt_;
246
eval select $mysql_errno as "after_failing_deallocate" ;
249
# ----------------------------------------------------------------------------
250
# test cases for "--disable_abort_on_error"
252
# "--disable_abort_on_error" switches off the abort of mysqltest
253
# after "unmasked" failing statements.
255
# The default is "--enable_abort_on_error".
258
# --error <error number> and --error <error number>
259
# in the line before the failing statement.
261
# There are some additional test cases for $mysql_errno
262
# because "--disable_abort_on_error" enables a new situation.
263
# Example: "unmasked" statement fails + analysis of $mysql_errno
264
# ----------------------------------------------------------------------------
266
# ----------------------------------------------------------------------------
267
# Switch off the abort on error and check the effect on $mysql_errno
268
# ----------------------------------------------------------------------------
271
--disable_abort_on_error
272
eval select $mysql_errno as "after_--disable_abort_on_error" ;
274
# ----------------------------------------------------------------------------
275
# "unmasked" failing statement should not cause an abort
276
# ----------------------------------------------------------------------------
279
# ----------------------------------------------------------------------------
280
# masked failing statements
281
# ----------------------------------------------------------------------------
282
# expected error = response
287
eval select $mysql_errno as "after_!errno_masked_error" ;
288
# expected error <> response
294
--exec echo "disable_abort_on_error; error 1000; select 3 from t1; error 1000; select 3 from t1;" | $MYSQL_TEST 2>&1
296
# ----------------------------------------------------------------------------
297
# Switch the abort on error on and check the effect on $mysql_errno
298
# ----------------------------------------------------------------------------
301
--enable_abort_on_error
302
eval select $mysql_errno as "after_--enable_abort_on_error" ;
304
# ----------------------------------------------------------------------------
305
# masked failing statements
306
# ----------------------------------------------------------------------------
307
# expected error = response
311
# ----------------------------------------------------------------------------
312
# check that the old default behaviour is not changed
313
# Please remove the '#' to get the abort on error
314
# ----------------------------------------------------------------------------
321
--exec echo "disable_abort_on_error; enable_abort_on_error; error 1064; select 3 from t1; select 3 from t1;" | $MYSQL_TEST 2>&1
324
# ----------------------------------------------------------------------------
326
# ----------------------------------------------------------------------------
329
# This is a ; comment
330
# This is a -- comment
331
# -- This is also a comment
332
# -- # This is also a comment
333
# -- This is also a ; comment
335
# ----------------------------------------------------------------------------
336
# Test comments with embedded command
337
# ----------------------------------------------------------------------------
343
--echo # MySQL: -- The
345
# ----------------------------------------------------------------------------
346
# Test detect end of line "junk"
347
# Most likely caused by a missing delimiter
348
# ----------------------------------------------------------------------------
350
# Too many parameters to function
352
--exec echo "sleep 5 6;" | $MYSQL_TEST 2>&1
354
# Too many parameters to function
356
--exec echo "--sleep 5 6" | $MYSQL_TEST 2>&1
360
# The comment will be "sucked into" the sleep command since
361
# delimiter is missing until after "show status"
362
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
368
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
369
remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
372
# Missing delimiter until eof
373
# The comment will be "sucked into" the sleep command since
374
# delimiter is missing
375
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
380
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
381
remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
384
# Missing delimiter until "disable_query_log"
386
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
395
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
396
remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
399
# Missing delimiter until "disable_query_log"
401
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
411
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
412
remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
415
# Missing delimiter until eof
417
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
428
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
429
remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
432
# Missing delimiter until eof
434
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
435
disconnect default # comment
442
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
444
remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
450
--exec echo "--sleep 4;" | $MYSQL_TEST 2>&1
452
--exec echo "--disable_query_log;" | $MYSQL_TEST 2>&1
455
# Allow trailing # comment
456
--sleep 1 # Wait for insert delayed to be executed.
457
--sleep 1 # Wait for insert delayed to be executed.
459
# ----------------------------------------------------------------------------
461
# ----------------------------------------------------------------------------
465
--exec echo "error;" | $MYSQL_TEST 2>&1
467
--exec echo "--error" | $MYSQL_TEST 2>&1
469
# First char must be uppercase 'S' or 'E' or [0-9]
471
--exec echo "--error s99999" | $MYSQL_TEST 2>&1
473
--exec echo "--error e99999" | $MYSQL_TEST 2>&1
475
--exec echo "--error 9eeeee" | $MYSQL_TEST 2>&1
477
--exec echo "--error 1sssss" | $MYSQL_TEST 2>&1
479
# First char 'S' but too long
481
--exec echo "--error S999999" | $MYSQL_TEST 2>&1
483
# First char 'S' but lowercase char found
485
--exec echo "--error S99a99" | $MYSQL_TEST 2>&1
487
# First char 'S' but too short
489
--exec echo "--error S9999" | $MYSQL_TEST 2>&1
491
# First char 'E' but not found in error array
493
--exec echo "--error E9999" | $MYSQL_TEST 2>&1
495
# First char [0-9] but contains chars
497
--exec echo "--error 999e9" | $MYSQL_TEST 2>&1
499
--exec echo "--error 9b" | $MYSQL_TEST 2>&1
501
# Multiple errorcodes separated by ','
503
#--error 9,ER_PARSE_ERROR
504
#--error ER_PARSE_ERROR
505
#--error 9,ER_PARSE_ERROR,9,ER_PARSE_ERROR
506
#--error 9, ER_PARSE_ERROR, 9, ER_PARSE_ERROR
507
#--error 9,S00000,9,ER_PARSE_ERROR
508
#--error 9,S00000,9,ER_PARSE_ERROR,ER_PARSE_ERROR,ER_PARSE_ERROR,9,10,11,12
510
--error 9,S00000,9,9,10,11,12
516
# Too many errorcodes specified
518
--exec echo "--error 1,2,3,4,5,6,7,8,9,10,11" | $MYSQL_TEST 2>&1
521
# ----------------------------------------------------------------------------
523
# ----------------------------------------------------------------------------
527
echo MySQL: The world''s most popular open source database;
528
echo "MySQL: The world's most popular open source database";
530
echo MySQL: The world''s
534
echo # MySQL: The world''s
538
echo - MySQL: The world''s
542
echo - MySQL: The world''s
544
-- open source database;
552
echo "MySQL: The world's most popular; open source database";
553
echo "MySQL: The world's most popular ; open source database";
554
echo "MySQL: The world's most popular ;open source database";
555
echo echo message echo message;
560
# Illegal use of echo
563
#--exec echo "echo \$;" | $MYSQL_TEST 2>&1
566
# ----------------------------------------------------------------------------
568
# ----------------------------------------------------------------------------
570
# Illegal use of exec
572
--exec echo "--exec false" | $MYSQL_TEST 2>&1
575
--exec echo "--exec " | $MYSQL_TEST 2>&1
577
# ----------------------------------------------------------------------------
579
# ----------------------------------------------------------------------------
584
let $message="MySQL";
587
let $message= MySQL: The
593
let $message= # MySQL: The
599
let $message= -- MySQL: The
602
-- open source database;
605
let $message= # MySQL: The
630
let $where=a long variable content;
636
let $where3=a long $where variable content;
639
let $where3=a long \\\$where variable content;
642
let $novar1= $novar2;
649
# ba\$cat\$cat should have been sufficient.
650
# ba\\\$cat\\\$cat -> ba\$cat\$cat -> ba$cat$cat -> banana
651
# Magnus' upcoming patch will fix the missing second interpretation.
652
let $cat=ba\\\$cat\\\$cat;
653
echo Not a banana: $cat;
656
# Test illegal uses of let
659
--exec echo "let ;" | $MYSQL_TEST 2>&1
662
--exec echo "let \$=hi;" | $MYSQL_TEST 2>&1
665
--exec echo "let \$1 hi;" | $MYSQL_TEST 2>&1
668
--exec echo "let \$m hi;" | $MYSQL_TEST 2>&1
671
--exec echo "let \$hi;" | $MYSQL_TEST 2>&1
674
--exec echo "let \$ hi;" | $MYSQL_TEST 2>&1
677
--exec echo "let =hi;" | $MYSQL_TEST 2>&1
680
--exec echo "let hi;" | $MYSQL_TEST 2>&1
682
# More advanced test for bug#17280
684
--echo # Execute: --echo # <whatever> success: \$success
685
--echo # <whatever> success: $success
686
--echo # Execute: echo # <whatever> success: \$success ;
687
echo # <whatever> success: $success ;
689
--echo # The next two variants work fine and expand the content of \$success
690
--echo # Execute: --echo \$success
692
--echo # Execute: echo \$success ;
696
# ----------------------------------------------------------------------------
697
# Test to assign let from variable
698
# let $<var_name>=$<var_name>;
699
# ----------------------------------------------------------------------------
701
--echo # Check if let \$B = \$A is an assignment per value.
703
# Basic preparations:
704
--echo let \$A = initial value of A;
705
let $A = initial value of A;
706
# --echo # Content of \$A is: $A
707
--echo let \$B = initial value of B;
708
let $B = initial value of B;
709
# --echo # Content of \$B is: $B
714
--echo # Content of \$A is: $A
716
# Changes of $B must NOT affect $A and Changes of $A must NOT affect $B !
717
--echo let \$A = changed value of A;
718
let $A = changed value of A;
719
--echo # Content of \$B is: $B
721
--echo let \$B = changed value of B;
722
let $B = changed value of B;
723
--echo # Content of \$A is: $A
725
# ----------------------------------------------------------------------------
726
# Test let from query with $variable
727
# let $<var_name>=`<query with $variable>`;
728
# ----------------------------------------------------------------------------
730
let $var1=content of variable 1;
731
let $var2= `select "$var1"`;
732
let $var3= `select concat("$var1", " ", "$var2")`;
735
if (`select length("$var3") > 0`)
737
echo length of var3 is longer than 0;
740
# ----------------------------------------------------------------------------
741
# Test to assign let from query
742
# let $<var_name>=`<query>`;
743
# ----------------------------------------------------------------------------
745
let $var1= `select "hi" as "Col", 1 as "Column1", "hi there" as Col3`;
749
let $var2= `select 2 as "Column num 2"`;
753
let $var2= `select 2 as "Column num 2"`;
756
echo var3 two columns with same name;
757
let $var3= `select 1 as "Col", 2 as "Col", 3 as "var3"`;
760
echo var4 from query that returns NULL;
761
let $var4= `select NULL`;
763
echo var5 from query that returns no row;
764
let $var5= `SHOW VARIABLES LIKE "nonexisting_variable"`;
766
echo failing query in let;
767
--write_file $MYSQLTEST_VARDIR/tmp/let.sql
768
let $var2= `failing query`;
773
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/let.sql 2>&1
775
remove_file $MYSQLTEST_VARDIR/tmp/let.sql;
778
# ----------------------------------------------------------------------------
779
# Test source command
780
# ----------------------------------------------------------------------------
782
# Test illegal uses of source
785
--exec echo "source ;" | $MYSQL_TEST 2>&1
788
--replace_result \\ /
789
# Source a nonexisting file
791
--exec echo "source non_existingFile;" | $MYSQL_TEST 2>&1
794
--exec echo "source $MYSQLTEST_VARDIR/tmp/recursive.sql;" > $MYSQLTEST_VARDIR/tmp/recursive.sql
795
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
797
--exec echo "source $MYSQLTEST_VARDIR/tmp/recursive.sql;" | $MYSQL_TEST 2>&1
798
remove_file $MYSQLTEST_VARDIR/tmp/recursive.sql;
800
# Source a file with error
801
--exec echo "garbage ;" > $MYSQLTEST_VARDIR/tmp/error.sql
802
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
804
--exec echo "source $MYSQLTEST_VARDIR/tmp/error.sql;" | $MYSQL_TEST 2>&1
806
remove_file $MYSQLTEST_VARDIR/tmp/error.sql;
808
# Test execution of source in a while loop
809
--write_file $MYSQLTEST_VARDIR/tmp/sourced.inc
810
echo here is the sourced script;
813
let $outer= 2; # Number of outer loops
816
eval SELECT '$outer = outer loop variable after while' AS "";
818
--source $MYSQLTEST_VARDIR/tmp/sourced.inc
820
eval SELECT '$outer = outer loop variable before dec' AS "";
822
eval SELECT '$outer = outer loop variable after dec' AS "";
825
let $outer= 2; # Number of outer loops
828
eval SELECT '$outer = outer loop variable after while' AS "";
830
echo here is the sourced script;
832
eval SELECT '$outer = outer loop variable before dec' AS "";
834
eval SELECT '$outer = outer loop variable after dec' AS "";
838
# Test execution of source in a while loop
839
--disable_abort_on_error
840
# Sourcing of a file within while loop, sourced file will
845
SELECT 'In loop' AS "";
846
--source $MYSQLTEST_VARDIR/tmp/sourced.inc
849
--enable_abort_on_error
852
# Test source $variable/<filename>
853
--source $MYSQLTEST_VARDIR/tmp/sourced.inc
855
--remove_file $MYSQLTEST_VARDIR/tmp/sourced.inc
857
--write_file $MYSQLTEST_VARDIR/tmp/sourced.inc
862
source $MYSQLTEST_VARDIR/tmp/$x.inc;
864
let $x= $MYSQLTEST_VARDIR;
865
source $x/tmp/sourced.inc;
867
--remove_file $MYSQLTEST_VARDIR/tmp/sourced.inc
870
# ----------------------------------------------------------------------------
872
# ----------------------------------------------------------------------------
880
--exec echo "sleep ;" | $MYSQL_TEST 2>&1
882
--exec echo "real_sleep ;" | $MYSQL_TEST 2>&1
886
--exec echo "sleep abc;" | $MYSQL_TEST 2>&1
888
--exec echo "real_sleep abc;" | $MYSQL_TEST 2>&1
890
# ----------------------------------------------------------------------------
892
# ----------------------------------------------------------------------------
907
--exec echo "inc;" | $MYSQL_TEST 2>&1
909
--exec echo "inc i;" | $MYSQL_TEST 2>&1
911
--exec echo "let \$i=100; inc \$i 1000; echo \$i;" | $MYSQL_TEST 2>&1
913
inc $i; inc $i; inc $i; --echo $i
917
# ----------------------------------------------------------------------------
919
# ----------------------------------------------------------------------------
935
--exec echo "dec;" | $MYSQL_TEST 2>&1
937
--exec echo "dec i;" | $MYSQL_TEST 2>&1
939
--exec echo "let \$i=100; dec \$i 1000; echo \$i;" | $MYSQL_TEST 2>&1
942
# ----------------------------------------------------------------------------
944
# ----------------------------------------------------------------------------
945
#system ls > /dev/null;
946
system echo "hej" > /dev/null;
947
#--system ls > /dev/null
948
--system echo "hej" > /dev/null;
951
--exec echo "system;" | $MYSQL_TEST 2>&1
953
--exec echo "system $NONEXISTSINFVAREABLI;" | $MYSQL_TEST 2>&1
955
--exec echo "system false;" | $MYSQL_TEST 2>&1
957
--disable_abort_on_error
958
system NonExistsinfComamdn 2> /dev/null;
959
--enable_abort_on_error
962
# ----------------------------------------------------------------------------
964
# ----------------------------------------------------------------------------
976
# ----------------------------------------------------------------------------
978
# ----------------------------------------------------------------------------
983
echo Counter is greater than 0, (counter=10);
987
echo Counter is not 0, (counter=10);
992
echo Counter is greater than 0, (counter=0);
996
echo Counter is not 0, (counter=0);
999
# ----------------------------------------------------------------------------
1000
# Test while, { and }
1001
# ----------------------------------------------------------------------------
1010
#let $i=1;while ($i){echo $i;dec $i;}
1015
echo Testing while with not;
1019
# Exceed max nesting level
1020
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest_while.inc
1160
--replace_result \\ / $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
1162
--exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest_while.inc;" | $MYSQL_TEST 2>&1
1163
--remove_file $MYSQLTEST_VARDIR/tmp/mysqltest_while.inc
1165
--exec echo "while \$i;" | $MYSQL_TEST 2>&1
1167
--exec echo "while (\$i;" | $MYSQL_TEST 2>&1
1169
--exec echo "let \$i=1; while (\$i) dec \$i;" | $MYSQL_TEST 2>&1
1171
--exec echo "};" | $MYSQL_TEST 2>&1
1173
--exec echo "end;" | $MYSQL_TEST 2>&1
1175
--exec echo "{;" | $MYSQL_TEST 2>&1
1177
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
1182
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
1183
remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
1185
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
1190
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
1191
remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
1193
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
1198
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1
1200
remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
1202
# ----------------------------------------------------------------------------
1203
# Test error messages returned from comments starting with a command
1204
# ----------------------------------------------------------------------------
1206
--exec echo "--if the other server is down" | $MYSQL_TEST 2>&1
1209
--exec echo "-- end when ..." | $MYSQL_TEST 2>&1
1211
# ----------------------------------------------------------------------------
1213
# ----------------------------------------------------------------------------
1214
--replace_result a b
1215
select "a" as col1, "c" as col2;
1217
--replace_result a b c d
1218
select "a" as col1, "c" as col2;
1221
--exec echo "--replace_result a" | $MYSQL_TEST 2>&1
1223
--exec echo "--replace_result a;" | $MYSQL_TEST 2>&1
1225
--exec echo "replace_result a;" | $MYSQL_TEST 2>&1
1227
--exec echo "replace_result a ;" | $MYSQL_TEST 2>&1
1228
--exec echo "replace_result a b; echo OK;" | $MYSQL_TEST 2>&1
1230
--exec echo "--replace_result a b c" | $MYSQL_TEST 2>&1
1232
--exec echo "replace_result a b c ;" | $MYSQL_TEST 2>&1
1235
--replace_column 1 b
1236
select "a" as col1, "c" as col2;
1238
--replace_column 1 b 2 d
1239
select "a" as col1, "c" as col2;
1242
--exec echo "--replace_column a" | $MYSQL_TEST 2>&1
1245
--exec echo "--replace_column 1" | $MYSQL_TEST 2>&1
1248
--exec echo "--replace_column a b" | $MYSQL_TEST 2>&1
1250
--exec echo "--replace_column a 1" | $MYSQL_TEST 2>&1
1252
--exec echo "--replace_column 1 b c " | $MYSQL_TEST 2>&1
1255
# ----------------------------------------------------------------------------
1256
# Test sync_with_master
1257
# ----------------------------------------------------------------------------
1259
--exec echo "sync_with_master 10!;" | $MYSQL_TEST 2>&1
1261
--exec echo "sync_with_master a;" | $MYSQL_TEST 2>&1
1263
# ----------------------------------------------------------------------------
1265
# ----------------------------------------------------------------------------
1268
--exec echo "connect;" | $MYSQL_TEST 2>&1
1270
--exec echo "connect ();" | $MYSQL_TEST 2>&1
1272
--exec echo "connect (con2);" | $MYSQL_TEST 2>&1
1274
--exec echo "connect (con2,);" | $MYSQL_TEST 2>&1
1276
--exec echo "connect (con2,localhost,root,,illegal_db);" | $MYSQL_TEST 2>&1
1278
--exec echo "connect (con1,localhost,root,,,illegal_port,);" | $MYSQL_TEST 2>&1
1280
--exec echo "connect (con1,localhost,root,,,,,SMTP POP);" | $MYSQL_TEST 2>&1
1282
# Repeat connect/disconnect
1283
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
1287
connect (test_con1,localhost,root,,);
1288
disconnect test_con1;
1292
--exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql; echo OK;" | $MYSQL_TEST 2>&1
1293
remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
1295
# Repeat connect/disconnect
1296
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
1300
connect (test_con1,localhost,root,,);
1301
disconnect test_con1;
1305
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
1307
--exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1
1308
remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
1310
# Select disconnected connection
1311
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
1312
connect (test_con1,localhost,root,,);
1313
disconnect test_con1;
1314
connection test_con1;
1316
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
1318
--exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1
1319
remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
1321
# Connection name already used
1322
--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql
1323
connect (test_con1,localhost,root,,);
1324
connect (test_con1,localhost,root,,);
1326
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
1328
--exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1
1330
remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql;
1332
# connect when "disable_abort_on_error" caused "connection not found"
1333
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
1334
--disable_abort_on_error
1335
connect (con1,localhost,root,,);
1339
--enable_abort_on_error
1341
# Test connect without a database
1342
connect (con2,localhost,root,,*NO-ONE*);
1343
--error ER_NO_DB_ERROR
1348
# ----------------------------------------------------------------------------
1349
# Test mysqltest arguments
1350
# ----------------------------------------------------------------------------
1352
# -x <file_name>, use the file specified after -x as the test file
1353
--exec $MYSQL_TEST < $MYSQL_TEST_DIR/include/mysqltest-x.inc
1354
--exec $MYSQL_TEST -x $MYSQL_TEST_DIR/include/mysqltest-x.inc
1355
--exec $MYSQL_TEST --test_file=$MYSQL_TEST_DIR/include/mysqltest-x.inc
1357
--replace_result \\ /
1359
--exec $MYSQL_TEST -x non_existing_file.inc 2>&1
1362
# ----------------------------------------------------------------------------
1363
# TODO Test queries, especially their errormessages... so it's easy to debug
1364
# new scripts and diagnose errors
1365
# ----------------------------------------------------------------------------
1367
# ----------------------------------------------------------------------------
1369
# ----------------------------------------------------------------------------
1383
# Bug #10251: Identifiers containing quotes not handled correctly
1385
select 1 as `a'b`, 2 as `a"b`;
1387
# Test escaping of quotes
1388
select 'aaa\\','aa''a',"aa""a";
1391
# Check of include/show_msg.inc and include/show_msg80.inc
1394
# The message contains in most cases a string with the default character set
1395
let $message= Here comes a message;
1396
--source include/show_msg.inc
1398
# The message could also contain a string with character set utf8
1399
let $message= `SELECT USER()`;
1400
--source include/show_msg.inc
1402
# The message contains more then 80 characters on multiple lines
1403
# and is kept between double quotes.
1405
"Here comes a very very long message that
1406
- is longer then 80 characters and
1407
- consists of several lines";
1408
--source include/show_msg80.inc
1410
# The message contains more then 80 characters on multiple lines
1411
# and uses the auxiliary character "." at the beginning of the message lines.
1412
let $message= . Here comes a very very long message that
1413
. - is longer then 80 characters and
1414
. - consists of several lines;
1415
--source include/show_msg80.inc
1418
# Test --enable_parsing / disable_parsing
1422
# The following will not enable query logging
1424
select "this will not be executed";
1426
select "this will be executed";
1430
# Test zero length result file. Should not pass
1432
--exec touch $MYSQLTEST_VARDIR/tmp/zero_length_file.result
1433
--exec echo "echo ok;" > $MYSQLTEST_VARDIR/tmp/query.sql
1435
--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql -R $MYSQLTEST_VARDIR/tmp/zero_length_file.result > /dev/null 2>&1
1437
remove_file $MYSQLTEST_VARDIR/tmp/zero_length_file.result;
1439
remove_file $MYSQLTEST_VARDIR/log/zero_length_file.reject;
1441
remove_file $MYSQL_TEST_DIR/r/zero_length_file.reject;
1444
# Test that a test file that does not generate any output fails.
1446
--exec echo "let \$i= 1;" > $MYSQLTEST_VARDIR/tmp/query.sql
1448
--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql 2>&1
1450
remove_file $MYSQLTEST_VARDIR/tmp/query.sql;
1453
# Test that mysqltest fails when there are no queries executed
1454
# but a result file exists
1455
# NOTE! This will never happen as long as it's not allowed to have
1456
# test files that produce no output
1457
#--exec echo "something" > $MYSQLTEST_VARDIR/tmp/result_file.result
1458
#--exec echo "let \$i= 1;" > $MYSQLTEST_VARDIR/tmp/query.sql
1460
#--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql -R $MYSQLTEST_VARDIR/tmp/result_file.result 2>&1
1463
# Bug #11731 mysqltest in multi-statement queries ignores errors in
1467
echo Failing multi statement query;
1468
# PS does not support multi statement
1469
--exec echo "--disable_ps_protocol" > $MYSQLTEST_VARDIR/tmp/bug11731.sql
1470
--exec echo "delimiter ||||;" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1471
--exec echo "create table t1 (a int primary key);" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1472
--exec echo "insert into t1 values (1);" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1473
--exec echo "select 'select-me';" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1474
--exec echo "insertz 'error query'||||" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1475
--exec echo "delimiter ;||||" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1478
--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/bug11731.sql 2>&1
1481
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
1483
--exec $MYSQL_TEST --record -x $MYSQLTEST_VARDIR/tmp/bug11731.sql -R $MYSQLTEST_VARDIR/tmp/bug11731.out 2>&1
1484
# The .out file should be non existent
1485
--exec test ! -s $MYSQLTEST_VARDIR/tmp/bug11731.out
1489
echo Multi statement using expected error;
1490
# PS does not support multi statement
1491
--exec echo "--disable_ps_protocol" > $MYSQLTEST_VARDIR/tmp/bug11731.sql
1492
--exec echo "delimiter ||||;" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1493
--exec echo "--error 1064" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1494
--exec echo "create table t1 (a int primary key);" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1495
--exec echo "insert into t1 values (1);" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1496
--exec echo "select 'select-me';" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1497
--exec echo "insertz "error query"||||" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1498
--exec echo "delimiter ;||||" >> $MYSQLTEST_VARDIR/tmp/bug11731.sql
1500
# These two should work since the error is expected
1501
--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/bug11731.sql 2>&1
1504
--exec $MYSQL_TEST --record -x $MYSQLTEST_VARDIR/tmp/bug11731.sql -R $MYSQLTEST_VARDIR/tmp/bug11731.out 2>&1
1505
# The .out file should exist
1506
--exec test -s $MYSQLTEST_VARDIR/tmp/bug11731.out
1508
remove_file $MYSQLTEST_VARDIR/tmp/bug11731.out;
1509
remove_file $MYSQLTEST_VARDIR/log/bug11731.log;
1510
remove_file $MYSQLTEST_VARDIR/tmp/bug11731.sql;
1513
# Bug#19890 mysqltest: "query" command is broken
1516
# It should be possible to use the command "query" to force mysqltest to
1517
# send the command to the server although it's a builtin mysqltest command.
1524
# Just an empty query command
1528
# test for replace_regex
1529
--replace_regex /at/b/
1530
select "at" as col1, "c" as col2;
1532
--replace_regex /at/b/i
1533
select "at" as col1, "AT" as col2, "c" as col3;
1535
--replace_regex /a/b/ /ct/d/
1536
select "a" as col1, "ct" as col2;
1538
--replace_regex /(strawberry)/raspberry and \1/ /blueberry/blackberry/ /potato/tomato/;
1539
select "strawberry","blueberry","potato";
1542
--exec echo "--replace_regex a" | $MYSQL_TEST 2>&1
1544
--exec echo "--replace_regex a;" | $MYSQL_TEST 2>&1
1546
--exec echo "replace_regex a;" | $MYSQL_TEST 2>&1
1548
--exec echo "replace_regex a ;" | $MYSQL_TEST 2>&1
1550
--exec echo "replace_regex a b; echo OK;" | $MYSQL_TEST 2>&1
1552
--exec echo "--replace_regex /a b c" | $MYSQL_TEST 2>&1
1554
--exec echo "replace_regex /a /b c ;" | $MYSQL_TEST 2>&1
1557
# replace_regex should replace substitutions from left to right in output
1559
create table t1 (a int, b int);
1560
insert into t1 values (1,3);
1561
insert into t1 values (2,4);
1562
--replace_regex /A/C/ /B/D/i /3/2/ /2/1/
1566
# ----------------------------------------------------------------------------
1567
# test for remove_file
1568
# ----------------------------------------------------------------------------
1571
--exec echo "remove_file ;" | $MYSQL_TEST 2>&1
1574
remove_file non_existing_file;
1576
# ----------------------------------------------------------------------------
1577
# test for write_file
1578
# ----------------------------------------------------------------------------
1580
--exec echo "write_file ;" | $MYSQL_TEST 2>&1
1583
--exec echo "write_file filename ;" | $MYSQL_TEST 2>&1
1585
# Comment out this test as it confuses cmd.exe with unmatched "
1587
#--exec echo "write_file filename \";" | $MYSQL_TEST 2>&1
1589
write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1590
Content for test_file1
1592
file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1593
cat_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1594
remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1596
write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp END_DELIMITER;
1597
Content for test_file1 contains EOF
1599
file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1601
# write to already exisiting file
1602
--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR
1604
--exec echo "write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;" | $MYSQL_TEST 2>&1
1606
remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1608
# ----------------------------------------------------------------------------
1609
# test for append_file
1610
# ----------------------------------------------------------------------------
1612
write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1613
Content for test_file1
1615
file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1617
append_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1620
file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1622
remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1623
append_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1624
Appended text on nonexisting file
1627
remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1629
# ----------------------------------------------------------------------------
1631
# ----------------------------------------------------------------------------
1633
--write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp
1635
for cat_file command
1638
cat_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1639
remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1642
--exec echo "cat_file non_existing_file;" | $MYSQL_TEST 2>&1
1644
# ----------------------------------------------------------------------------
1645
# test for diff_files
1646
# ----------------------------------------------------------------------------
1648
--write_file $MYSQLTEST_VARDIR/tmp/diff1.tmp
1650
for diff_file command
1654
--write_file $MYSQLTEST_VARDIR/tmp/diff2.tmp
1656
for diff_file command
1660
--write_file $MYSQLTEST_VARDIR/tmp/diff3.tmp
1662
for diff_file command
1666
--write_file $MYSQLTEST_VARDIR/tmp/diff4.tmp
1668
for diff_file command
1672
# Compare equal files
1673
--diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff2.tmp
1674
--diff_files $MYSQLTEST_VARDIR/tmp/diff2.tmp $MYSQLTEST_VARDIR/tmp/diff1.tmp
1676
# Write the below commands to a intermediary file and execute them with
1677
# mysqltest in --exec, since the output will vary depending on what "diff"
1678
# is available it is sent to /dev/null
1679
--write_file $MYSQLTEST_VARDIR/tmp/diff.test
1680
# Compare files that differ in size
1682
--diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff3.tmp
1684
--diff_files $MYSQLTEST_VARDIR/tmp/diff3.tmp $MYSQLTEST_VARDIR/tmp/diff1.tmp
1686
# Compare files that differ only in content
1688
--diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff4.tmp
1690
--diff_files $MYSQLTEST_VARDIR/tmp/diff4.tmp $MYSQLTEST_VARDIR/tmp/diff1.tmp
1693
# Execute the above diffs, and send their output to /dev/null - only
1694
# interesting to see that it returns correct error codes
1695
--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/diff.test > /dev/null 2>&1
1698
# Compare equal files, again...
1699
--diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff2.tmp
1701
--remove_file $MYSQLTEST_VARDIR/tmp/diff1.tmp
1702
--remove_file $MYSQLTEST_VARDIR/tmp/diff2.tmp
1703
--remove_file $MYSQLTEST_VARDIR/tmp/diff3.tmp
1704
--remove_file $MYSQLTEST_VARDIR/tmp/diff4.tmp
1705
--remove_file $MYSQLTEST_VARDIR/tmp/diff.test
1708
# ----------------------------------------------------------------------------
1709
# test for file_exist
1710
# ----------------------------------------------------------------------------
1712
--exec echo "file_exists ;" | $MYSQL_TEST 2>&1
1715
remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1717
file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1718
write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1719
Content for test_file1
1721
file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1722
remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1724
file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp;
1727
# ----------------------------------------------------------------------------
1728
# test for copy_file
1729
# ----------------------------------------------------------------------------
1730
--write_file $MYSQLTEST_VARDIR/tmp/file1.tmp
1734
copy_file $MYSQLTEST_VARDIR/tmp/file1.tmp $MYSQLTEST_VARDIR/tmp/file2.tmp;
1735
file_exists $MYSQLTEST_VARDIR/tmp/file2.tmp;
1736
remove_file $MYSQLTEST_VARDIR/tmp/file1.tmp;
1737
remove_file $MYSQLTEST_VARDIR/tmp/file2.tmp;
1740
--exec echo "copy_file ;" | $MYSQL_TEST 2>&1
1743
--exec echo "copy_file from_file;" | $MYSQL_TEST 2>&1
1745
# ----------------------------------------------------------------------------
1747
# ----------------------------------------------------------------------------
1748
--write_file $MYSQLTEST_VARDIR/tmp/file1.tmp
1752
chmod 0000 $MYSQLTEST_VARDIR/tmp/file1.tmp;
1753
# The below write fails, but --error is not implemented
1755
#--write_file $MYSQLTEST_VARDIR/tmp/file1.tmp
1759
chmod 0777 $MYSQLTEST_VARDIR/tmp/file1.tmp;
1760
remove_file $MYSQLTEST_VARDIR/tmp/file1.tmp;
1761
--write_file $MYSQLTEST_VARDIR/tmp/file1.tmp
1765
remove_file $MYSQLTEST_VARDIR/tmp/file1.tmp;
1768
--exec echo "chmod ;" | $MYSQL_TEST 2>&1
1771
--exec echo "chmod 0 from_file;" | $MYSQL_TEST 2>&1
1774
--exec echo "chmod 08 from_file;" | $MYSQL_TEST 2>&1
1777
--exec echo "chmod from_file;" | $MYSQL_TEST 2>&1
1780
--exec echo "chmod ABZD from_file;" | $MYSQL_TEST 2>&1
1783
--exec echo "chmod 06789 from_file;" | $MYSQL_TEST 2>&1
1786
# ----------------------------------------------------------------------------
1788
# ----------------------------------------------------------------------------
1802
--exec echo "perl TOO_LONG_DELIMITER ;" | $MYSQL_TEST 2>&1
1813
# ----------------------------------------------------------------------------
1815
# ----------------------------------------------------------------------------
1818
--exec echo "die test of die;" | $MYSQL_TEST 2>&1
1821
# ----------------------------------------------------------------------------
1823
# ----------------------------------------------------------------------------
1825
--exec echo "echo Some output; exit; echo Not this;" | $MYSQL_TEST 2>&1
1827
# ----------------------------------------------------------------------------
1828
# test for sorted_result
1829
# ----------------------------------------------------------------------------
1831
create table t1( a int, b char(255), c timestamp);
1832
insert into t1 values(1, 'Line 1', '2007-04-05'), (2, "Part 2", '2007-04-05');
1833
insert into t1 values(1, 'Line 1', '2007-04-05'), (2, "Part 3", '2007-04-05');
1837
# Should not be sorted
1856
# 1. Assignment of result set sorting
1858
SELECT 2 as "my_col"
1863
SELECT 2 as "my_col" UNION SELECT 1;
1865
SELECT 2 as "my_col"
1869
# 2. Ensure that the table header will be not sorted into the result
1875
# 3. Ensure that an empty result set does not cause problems
1876
CREATE TABLE t1( a CHAR);
1881
# 4. Ensure that NULL values within the result set do not cause problems
1882
SELECT NULL as "my_col1",2 AS "my_col2"
1886
SELECT NULL as "my_col1",2 AS "my_col2"
1890
SELECT 2 as "my_col1",NULL AS "my_col2"
1894
SELECT 2 as "my_col1",NULL AS "my_col2"
1898
# 5. "sorted_result" changes nothing when applied to a non query statement.
1902
# 6. Show that "sorted_result;" before the "SET @a = 17;" above does not affect
1903
# the now following query.
1904
SELECT 2 as "my_col"
1908
# 7. Ensure that "sorted_result" in combination with $variables works
1909
let $my_stmt=SELECT 2 as "my_col"
1915
# 8. Ensure that "sorted_result " does not change the semantics of
1916
# "--error ...." or the protocol output after such an expected failure
1919
SELECT '2' as "my_col1",2 as "my_col2"
1921
SELECT '1',1 from t2;
1923
# 9. Ensure that several result formatting options including "sorted_result"
1924
# - have all an effect
1925
# - "--sorted_result" does not need to be direct before the statement
1926
# - Row sorting is applied after modification of the column content
1928
--replace_column 1 #
1929
SELECT '1' as "my_col1",2 as "my_col2"
1933
# 10. Ensure that at least 1024 rows within a result set do not cause problems
1935
CREATE TABLE t1 (f1 INT);
1936
INSERT INTO t1 SET f1 = 1024;
1937
INSERT INTO t1 SELECT f1 - 1 FROM t1;
1938
INSERT INTO t1 SELECT f1 - 2 FROM t1;
1939
INSERT INTO t1 SELECT f1 - 4 FROM t1;
1940
INSERT INTO t1 SELECT f1 - 8 FROM t1;
1941
INSERT INTO t1 SELECT f1 - 16 FROM t1;
1942
INSERT INTO t1 SELECT f1 - 32 FROM t1;
1943
INSERT INTO t1 SELECT f1 - 64 FROM t1;
1944
INSERT INTO t1 SELECT f1 - 128 FROM t1;
1945
INSERT INTO t1 SELECT f1 - 256 FROM t1;
1946
INSERT INTO t1 SELECT f1 - 512 FROM t1;
1947
--disable_result_log
1952
# ----------------------------------------------------------------------------
1953
# Some coverage tests
1954
# ----------------------------------------------------------------------------
1957
--exec $MYSQL_TEST --help 2>&1 > /dev/null
1958
--exec $MYSQL_TEST --version 2>&1 > /dev/null
1960
--disable_abort_on_error
1962
--exec $MYSQL_TEST a b c 2>&1 > /dev/null
1963
--enable_abort_on_error
1966
# ----------------------------------------------------------------------------
1967
# test for query_get_value
1968
# ----------------------------------------------------------------------------
1971
a int, b varchar(255), c datetime
1973
SHOW COLUMNS FROM t1;
1975
#------------ Positive tests ------------
1976
# 1. constant parameters
1977
# value is simple string without spaces
1978
let $value= query_get_value(SHOW COLUMNS FROM t1, Type, 1);
1979
--echo statement=SHOW COLUMNS FROM t1 row_number=1, column_name="Type", Value=$value
1980
let $value= query_get_value("SHOW COLUMNS FROM t1", Type, 1);
1981
--echo statement="SHOW COLUMNS FROM t1" row_number=1, column_name="Type", Value=$value
1983
# 2. $variables as parameters
1985
let $my_show= SHOW COLUMNS FROM t1;
1986
let $column_name= Default;
1988
let $value= query_get_value($my_show, $column_name, $row_number);
1989
--echo statement=$my_show row_number=$row_number, column_name=$column_name, Value=$value
1991
# 3. result set of a SELECT (not recommended, because projection and
1992
# selection could be done much better by pure SELECT functionality)
1993
# value is string with space in the middle
1994
let $value= query_get_value(SELECT 'A B' AS "MyColumn", MyColumn, 1);
1995
--echo value= ->$value<-
1997
# 4. column name with space
1998
let $value= query_get_value(SELECT 1 AS "My Column", My Column, 1);
1999
--echo value= $value
2001
#------------ Negative tests ------------
2002
# 5. Incomplete statement including missing parameters
2003
# 5.1 incomplete statement
2005
--exec echo "let \$value= query_get_value(SHOW;" | $MYSQL_TEST 2>&1
2008
--exec echo "let \$value= query_get_value;" | $MYSQL_TEST 2>&1
2009
# 5.3 missing column name
2011
--exec echo "let \$value= query_get_value(SHOW COLUMNS FROM t1);" | $MYSQL_TEST 2>&1
2012
# 5.4 missing row number
2014
--exec echo "let \$value= query_get_value(SHOW COLUMNS FROM t1, Field);" | $MYSQL_TEST 2>&1
2016
# 6. Somehow "wrong" value of parameters
2018
# 6.1.1 non sense number 0
2019
let $value= initialized;
2020
let $value= query_get_value(SHOW COLUMNS FROM t1, Field, 0);
2021
--echo value= $value
2022
# 6.1.2 after the last row
2023
let $value= initialized;
2024
let $value= query_get_value(SHOW COLUMNS FROM t1, Field, 10);
2025
--echo value= $value
2026
# 6.1.3 invalid row number
2028
--exec echo "let \$value= query_get_value(SHOW COLUMNS FROM t1, Field, notnumber);" | $MYSQL_TEST 2>&1
2029
# 6.2 column name parameter, name of not existing column
2031
--exec echo "let \$value= query_get_value(SHOW COLUMNS FROM t1, column_not_exists, 1);" | $MYSQL_TEST 2>&1
2032
# 6.3. statement which never gives a result set
2034
--exec echo "let \$value= query_get_value(SET @A = 1, Field, 1);" | $MYSQL_TEST 2>&1
2035
# 6.4. statement contains a ","
2036
# Note: There is no need to improve this, because we need query_get_value
2037
# for SHOW commands only.
2039
--exec echo "let \$value= query_get_value(SELECT 1 AS "A", 1 AS "B", 1);" | $MYSQL_TEST 2>&1
2041
# 7. empty result set
2042
let $value= initialized;
2043
let $value= query_get_value(SELECT a FROM t1, a, 1);
2044
--echo value= $value
2046
# 9. failing statement
2048
--exec echo "let \$value= query_get_value(SHOW COLNS FROM t1, Field, 1);" | $MYSQL_TEST 2>&1
2050
# 10. Artificial example how to process a complete SHOW result set:
2051
let $show_statement= SHOW COLUMNS FROM t1;
2056
--echo Field Type Null Key Default Extra
2059
let $Field= query_get_value($show_statement, Field, $rowno);
2060
if (`SELECT '$Field' = 'No such row'`)
2064
if (`SELECT '$Field' <> 'No such row'`)
2066
let $Type= query_get_value($show_statement, Type, $rowno);
2067
let $Null= query_get_value($show_statement, Null, $rowno);
2068
if (`SELECT '$Null' = 'YES'`)
2072
let $Key= query_get_value($show_statement, Key, $rowno);
2073
let $Default= query_get_value($show_statement, Default, $rowno);
2074
let $Extra= query_get_value($show_statement, Extra, $rowno);
2075
--echo $Field $Type $Null ->$Key<- $Default $Extra
2080
--echo Number of columns with Default NULL: $count
2082
eval $show_statement;
2086
# ----------------------------------------------------------------------------
2087
# Test change_user command
2088
# ----------------------------------------------------------------------------
2091
--exec echo "--change_user root,,inexistent" | $MYSQL_TEST 2>&1
2094
--exec echo "--change_user inexistent,,test" | $MYSQL_TEST 2>&1
2097
--exec echo "--change_user root,inexistent,test" | $MYSQL_TEST 2>&1
2101
--change_user root,,
2102
--change_user root,,test
2104
# ----------------------------------------------------------------------------
2105
# Test mkdir and rmdir command
2106
# ----------------------------------------------------------------------------
2108
mkdir $MYSQLTEST_VARDIR/tmp/testdir;
2109
rmdir $MYSQLTEST_VARDIR/tmp/testdir;
2111
# Directory already exist
2112
mkdir $MYSQLTEST_VARDIR/tmp/testdir;
2114
mkdir $MYSQLTEST_VARDIR/tmp/testdir;
2116
# Remove dir with file inside
2117
write_file $MYSQLTEST_VARDIR/tmp/testdir/file1.txt;
2121
rmdir $MYSQLTEST_VARDIR/tmp/testdir;
2123
remove_file $MYSQLTEST_VARDIR/tmp/testdir/file1.txt;
2124
rmdir $MYSQLTEST_VARDIR/tmp/testdir;