summaryrefslogtreecommitdiff
path: root/client/mysqltest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/mysqltest.cc')
-rw-r--r--client/mysqltest.cc53
1 files changed, 45 insertions, 8 deletions
diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index 91bc531b2ae..efece866ef5 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -837,6 +837,8 @@ static void handle_no_active_connection(struct st_command* command,
#define EMB_SEND_QUERY 1
#define EMB_READ_QUERY_RESULT 2
#define EMB_END_CONNECTION 3
+#define EMB_PREPARE_STMT 4
+#define EMB_EXECUTE_STMT 5
/* workaround for MySQL BUG#57491 */
#undef MY_WME
@@ -872,11 +874,19 @@ pthread_handler_t connection_thread(void *arg)
case EMB_END_CONNECTION:
goto end_thread;
case EMB_SEND_QUERY:
- cn->result= mysql_send_query(cn->mysql, cn->cur_query, cn->cur_query_len);
+ cn->result= mysql_send_query(cn->mysql,
+ cn->cur_query, cn->cur_query_len);
break;
case EMB_READ_QUERY_RESULT:
cn->result= mysql_read_query_result(cn->mysql);
break;
+ case EMB_PREPARE_STMT:
+ cn->result= mysql_stmt_prepare(cn->stmt,
+ cn->cur_query, cn->cur_query_len);
+ break;
+ case EMB_EXECUTE_STMT:
+ cn->result= mysql_stmt_execute(cn->stmt);
+ break;
default:
DBUG_ASSERT(0);
}
@@ -946,6 +956,30 @@ static int do_read_query_result(struct st_connection *cn)
}
+static int do_stmt_prepare(struct st_connection *cn, const char *q, int q_len)
+{
+ /* The cn->stmt is already set. */
+ if (!cn->has_thread)
+ return mysql_stmt_prepare(cn->stmt, q, q_len);
+ cn->cur_query= q;
+ cn->cur_query_len= q_len;
+ signal_connection_thd(cn, EMB_PREPARE_STMT);
+ wait_query_thread_done(cn);
+ return cn->result;
+}
+
+
+static int do_stmt_execute(struct st_connection *cn)
+{
+ /* The cn->stmt is already set. */
+ if (!cn->has_thread)
+ return mysql_stmt_execute(cn->stmt);
+ signal_connection_thd(cn, EMB_EXECUTE_STMT);
+ wait_query_thread_done(cn);
+ return cn->result;
+}
+
+
static void emb_close_connection(struct st_connection *cn)
{
if (!cn->has_thread)
@@ -979,6 +1013,8 @@ static void init_connection_thd(struct st_connection *cn)
#define init_connection_thd(X) do { } while(0)
#define do_send_query(cn,q,q_len) mysql_send_query(cn->mysql, q, q_len)
#define do_read_query_result(cn) mysql_read_query_result(cn->mysql)
+#define do_stmt_prepare(cn, q, q_len) mysql_stmt_prepare(cn->stmt, q, q_len)
+#define do_stmt_execute(cn) mysql_stmt_execute(cn->stmt)
#endif /*EMBEDDED_LIBRARY*/
@@ -8078,11 +8114,12 @@ void handle_no_error(struct st_command *command)
error - function will not return
*/
-void run_query_stmt(MYSQL *mysql, struct st_command *command,
+void run_query_stmt(struct st_connection *cn, struct st_command *command,
char *query, int query_len, DYNAMIC_STRING *ds,
DYNAMIC_STRING *ds_warnings)
{
MYSQL_RES *res= NULL; /* Note that here 'res' is meta data result set */
+ MYSQL *mysql= cn->mysql;
MYSQL_STMT *stmt;
DYNAMIC_STRING ds_prepare_warnings;
DYNAMIC_STRING ds_execute_warnings;
@@ -8092,11 +8129,11 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command,
/*
Init a new stmt if it's not already one created for this connection
*/
- if(!(stmt= cur_con->stmt))
+ if(!(stmt= cn->stmt))
{
if (!(stmt= mysql_stmt_init(mysql)))
die("unable to init stmt structure");
- cur_con->stmt= stmt;
+ cn->stmt= stmt;
}
/* Init dynamic strings for warnings */
@@ -8109,7 +8146,7 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command,
/*
Prepare the query
*/
- if (mysql_stmt_prepare(stmt, query, query_len))
+ if (do_stmt_prepare(cn, query, query_len))
{
handle_error(command, mysql_stmt_errno(stmt),
mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds);
@@ -8144,7 +8181,7 @@ void run_query_stmt(MYSQL *mysql, struct st_command *command,
/*
Execute the query
*/
- if (mysql_stmt_execute(stmt))
+ if (do_stmt_execute(cn))
{
handle_error(command, mysql_stmt_errno(stmt),
mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds);
@@ -8279,7 +8316,7 @@ end:
if (mysql->reconnect)
{
mysql_stmt_close(stmt);
- cur_con->stmt= NULL;
+ cn->stmt= NULL;
}
DBUG_VOID_RETURN;
@@ -8536,7 +8573,7 @@ void run_query(struct st_connection *cn, struct st_command *command, int flags)
if (ps_protocol_enabled &&
complete_query &&
match_re(&ps_re, query))
- run_query_stmt(mysql, command, query, query_len, ds, &ds_warnings);
+ run_query_stmt(cn, command, query, query_len, ds, &ds_warnings);
else
run_query_normal(cn, command, flags, query, query_len,
ds, &ds_warnings);