Commit 09eee68d authored by unknown's avatar unknown

Add new parameter to do_eval so that only unescaped variables in input string...

Add new parameter to do_eval so that only unescaped variables in input string is expanded and rest of string is left untouched.


client/mysqltest.c:
  Add new parameter to 'do_eval' that will add any escape chars found in the input string to the output string. 
  This is used in 'do_system' and in 'do_exec' where only unescaped variables
  will be expanded, rest of the string will be left untouched.
mysql-test/r/mysqltest.result:
  Update test result
mysql-test/t/mysqldump.test:
  Revert previous patch that added extra \\ in "exec" command
mysql-test/t/mysqltest.test:
  Revert previous patch that added extra \\ in exec command
parent 24d77e97
......@@ -457,7 +457,8 @@ static int insert_pointer_name(reg1 POINTER_ARRAY *pa,my_string name);
static void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds,
const char *from, int len);
void free_pointer_array(POINTER_ARRAY *pa);
static void do_eval(DYNAMIC_STRING *query_eval, const char *query);
static void do_eval(DYNAMIC_STRING *query_eval, const char *query,
my_bool pass_through_escape_chars);
static void str_to_file(const char *fname, char *str, int size);
#ifdef __WIN__
......@@ -489,7 +490,8 @@ static void handle_error(const char *query, struct st_query *q,
const char *err_sqlstate, DYNAMIC_STRING *ds);
static void handle_no_error(struct st_query *q);
static void do_eval(DYNAMIC_STRING* query_eval, const char *query)
static void do_eval(DYNAMIC_STRING* query_eval, const char *query,
my_bool pass_through_escape_chars)
{
const char *p;
register char c, next_c;
......@@ -524,6 +526,12 @@ static void do_eval(DYNAMIC_STRING* query_eval, const char *query)
{
/* Set escaped only if next char is \ or $ */
escaped = 1;
if (pass_through_escape_chars)
{
/* The escape char should be added to the output string. */
dynstr_append_mem(query_eval, p, 1);
}
}
else
dynstr_append_mem(query_eval, p, 1);
......@@ -713,7 +721,7 @@ static int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname)
init_dynamic_string(&res_ds, "", 0, 65536);
if (eval_result)
{
do_eval(&res_ds, tmp);
do_eval(&res_ds, tmp, FALSE);
res_ptr = res_ds.str;
if ((res_len = res_ds.length) != ds->length)
{
......@@ -1085,7 +1093,7 @@ static void do_exec(struct st_query *query)
init_dynamic_string(&ds_cmd, 0, strlen(cmd)+256, 256);
/* Eval the command, thus replacing all environment variables */
do_eval(&ds_cmd, cmd);
do_eval(&ds_cmd, cmd, TRUE);
cmd= ds_cmd.str;
DBUG_PRINT("info", ("Executing '%s' as '%s'",
......@@ -1379,7 +1387,7 @@ int do_system(struct st_query *command)
init_dynamic_string(&ds_cmd, 0, strlen(command->first_argument) + 64, 256);
/* Eval the system command, thus replacing all environment variables */
do_eval(&ds_cmd, command->first_argument);
do_eval(&ds_cmd, command->first_argument, TRUE);
DBUG_PRINT("info", ("running system command '%s' as '%s'",
command->first_argument, ds_cmd.str));
......@@ -3984,7 +3992,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags)
if (command->type == Q_EVAL)
{
init_dynamic_string(&eval_query, "", 16384, 65536);
do_eval(&eval_query, command->query);
do_eval(&eval_query, command->query, FALSE);
query = eval_query.str;
query_len = eval_query.length;
}
......
......@@ -218,7 +218,7 @@ mysqltest: At line 1: Missing variable name in let
mysqltest: At line 1: Variable name in hi=hi does not start with '$'
mysqltest: At line 1: Missing assignment operator in let
mysqltest: At line 1: Missing assignment operator in let
mysqltest: At line 1: Missing arguments to let
mysqltest: At line 1: Missing assignment operator in let
mysqltest: At line 1: Missing variable name in let
mysqltest: At line 1: Variable name in =hi does not start with '$'
mysqltest: At line 1: Missing assignment operator in let
......
......@@ -647,7 +647,7 @@ select '------ Testing with illegal table names ------' as test_sequence ;
--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "\\t1" 2>&1
--error 6
--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "\\\\\\t1" 2>&1
--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "\\\\t1" 2>&1
--error 6
--exec $MYSQL_DUMP --compact --skip-comments mysqldump_test_db "t\1" 2>&1
......
......@@ -678,7 +678,7 @@ echo $i;
--error 1
--exec echo "inc i;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "let \\\$i=100; inc \\\$i 1000; echo \\\$i;" | $MYSQL_TEST 2>&1
--exec echo "let \$i=100; inc \$i 1000; echo \$i;" | $MYSQL_TEST 2>&1
inc $i; inc $i; inc $i; --echo $i
echo $i;
......@@ -706,7 +706,7 @@ echo $d;
--error 1
--exec echo "dec i;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "let \\\$i=100; dec \\\$i 1000; echo \\\$i;" | $MYSQL_TEST 2>&1
--exec echo "let \$i=100; dec \$i 1000; echo \$i;" | $MYSQL_TEST 2>&1
# ----------------------------------------------------------------------------
......@@ -761,11 +761,11 @@ while ($i)
--error 1
--exec echo "source include/mysqltest_while.inc;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "while \\\$i;" | $MYSQL_TEST 2>&1
--exec echo "while \$i;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "while (\\\$i;" | $MYSQL_TEST 2>&1
--exec echo "while (\$i;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "let \\\$i=1; while (\\\$i) dec \\\$i;" | $MYSQL_TEST 2>&1
--exec echo "let \$i=1; while (\$i) dec \$i;" | $MYSQL_TEST 2>&1
--error 1
--exec echo "};" | $MYSQL_TEST 2>&1
--error 1
......@@ -877,22 +877,22 @@ select "a" as col1, "c" as col2;
--exec echo "connect (con1,localhost,root,,,,,SMTP POP);" | $MYSQL_TEST 2>&1
# Repeat connect/disconnect
--exec echo "let \\\$i=100;" > var/tmp/con.sql
--exec echo "while (\\\$i)" >> var/tmp/con.sql
--exec echo "let \$i=100;" > var/tmp/con.sql
--exec echo "while (\$i)" >> var/tmp/con.sql
--exec echo "{" >> var/tmp/con.sql
--exec echo " connect (test_con1,localhost,root,,); " >> var/tmp/con.sql
--exec echo " connect (test_con1,localhost,root,,); " >> var/tmp/con.sql
--exec echo " disconnect test_con1; " >> var/tmp/con.sql
--exec echo " dec \\\$i; " >> var/tmp/con.sql
--exec echo " dec \$i; " >> var/tmp/con.sql
--exec echo "}" >> var/tmp/con.sql
--exec echo "source var/tmp/con.sql; echo OK;" | $MYSQL_TEST 2>&1
# Repeat connect/disconnect, exceed max number of connections
--exec echo "let \\\$i=200;" > var/tmp/con.sql
--exec echo "while (\\\$i)" >> var/tmp/con.sql
--exec echo "let \$i=200;" > var/tmp/con.sql
--exec echo "while (\$i)" >> var/tmp/con.sql
--exec echo "{" >> var/tmp/con.sql
--exec echo " connect (test_con1,localhost,root,,); " >> var/tmp/con.sql
--exec echo " disconnect test_con1; " >> var/tmp/con.sql
--exec echo " dec \\\$i; " >> var/tmp/con.sql
--exec echo " dec \$i; " >> var/tmp/con.sql
--exec echo "}" >> var/tmp/con.sql
--error 1
--exec echo "source var/tmp/con.sql;" | $MYSQL_TEST 2>&1
......@@ -1001,7 +1001,7 @@ select "this will be executed";
#
# Test that a test file that does not generate any output fails.
#
--exec echo "let \\\$i= 1;" > $MYSQL_TEST_DIR/var/tmp/query.sql
--exec echo "let \$i= 1;" > $MYSQL_TEST_DIR/var/tmp/query.sql
--error 1
--exec $MYSQL_TEST -x var/tmp/query.sql 2>&1
......
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