From 9ed35f83fa66a15dd87834e67d32fa2150efaf7a Mon Sep 17 00:00:00 2001 From: "msvensson@neptunus.(none)" <> Date: Tue, 16 Aug 2005 17:10:52 +0200 Subject: [PATCH] BUG#10267 mysqltest, wrong number of loops when a script is sourced within a loop --- client/mysqltest.c | 8 ++++- mysql-test/r/mysqltest.result | 55 +++++++++++++++++++++++++++++++++++ mysql-test/t/mysqltest.test | 43 +++++++++++++++++++++++++++ 3 files changed, 105 insertions(+), 1 deletion(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 2455c4adfd3..dff91560b81 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -962,7 +962,13 @@ int do_source(struct st_query* q) *p++= 0; check_eol_junk(p); } + /* If this file has already been sourced, dont source it again. + It's already available in the q_lines cache */ + if (parser.current_line < (parser.read_lines - 1)) + return 0; return open_file(name); + + } @@ -2378,7 +2384,7 @@ int read_query(struct st_query** q_ptr) DBUG_PRINT("warning",("too long query")); DBUG_RETURN(1); } - DBUG_PRINT("info", ("query: %s", read_query_buf)); + DBUG_PRINT("info", ("query: %s", read_query_buf)); if (*p == '#') { q->type = Q_COMMENT; diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index 3b2828c3c6c..21c73f2c7bf 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -224,6 +224,61 @@ mysqltest: At line 1: Missing file name in source mysqltest: At line 1: Could not open file ./non_existingFile mysqltest: In included file "./var/tmp/recursive.sql": At line 1: Source directives are nesting too deep mysqltest: In included file "./var/tmp/error.sql": At line 1: query 'garbage ' failed: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'garbage' at line 1 + +2 = outer loop variable after while +here is the sourced script + +2 = outer loop variable before dec + +1 = outer loop variable after dec + +1 = outer loop variable after while +here is the sourced script + +1 = outer loop variable before dec + +0 = outer loop variable after dec + +2 = outer loop variable after while +here is the sourced script + +2 = outer loop variable before dec + +1 = outer loop variable after dec + +1 = outer loop variable after while +here is the sourced script + +1 = outer loop variable before dec + +0 = outer loop variable after dec + +In loop +here is the sourced script + +In loop +here is the sourced script + +In loop +here is the sourced script + +In loop +here is the sourced script + +In loop +here is the sourced script + +In loop +here is the sourced script + +In loop +here is the sourced script + +In loop +here is the sourced script + +In loop +here is the sourced script mysqltest: At line 1: Missing argument to sleep mysqltest: At line 1: Invalid argument to sleep "abc" 1 diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 6e1b24e1232..8099510ecd1 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -524,6 +524,49 @@ echo $1; --exec echo "source var/tmp/error.sql;" | $MYSQL_TEST 2>&1 +# Test execution of source in a while loop +--exec echo "echo here is the sourced script;" > var/tmp/sourced.sql +--disable_query_log +let $outer= 2; # Number of outer loops +while ($outer) +{ + eval SELECT '$outer = outer loop variable after while' AS ""; + + --source var/tmp/sourced.sql + + eval SELECT '$outer = outer loop variable before dec' AS ""; + dec $outer; + eval SELECT '$outer = outer loop variable after dec' AS ""; +} + +let $outer= 2; # Number of outer loops +while ($outer) +{ + eval SELECT '$outer = outer loop variable after while' AS ""; + + echo here is the sourced script; + + eval SELECT '$outer = outer loop variable before dec' AS ""; + dec $outer; + eval SELECT '$outer = outer loop variable after dec' AS ""; +} + + +# Test execution of source in a while loop +--exec echo "--source var/tmp/sourced.sql" > var/tmp/sourced1.sql +--disable_abort_on_error +# Sourcing of a file within while loop, sourced file will +# source other file +let $num= 9; +while ($num) +{ + SELECT 'In loop' AS ""; + --source var/tmp/sourced1.sql + dec $num; +} +--enable_abort_on_error; +--enable_query_log + # ---------------------------------------------------------------------------- # Test sleep command # ----------------------------------------------------------------------------