diff --git a/client/mysqltest.cc b/client/mysqltest.cc
index c1c2a2b1112..01c69bd7893 100644
--- a/client/mysqltest.cc
+++ b/client/mysqltest.cc
@@ -70,6 +70,199 @@ static my_bool non_blocking_api_enabled= 0;
 #if !defined(EMBEDDED_LIBRARY)
 #define WRAP_NONBLOCK_ENABLED non_blocking_api_enabled
 #include "../tests/nonblock-wrappers.h"
+
+#if 0
+
+#undef mysql_real_query
+#undef mysql_store_result
+#undef mysql_send_query
+#undef mysql_read_query_result
+
+// now we use wrap_mysql_real_query() in OUR new wrapper
+
+uint max_exec_time_us;
+bool wrapping;
+const char *wrapped_query;
+unsigned long wrapped_query_length;
+#define MAX_STATEMENT_TIME     100000000
+#define MYSQL_ERRNO_TIMEOUT  1969
+#define MYSQL_ERRNO_INTERUPTED  1317
+#define STATEMENT_TIME_INCREMENT 10
+
+#define BAND4  10000000
+#define BAND3  1000000
+#define BAND2  10000
+
+void
+increment_exec_time( uint *v )
+{
+  if (*v < BAND2)
+    *v += STATEMENT_TIME_INCREMENT;
+  else
+    if (*v >= BAND2 && *v < BAND3)
+      *v += STATEMENT_TIME_INCREMENT*10;
+    else
+      if (*v >= BAND3 && *v < BAND4)
+        *v += STATEMENT_TIME_INCREMENT*100;
+      else
+        if (*v >= BAND4)
+          *v += STATEMENT_TIME_INCREMENT*1000;
+}
+
+int STDCALL
+mysql_real_query_timed(MYSQL *mysql, const char *query, unsigned long length)
+{
+  int result= 0, set_result= 0;
+  char qry_set[256];
+  max_exec_time_us= STATEMENT_TIME_INCREMENT;
+  wrapping= TRUE;
+
+  wrapped_query= query;
+  wrapped_query_length= length;
+
+  while (max_exec_time_us < MAX_STATEMENT_TIME)     // this needs to be a much smarter search than this
+  {
+    increment_exec_time( &max_exec_time_us );
+    sprintf( qry_set, "set max_statement_time=%f",
+                                            (float)max_exec_time_us/1000000);
+    if ((set_result= wrap_mysql_real_query(mysql, qry_set, strlen(qry_set))))
+      return set_result;
+
+    result= wrap_mysql_real_query(mysql, query, length);
+
+    if (mysql_errno(mysql) == MYSQL_ERRNO_TIMEOUT)
+      continue;
+    else
+      break;
+  }
+  return result;
+}
+
+MYSQL_RES * STDCALL
+mysql_store_result_timed(MYSQL *mysql)
+{
+  MYSQL_RES *result= wrap_mysql_store_result(mysql);
+  char qry_set[256];
+  int set_result;
+
+  if (wrapping)
+  {
+    while (mysql_errno(mysql) == MYSQL_ERRNO_TIMEOUT)
+    {
+      // reexecute wrapped_query and try again
+      while (max_exec_time_us < MAX_STATEMENT_TIME)
+      {
+        increment_exec_time( &max_exec_time_us );
+        sprintf( qry_set, "set max_statement_time=%f",
+                                               (float)max_exec_time_us/1000000);
+        if ((set_result= wrap_mysql_real_query(mysql, qry_set, strlen(qry_set))))
+          return result;
+
+        set_result= wrap_mysql_real_query(mysql,
+                                          wrapped_query,
+                                          wrapped_query_length);
+
+        if (mysql_errno(mysql) == MYSQL_ERRNO_TIMEOUT)
+          continue;
+        else
+          break;
+      }
+      result= wrap_mysql_store_result(mysql);
+      if (max_exec_time_us >= MAX_STATEMENT_TIME)
+        break;
+    }
+  }
+  wrapping= FALSE;
+  sprintf( qry_set, "set max_statement_time=999" );
+  max_exec_time_us= 0;
+  set_result= wrap_mysql_real_query(mysql, qry_set, strlen(qry_set));
+
+  return result;
+}
+
+int STDCALL
+mysql_send_query_timed(MYSQL* mysql, const char* query, unsigned long length)
+{
+  char qry_set[256];
+  int set_result, result;
+  wrapping= TRUE;
+  wrapped_query= query;
+  wrapped_query_length= length;
+
+  while (max_exec_time_us < MAX_STATEMENT_TIME)     // this needs to be a much smarter search than this
+  {
+    increment_exec_time( &max_exec_time_us );
+    sprintf( qry_set, "set max_statement_time=%f",
+                                            (float)max_exec_time_us/1000000);
+    if ((set_result= wrap_mysql_real_query(mysql, qry_set, strlen(qry_set))))
+      return set_result;
+
+    result= wrap_mysql_send_query(mysql, query, length);
+
+    if (mysql_errno(mysql) == MYSQL_ERRNO_TIMEOUT)
+      continue;
+    else
+      break;
+  }
+
+  return result;
+}
+
+my_bool STDCALL
+mysql_read_query_result_timed(MYSQL *mysql)
+{
+  my_bool result= wrap_mysql_read_query_result(mysql);
+  char qry_set[256];
+  int set_result;
+
+  if (wrapping)
+  {
+    while (mysql_errno(mysql) == MYSQL_ERRNO_TIMEOUT ||
+           mysql_errno(mysql) == MYSQL_ERRNO_INTERUPTED)
+    {
+
+      // reexecute wrapped_query and try again
+      while (max_exec_time_us < MAX_STATEMENT_TIME)
+      {
+        increment_exec_time( &max_exec_time_us );
+        sprintf( qry_set, "set max_statement_time=%f",
+                                               (float)max_exec_time_us/1000000);
+        if ((set_result= wrap_mysql_real_query(mysql, qry_set, strlen(qry_set))))
+          return result;
+
+        set_result= wrap_mysql_send_query(mysql,
+                                          wrapped_query,
+                                          wrapped_query_length);
+
+        if (mysql_errno(mysql) == MYSQL_ERRNO_TIMEOUT)
+          continue;
+        else
+          break;
+      }
+      result= wrap_mysql_read_query_result(mysql);
+      if (max_exec_time_us >= MAX_STATEMENT_TIME)
+        break;
+    }
+  }
+  /*
+  // breaks statements that change state
+  wrapping= FALSE;
+  sprintf( qry_set, "set max_statement_time=999" );
+  max_exec_time_us= 0;
+  set_result= wrap_mysql_real_query(mysql, qry_set, strlen(qry_set));
+  set_result= wrap_mysql_send_query(mysql, wrapped_query, wrapped_query_length);
+  result= wrap_mysql_read_query_result(mysql);
+  */
+  return result;
+}
+
+#define mysql_real_query mysql_real_query_timed
+#define mysql_store_result mysql_store_result_timed
+#define mysql_send_query mysql_send_query_timed
+#define mysql_read_query_result mysql_read_query_result_timed
+
+#endif
+
 #endif
 
 
