diff options
Diffstat (limited to 'mysql-test/t/mysqltest.test')
-rw-r--r-- | mysql-test/t/mysqltest.test | 397 |
1 files changed, 354 insertions, 43 deletions
diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 328206626df..8a38972c00f 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -1,3 +1,5 @@ +-- source include/have_log_bin.inc + # This test should work in embedded server after mysqltest is fixed -- source include/not_embedded.inc @@ -46,11 +48,6 @@ select otto from (select 1 as otto) as t1; --error 0 select otto from (select 1 as otto) as t1; -# expectation <> response --- // --error 1054 --- // select otto from (select 1 as otto) as t1; - - # ---------------------------------------------------------------------------- # Negative case(statement): # The derived table t1 does not contain a column named 'friedrich' . @@ -331,9 +328,9 @@ select 3 from t1 ; # This is a comment # This is a ; comment # This is a -- comment --- This is also a comment --- # This is also a comment --- This is also a ; comment +# -- This is also a comment +# -- # This is also a comment +# -- This is also a ; comment # ---------------------------------------------------------------------------- # Test comments with embedded command @@ -369,6 +366,7 @@ show status; EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # # Missing delimiter until eof @@ -380,6 +378,7 @@ sleep 7 EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # # Missing delimiter until "disable_query_log" @@ -394,6 +393,7 @@ disable_query_log; EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # # Missing delimiter until "disable_query_log" @@ -409,6 +409,7 @@ disable_query_log; EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # # Missing delimiter until eof @@ -425,6 +426,7 @@ disconnect default EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # # Missing delimiter until eof @@ -439,6 +441,8 @@ EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; + # # Extra delimiter # @@ -737,38 +741,40 @@ if (`select length("$var3") > 0`) # Test to assign let from query # let $<var_name>=`<query>`; # ---------------------------------------------------------------------------- ---disable_parsing echo var1; let $var1= `select "hi" as "Col", 1 as "Column1", "hi there" as Col3`; echo $var1; -echo $var1_Col; -echo $var1_Column1; -echo $var1_Col3; echo var2; let $var2= `select 2 as "Column num 2"`; echo $var2; -echo $var2_Column num 2; -echo $var2_Column; echo var2 again; let $var2= `select 2 as "Column num 2"`; echo $var2; -echo $var2_Column num 2; -echo $var2_Column_num_2; -echo $var2_Column; echo var3 two columns with same name; let $var3= `select 1 as "Col", 2 as "Col", 3 as "var3"`; echo $var3; -echo $var3_Col; -echo $var3_Col; -echo $var3_var3; -#echo failing query in let; -#--error 1 -#--exec echo "let $var2= `failing query;`" | $MYSQL_TEST 2>&1 ---enable_parsing +echo var4 from query that returns NULL; +let $var4= `select NULL`; + +echo var5 from query that returns no row; +let $var5= `SHOW VARIABLES LIKE "nonexisting_variable"`; + +echo failing query in let; +--write_file $MYSQLTEST_VARDIR/tmp/let.sql +let $var2= `failing query`; +echo $var2; +EOF + +--error 1 +--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/let.sql 2>&1 + +remove_file $MYSQLTEST_VARDIR/tmp/let.sql; + + # ---------------------------------------------------------------------------- # Test source command # ---------------------------------------------------------------------------- @@ -789,6 +795,7 @@ echo $var3_var3; --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --error 1 --exec echo "source $MYSQLTEST_VARDIR/tmp/recursive.sql;" | $MYSQL_TEST 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/recursive.sql; # Source a file with error --exec echo "garbage ;" > $MYSQLTEST_VARDIR/tmp/error.sql @@ -796,6 +803,7 @@ echo $var3_var3; --error 1 --exec echo "source $MYSQLTEST_VARDIR/tmp/error.sql;" | $MYSQL_TEST 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/error.sql; # Test execution of source in a while loop --write_file $MYSQLTEST_VARDIR/tmp/sourced.inc @@ -840,8 +848,25 @@ while ($num) } --enable_abort_on_error --enable_query_log + +# Test source $variable/<filename> +--source $MYSQLTEST_VARDIR/tmp/sourced.inc + +--remove_file $MYSQLTEST_VARDIR/tmp/sourced.inc + +--write_file $MYSQLTEST_VARDIR/tmp/sourced.inc +echo "hello"; +EOF + +let $x= sourced; +source $MYSQLTEST_VARDIR/tmp/$x.inc; + +let $x= $MYSQLTEST_VARDIR; +source $x/tmp/sourced.inc; + --remove_file $MYSQLTEST_VARDIR/tmp/sourced.inc + # ---------------------------------------------------------------------------- # Test sleep command # ---------------------------------------------------------------------------- @@ -962,7 +987,7 @@ if (!$counter) echo Counter is not 0, (counter=10); } let $counter=0; -if ($counter) +if($counter) { echo Counter is greater than 0, (counter=0); } @@ -1155,6 +1180,7 @@ echo hej; EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql while (0) @@ -1162,6 +1188,7 @@ while (0) EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql while (0){ @@ -1170,6 +1197,8 @@ EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; + # ---------------------------------------------------------------------------- # Test error messages returned from comments starting with a command # ---------------------------------------------------------------------------- @@ -1227,11 +1256,9 @@ select "a" as col1, "c" as col2; # Test sync_with_master # ---------------------------------------------------------------------------- --error 1 ---exec echo "save_master_pos; sync_with_master 10!;" | $MYSQL_TEST 2>&1 +--exec echo "sync_with_master 10!;" | $MYSQL_TEST 2>&1 --error 1 ---exec echo "save_master_pos; sync_with_master 10 !;" | $MYSQL_TEST 2>&1 ---error 1 ---exec echo "save_master_pos; sync_with_master a;" | $MYSQL_TEST 2>&1 +--exec echo "sync_with_master a;" | $MYSQL_TEST 2>&1 # ---------------------------------------------------------------------------- # Test connect @@ -1263,8 +1290,9 @@ while ($i) } EOF --exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql; echo OK;" | $MYSQL_TEST 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; -# Repeat connect/disconnect, exceed max number of connections +# Repeat connect/disconnect --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql let $i=200; while ($i) @@ -1277,6 +1305,7 @@ EOF --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --error 1 --exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # Select disconnected connection --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql @@ -1287,6 +1316,7 @@ EOF --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --error 1 --exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; # Connection name already used --write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql @@ -1297,6 +1327,8 @@ EOF --error 1 --exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql;" | $MYSQL_TEST 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql; + # connect when "disable_abort_on_error" caused "connection not found" --replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT --disable_abort_on_error @@ -1400,7 +1432,11 @@ select "this will be executed"; --exec touch $MYSQLTEST_VARDIR/tmp/zero_length_file.result --exec echo "echo ok;" > $MYSQLTEST_VARDIR/tmp/query.sql --error 1 ---exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql -R $MYSQLTEST_VARDIR/tmp/zero_length_file.result 2>&1 +--exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql -R $MYSQLTEST_VARDIR/tmp/zero_length_file.result > /dev/null 2>&1 + +remove_file $MYSQLTEST_VARDIR/tmp/zero_length_file.result; +remove_file $MYSQLTEST_VARDIR/log/zero_length_file.reject; + # # Test that a test file that does not generate any output fails. # @@ -1408,6 +1444,8 @@ select "this will be executed"; --error 1 --exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/query.sql 2>&1 +remove_file $MYSQLTEST_VARDIR/tmp/query.sql; + # # Test that mysqltest fails when there are no queries executed # but a result file exists @@ -1437,6 +1475,7 @@ echo Failing multi statement query; --exec $MYSQL_TEST -x $MYSQLTEST_VARDIR/tmp/bug11731.sql 2>&1 drop table t1; +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --error 1 --exec $MYSQL_TEST --record -x $MYSQLTEST_VARDIR/tmp/bug11731.sql -R $MYSQLTEST_VARDIR/tmp/bug11731.out 2>&1 # The .out file should be non existent @@ -1463,6 +1502,9 @@ drop table t1; # The .out file should exist --exec test -s $MYSQLTEST_VARDIR/tmp/bug11731.out drop table t1; +remove_file $MYSQLTEST_VARDIR/tmp/bug11731.out; +remove_file $MYSQLTEST_VARDIR/log/bug11731.log; +remove_file $MYSQLTEST_VARDIR/tmp/bug11731.sql; # # Bug#19890 mysqltest: "query" command is broken @@ -1545,12 +1587,19 @@ write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; Content for test_file1 EOF file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp; +cat_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp END_DELIMITER; Content for test_file1 contains EOF END_DELIMITER file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp; + +# write to already exisiting file +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR +--error 1 +--exec echo "write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp;" | $MYSQL_TEST 2>&1 + remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; # ---------------------------------------------------------------------------- @@ -1572,6 +1621,8 @@ append_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; Appended text on nonexisting file EOF +remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; + # ---------------------------------------------------------------------------- # test for cat_file # ---------------------------------------------------------------------------- @@ -1582,6 +1633,7 @@ for cat_file command of mysqltest EOF cat_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; +remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; --error 1 --exec echo "cat_file non_existing_file;" | $MYSQL_TEST 2>&1 @@ -1608,19 +1660,48 @@ for diff_file command of mysqltest EOF +--write_file $MYSQLTEST_VARDIR/tmp/diff4.tmp +Some data +for diff_file command +of musqltest +EOF + # Compare equal files --diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff2.tmp --diff_files $MYSQLTEST_VARDIR/tmp/diff2.tmp $MYSQLTEST_VARDIR/tmp/diff1.tmp -# Compare files that differ +# Write the below commands to a intermediary file and execute them with +# mysqltest in --exec, since the output will vary depending on what "diff" +# is available it is sent to /dev/null +--write_file $MYSQLTEST_VARDIR/tmp/diff.test +# Compare files that differ in size +--error 2 +--diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff3.tmp +--error 2 +--diff_files $MYSQLTEST_VARDIR/tmp/diff3.tmp $MYSQLTEST_VARDIR/tmp/diff1.tmp + +# Compare files that differ only in content --error 1 ---diff_files $MYSQLTEST_VARDIR/tmp/diff3.tmp $MYSQLTEST_VARDIR/tmp/diff2.tmp +--diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff4.tmp --error 1 ---diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff3.tmp +--diff_files $MYSQLTEST_VARDIR/tmp/diff4.tmp $MYSQLTEST_VARDIR/tmp/diff1.tmp +EOF + +# Execute the above diffs, and send their output to /dev/null - only +# interesting to see that it returns correct error codes +--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/diff.test > /dev/null 2>&1 + # Compare equal files, again... --diff_files $MYSQLTEST_VARDIR/tmp/diff1.tmp $MYSQLTEST_VARDIR/tmp/diff2.tmp +--remove_file $MYSQLTEST_VARDIR/tmp/diff1.tmp +--remove_file $MYSQLTEST_VARDIR/tmp/diff2.tmp +--remove_file $MYSQLTEST_VARDIR/tmp/diff3.tmp +--remove_file $MYSQLTEST_VARDIR/tmp/diff4.tmp +--remove_file $MYSQLTEST_VARDIR/tmp/diff.test + + # ---------------------------------------------------------------------------- # test for file_exist # ---------------------------------------------------------------------------- @@ -1673,6 +1754,7 @@ chmod 0000 $MYSQLTEST_VARDIR/tmp/file1.tmp; #EOF chmod 0777 $MYSQLTEST_VARDIR/tmp/file1.tmp; +remove_file $MYSQLTEST_VARDIR/tmp/file1.tmp; --write_file $MYSQLTEST_VARDIR/tmp/file1.tmp test2 EOF @@ -1740,23 +1822,130 @@ EOF --exec echo "echo Some output; exit; echo Not this;" | $MYSQL_TEST 2>&1 # ---------------------------------------------------------------------------- -# test for query_sorted +# test for sorted_result # ---------------------------------------------------------------------------- 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 3", '2007-04-05'); select * from t1; -query_sorted select * from t1; +--sorted_result +select * from t1; +# Should not be sorted +select * from t1; disable_result_log; -query_sorted select * from t1; +sorted_result; +select * from t1; enable_result_log; -query_sorted select ''; -query_sorted select "h"; -query_sorted select "he"; -query_sorted select "hep"; -query_sorted select "hepp"; +--sorted_result +select ''; +sorted_result; +select "h"; +--sorted_result +select "he"; +--sorted_result +select "hep"; +--sorted_result +select "hepp"; + +drop table t1; +# 1. Assignment of result set sorting +sorted_result; + SELECT 2 as "my_col" +UNION +SELECT 1; +# +--sorted_result +SELECT 2 as "my_col" UNION SELECT 1; +--sorted_result +SELECT 2 as "my_col" +UNION +SELECT 1; + +# 2. Ensure that the table header will be not sorted into the result +--sorted_result +SELECT '2' as "3" +UNION +SELECT '1'; + +# 3. Ensure that an empty result set does not cause problems +CREATE TABLE t1( a CHAR); +--sorted_result +SELECT * FROM t1; +DROP TABLE t1; + +# 4. Ensure that NULL values within the result set do not cause problems +SELECT NULL as "my_col1",2 AS "my_col2" +UNION +SELECT NULL,1; +--sorted_result +SELECT NULL as "my_col1",2 AS "my_col2" +UNION +SELECT NULL,1; +# +SELECT 2 as "my_col1",NULL AS "my_col2" +UNION +SELECT 1,NULL; +--sorted_result +SELECT 2 as "my_col1",NULL AS "my_col2" +UNION +SELECT 1,NULL; + +# 5. "sorted_result" changes nothing when applied to a non query statement. +sorted_result; + SET @a = 17; +# +# 6. Show that "sorted_result;" before the "SET @a = 17;" above does not affect +# the now following query. +SELECT 2 as "my_col" +UNION +SELECT 1; + +# 7. Ensure that "sorted_result" in combination with $variables works +let $my_stmt=SELECT 2 as "my_col" +UNION +SELECT 1; +--sorted_result +eval $my_stmt; + +# 8. Ensure that "sorted_result " does not change the semantics of +# "--error ...." or the protocol output after such an expected failure +--sorted_result +--error 1146 +SELECT '2' as "my_col1",2 as "my_col2" +UNION +SELECT '1',1 from t2; + +# 9. Ensure that several result formatting options including "sorted_result" +# - have all an effect +# - "--sorted_result" does not need to be direct before the statement +# - Row sorting is applied after modification of the column content +--sorted_result +--replace_column 1 # +SELECT '1' as "my_col1",2 as "my_col2" +UNION +SELECT '2',1; + +# 10. Ensure that at least 1024 rows within a result set do not cause problems +# +CREATE TABLE t1 (f1 INT); +INSERT INTO t1 SET f1 = 1024; +INSERT INTO t1 SELECT f1 - 1 FROM t1; +INSERT INTO t1 SELECT f1 - 2 FROM t1; +INSERT INTO t1 SELECT f1 - 4 FROM t1; +INSERT INTO t1 SELECT f1 - 8 FROM t1; +INSERT INTO t1 SELECT f1 - 16 FROM t1; +INSERT INTO t1 SELECT f1 - 32 FROM t1; +INSERT INTO t1 SELECT f1 - 64 FROM t1; +INSERT INTO t1 SELECT f1 - 128 FROM t1; +INSERT INTO t1 SELECT f1 - 256 FROM t1; +INSERT INTO t1 SELECT f1 - 512 FROM t1; +--disable_result_log +--sorted_result +SELECT * FROM t1; +--enable_result_log +DROP TABLE t1; # ---------------------------------------------------------------------------- # Some coverage tests # ---------------------------------------------------------------------------- @@ -1764,10 +1953,132 @@ query_sorted select "hepp"; --disable_query_log --exec $MYSQL_TEST --help 2>&1 > /dev/null --exec $MYSQL_TEST --version 2>&1 > /dev/null ---enable_quary_log +--enable_query_log --disable_abort_on_error --error 1 --exec $MYSQL_TEST a b c 2>&1 > /dev/null --enable_abort_on_error +--enable_query_log + +# ---------------------------------------------------------------------------- +# test for query_get_value +# ---------------------------------------------------------------------------- + +CREATE TABLE t1( + a int, b varchar(255), c datetime +); +SHOW COLUMNS FROM t1; + +#------------ Positive tests ------------ +# 1. constant parameters +# value is simple string without spaces +let $value= query_get_value(SHOW COLUMNS FROM t1, Type, 1); +--echo statement=SHOW COLUMNS FROM t1 row_number=1, column_name="Type", Value=$value +let $value= query_get_value("SHOW COLUMNS FROM t1", Type, 1); +--echo statement="SHOW COLUMNS FROM t1" row_number=1, column_name="Type", Value=$value +# +# 2. $variables as parameters +# value IS NULL +let $my_show= SHOW COLUMNS FROM t1; +let $column_name= Default; +let $row_number= 1; +let $value= query_get_value($my_show, $column_name, $row_number); +--echo statement=$my_show row_number=$row_number, column_name=$column_name, Value=$value +# +# 3. result set of a SELECT (not recommended, because projection and +# selection could be done much better by pure SELECT functionality) +# value is string with space in the middle +let $value= query_get_value(SELECT 'A B' AS "MyColumn", MyColumn, 1); +--echo value= ->$value<- +# +# 4. column name with space +let $value= query_get_value(SELECT 1 AS "My Column", My Column, 1); +--echo value= $value +# +#------------ Negative tests ------------ +# 5. Incomplete statement including missing parameters +# 5.1 incomplete statement +--error 1 +--exec echo "let \$value= query_get_value(SHOW;" | $MYSQL_TEST 2>&1 +# 5.2 missing query +--error 1 +--exec echo "let \$value= query_get_value;" | $MYSQL_TEST 2>&1 +# 5.3 missing column name +--error 1 +--exec echo "let \$value= query_get_value(SHOW COLUMNS FROM t1);" | $MYSQL_TEST 2>&1 +# 5.4 missing row number +--error 1 +--exec echo "let \$value= query_get_value(SHOW COLUMNS FROM t1, Field);" | $MYSQL_TEST 2>&1 +# +# 6. Somehow "wrong" value of parameters +# 6.1 row parameter +# 6.1.1 non sense number 0 +let $value= initialized; +let $value= query_get_value(SHOW COLUMNS FROM t1, Field, 0); +--echo value= $value +# 6.1.2 after the last row +let $value= initialized; +let $value= query_get_value(SHOW COLUMNS FROM t1, Field, 10); +--echo value= $value +# 6.1.3 invalid row number +--error 1 +--exec echo "let \$value= query_get_value(SHOW COLUMNS FROM t1, Field, notnumber);" | $MYSQL_TEST 2>&1 +# 6.2 column name parameter, name of not existing column +--error 1 +--exec echo "let \$value= query_get_value(SHOW COLUMNS FROM t1, column_not_exists, 1);" | $MYSQL_TEST 2>&1 +# 6.3. statement which never gives a result set +--error 1 +--exec echo "let \$value= query_get_value(SET @A = 1, Field, 1);" | $MYSQL_TEST 2>&1 +# 6.4. statement contains a "," +# Note: There is no need to improve this, because we need query_get_value +# for SHOW commands only. +--error 1 +--exec echo "let \$value= query_get_value(SELECT 1 AS "A", 1 AS "B", 1);" | $MYSQL_TEST 2>&1 +# +# 7. empty result set +let $value= initialized; +let $value= query_get_value(SELECT a FROM t1, a, 1); +--echo value= $value +# +# 9. failing statement +--error 1 +--exec echo "let \$value= query_get_value(SHOW COLNS FROM t1, Field, 1);" | $MYSQL_TEST 2>&1 +# +# 10. Artificial example how to process a complete SHOW result set: +let $show_statement= SHOW COLUMNS FROM t1; +let $rowno= 1; +let $run=1; +let $count= 0; +--echo +--echo Field Type Null Key Default Extra +while ($run) +{ + let $Field= query_get_value($show_statement, Field, $rowno); + if (`SELECT '$Field' = 'No such row'`) + { + let $run= 0; + } + if (`SELECT '$Field' <> 'No such row'`) + { + let $Type= query_get_value($show_statement, Type, $rowno); + let $Null= query_get_value($show_statement, Null, $rowno); + if (`SELECT '$Null' = 'YES'`) + { + inc $count; + } + let $Key= query_get_value($show_statement, Key, $rowno); + let $Default= query_get_value($show_statement, Default, $rowno); + let $Extra= query_get_value($show_statement, Extra, $rowno); + --echo $Field $Type $Null ->$Key<- $Default $Extra + inc $rowno; + } +} +--echo +--echo Number of columns with Default NULL: $count +--echo +eval $show_statement; + +drop table t1; --echo End of tests + |