diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index 95671963ab3..c5afd9a4f55 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -7812,14 +7812,14 @@ void append_table_headings(DYNAMIC_STRING *ds,
   Number of warnings appended to ds
 */
 
-int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql)
+int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql, MYSQL_STMT *stmt)
 {
   uint count;
   MYSQL_RES *warn_res;
   DYNAMIC_STRING res;
   DBUG_ENTER("append_warnings");
 
-  if (!(count= mysql_warning_count(mysql)))
+  if (!(count= (stmt) ? mysql_stmt_warning_count(stmt) : mysql_warning_count(mysql)))
     DBUG_RETURN(0);
 
   /*
@@ -7827,7 +7827,10 @@ int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql)
     through PS API we should not issue SHOW WARNINGS until
     we have not read all results...
   */
-  DBUG_ASSERT(!mysql_more_results(mysql));
+  if (!stmt)
+    DBUG_ASSERT(!mysql_more_results(mysql));
+  else
+    DBUG_ASSERT(!mysql_stmt_more_results(stmt));
 
   if (mysql_real_query(mysql, "SHOW WARNINGS", 13))
     die("Error running query \"SHOW WARNINGS\": %s", mysql_error(mysql));
@@ -7975,7 +7978,7 @@ void run_query_normal(struct st_connection *cn, struct st_command *command,
       */
       if (!disable_warnings && !mysql_more_results(mysql))
       {
-	if (append_warnings(ds_warnings, mysql) || ds_warnings->length)
+	if (append_warnings(ds_warnings, mysql, NULL) || ds_warnings->length)
 	{
 	  dynstr_append_mem(ds, "Warnings:\n", 10);
 	  dynstr_append_mem(ds, ds_warnings->str, ds_warnings->length);
@@ -8276,7 +8279,7 @@ void run_query_stmt(struct st_connection *cn, struct st_command *command,
     separate string
   */
   if (!disable_warnings)
-    append_warnings(&ds_prepare_warnings, mysql);
+    append_warnings(&ds_prepare_warnings, mysql, stmt);
 
   /*
     No need to call mysql_stmt_bind_param() because we have no
@@ -8311,7 +8314,7 @@ void run_query_stmt(struct st_connection *cn, struct st_command *command,
     and keep them in a separate string for later.
   */
   if (cursor_protocol_enabled && !disable_warnings)
-    append_warnings(&ds_execute_warnings, mysql);
+    append_warnings(&ds_execute_warnings, mysql, stmt);
 
   /*
     We instruct that we want to update the "max_length" field in
@@ -8398,7 +8401,7 @@ void run_query_stmt(struct st_connection *cn, struct st_command *command,
       /* Get the warnings from execute */
 
       /* Append warnings to ds - if there are any */
-      if (append_warnings(&ds_execute_warnings, mysql) ||
+      if (append_warnings(&ds_execute_warnings, mysql, stmt) ||
           ds_execute_warnings.length ||
           ds_prepare_warnings.length ||
           ds_warnings->length)
@@ -8633,7 +8636,7 @@ void run_query(struct st_connection *cn, struct st_command *command, int flags)
         Collect warnings from create of the view that should otherwise
         have been produced when the SELECT was executed
       */
-      append_warnings(&ds_warnings, cur_con->util_mysql);
+      append_warnings(&ds_warnings, cur_con->util_mysql, NULL);
     }
 
     dynstr_free(&query_str);
