summaryrefslogtreecommitdiff
path: root/client/mysqltest.cc
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@montyprogram.com>2012-05-08 00:26:41 +0200
committerVladislav Vaintroub <wlad@montyprogram.com>2012-05-08 00:26:41 +0200
commit597e98bc8355e838ad258abdf79e4a41609b6694 (patch)
tree06ea600dd44c791fc2fb43b654595fc916578515 /client/mysqltest.cc
parent8065143637dd622b094e548ae373a28bbe78e028 (diff)
downloadmariadb-git-597e98bc8355e838ad258abdf79e4a41609b6694.tar.gz
MDEV-261 : mysqtest crashes when assigning variable to result of select , like
let x = `SELECT <something>` The fix is to detect the condition "no active connection", to report error and die. Note, that the check for no active connection was already in place for ordinary commands, and was missing only for assign-variable command.
Diffstat (limited to 'client/mysqltest.cc')
-rw-r--r--client/mysqltest.cc45
1 files changed, 40 insertions, 5 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index 45de35ab84b..7d23bc75af7 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -739,6 +739,9 @@ void handle_error(struct st_command*,
const char *err_sqlstate, DYNAMIC_STRING *ds);
void handle_no_error(struct st_command*);
+static void handle_no_active_connection(struct st_command* command,
+ struct st_connection *cn, DYNAMIC_STRING *ds);
+
#ifdef EMBEDDED_LIBRARY
/* workaround for MySQL BUG#57491 */
@@ -2287,6 +2290,19 @@ void var_query_set(VAR *var, const char *query, const char** query_end)
DBUG_ENTER("var_query_set");
LINT_INIT(res);
+ if (!mysql)
+ {
+ struct st_command command;
+ memset(&command, 0, sizeof(command));
+ command.query= (char*)query;
+ command.first_word_len= (*query_end - query);
+ command.first_argument= command.query + command.first_word_len;
+ command.end= (char*)*query;
+ command.abort_on_error= 1; /* avoid uninitialized variables */
+ handle_no_active_connection(&command, cur_con, &ds_res);
+ DBUG_VOID_RETURN;
+ }
+
/* Only white space or ) allowed past ending ` */
while (end > query && *end != '`')
{
@@ -2392,6 +2408,12 @@ void var_set_query_get_value(struct st_command *command, VAR *var)
DBUG_ENTER("var_set_query_get_value");
LINT_INIT(res);
+ if (!mysql)
+ {
+ handle_no_active_connection(command, cur_con, &ds_res);
+ DBUG_VOID_RETURN;
+ }
+
strip_parentheses(command);
DBUG_PRINT("info", ("query: %s", command->query));
check_command_args(command, command->first_argument, query_get_value_args,
@@ -2550,6 +2572,7 @@ void eval_expr(VAR *v, const char *p, const char **p_end, bool do_eval)
command.first_word_len= len;
command.first_argument= command.query + len;
command.end= (char*)*p_end;
+ command.abort_on_error= 1; /* avoid uninitialized variables */
var_set_query_get_value(&command, v);
DBUG_VOID_RETURN;
}
@@ -6925,6 +6948,22 @@ int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql)
/*
+ Handle situation where query is sent but there is no active connection
+ (e.g directly after disconnect).
+
+ We emulate MySQL-compatible behaviour of sending something on a closed
+ connection.
+*/
+static void handle_no_active_connection(struct st_command *command,
+ struct st_connection *cn, DYNAMIC_STRING *ds)
+{
+ handle_error(command, 2006, "MySQL server has gone away", "000000", ds);
+ cn->pending= FALSE;
+ var_set_errno(2006);
+}
+
+
+/*
Run query using MySQL C API
SYNOPSIS
@@ -6950,11 +6989,7 @@ void run_query_normal(struct st_connection *cn, struct st_command *command,
if (!mysql)
{
- /* Emulate old behaviour of sending something on a closed connection */
- handle_error(command, 2006, "MySQL server has gone away",
- "000000", ds);
- cn->pending= FALSE;
- var_set_errno(2006);
+ handle_no_active_connection(command, cn, ds);
DBUG_VOID_RETURN;
}