summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjorn Munch <Bjorn.Munch@sun.com>2009-05-25 17:19:20 +0200
committerBjorn Munch <Bjorn.Munch@sun.com>2009-05-25 17:19:20 +0200
commitb12bb225d137d2773b05c406ac220c1dbca003ee (patch)
tree7d42d7a1730993e759511f4283655929592c7727
parent20e09b39fc769a325ff3bca882ab1444f77cf845 (diff)
downloadmariadb-git-b12bb225d137d2773b05c406ac220c1dbca003ee.tar.gz
Bug #44922 mysqltest's query_get_value function can't work with queries containing ','
check_command_args() always looks for the first , (or whatever) Extended check_command_args() to let arguments be quoted Added test in mysqltest.test
-rw-r--r--client/mysqltest.cc17
-rw-r--r--mysql-test/r/mysqltest.result1
-rw-r--r--mysql-test/t/connect.test3
-rw-r--r--mysql-test/t/mysqltest.test4
4 files changed, 22 insertions, 3 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index fdd4ff141bc..5b6d647f727 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -966,6 +966,7 @@ void check_command_args(struct st_command *command,
for (i= 0; i < num_args; i++)
{
const struct command_arg *arg= &args[i];
+ char delimiter;
switch (arg->type) {
/* A string */
@@ -974,8 +975,15 @@ void check_command_args(struct st_command *command,
while (*ptr && *ptr == ' ')
ptr++;
start= ptr;
- /* Find end of arg, terminated by "delimiter_arg" */
- while (*ptr && *ptr != delimiter_arg)
+ delimiter = delimiter_arg;
+ /* If start of arg is ' ` or " search to matching quote end instead */
+ if (*ptr && strchr ("'`\"", *ptr))
+ {
+ delimiter= *ptr;
+ start= ++ptr;
+ }
+ /* Find end of arg, terminated by "delimiter" */
+ while (*ptr && *ptr != delimiter)
ptr++;
if (ptr > start)
{
@@ -987,6 +995,11 @@ void check_command_args(struct st_command *command,
/* Empty string */
init_dynamic_string(arg->ds, "", 0, 0);
}
+ /* Find real end of arg, terminated by "delimiter_arg" */
+ /* This will do nothing if arg was not closed by quotes */
+ while (*ptr && *ptr != delimiter_arg)
+ ptr++;
+
command->last_argument= (char*)ptr;
/* Step past the delimiter */
diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result
index a9c20e34517..63941aee3ad 100644
--- a/mysql-test/r/mysqltest.result
+++ b/mysql-test/r/mysqltest.result
@@ -697,6 +697,7 @@ statement="SHOW COLUMNS FROM t1" row_number=1, column_name="Type", Value=int(11)
statement=SHOW COLUMNS FROM t1 row_number=1, column_name=Default, Value=NULL
value= ->A B<-
value= 1
+value= 2
mysqltest: At line 1: query_get_value - argument list started with '(' must be ended with ')'
mysqltest: At line 1: Missing required argument 'query' to command 'query_get_value'
mysqltest: At line 1: Missing required argument 'column name' to command 'query_get_value'
diff --git a/mysql-test/t/connect.test b/mysql-test/t/connect.test
index f609240646a..9a29e4ff861 100644
--- a/mysql-test/t/connect.test
+++ b/mysql-test/t/connect.test
@@ -55,7 +55,8 @@ disconnect con4;
connect (fail_con,localhost,test,,test2);
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
--error ER_ACCESS_DENIED_ERROR
-connect (fail_con,localhost,test,,"");
+# Need to protect "" within '' so it's interpreted literally
+connect (fail_con,localhost,test,,'""');
--replace_result $MASTER_MYSOCK MASTER_SOCKET $MASTER_MYPORT MASTER_PORT
--error ER_ACCESS_DENIED_ERROR
connect (fail_con,localhost,test,zorro,test2);
diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test
index 55cd041aaf5..0bc58d0f2f8 100644
--- a/mysql-test/t/mysqltest.test
+++ b/mysql-test/t/mysqltest.test
@@ -2037,6 +2037,10 @@ let $value= query_get_value(SELECT 'A B' AS "MyColumn", MyColumn, 1);
let $value= query_get_value(SELECT 1 AS "My Column", My Column, 1);
--echo value= $value
#
+# 4.1 Query containing , protected by quotes, quotes also on column
+let $value= query_get_value('SELECT 1 as a, 2 as b', "b", 1);
+--echo value= $value
+#
#------------ Negative tests ------------
# 5. Incomplete statement including missing parameters
# 5.1 incomplete statement