From 06fc7b5cff7a55cfa5cfa793dd0fe2ca2c86456a Mon Sep 17 00:00:00 2001
From: unknown <sergefp@mysql.com>
Date: Tue, 14 Dec 2004 10:57:30 +0300
Subject: [PATCH] Test for BUG#7242: Testing prepare + several times execute
 (here in client_test.c because we need to check if several PS execution works
 and the bug shows up with binary protocol only )

tests/client_test.c:
  Test for BUG#7242: Testing prepare + several times execute
---
 tests/client_test.c | 51 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/tests/client_test.c b/tests/client_test.c
index 75ce242900a..b0bf40799da 100644
--- a/tests/client_test.c
+++ b/tests/client_test.c
@@ -1026,6 +1026,56 @@ static void test_tran_innodb()
 }
 
 
+/* Test for BUG#7242 */
+
+static void test_prepare_insert_update()
+{
+  MYSQL_STMT *stmt;
+  int        rc;
+  int        i;
+  const char *testcase[]= {
+    "CREATE TABLE t1 (a INT, b INT, c INT, UNIQUE (A), UNIQUE(B))",
+    "INSERT t1 VALUES (1,2,10), (3,4,20)",
+    "INSERT t1 VALUES (5,6,30), (7,4,40), (8,9,60) ON DUPLICATE KEY UPDATE c=c+100",
+    "SELECT * FROM t1",
+    "INSERT t1 SET a=5 ON DUPLICATE KEY UPDATE b=0",
+    "SELECT * FROM t1",
+    "INSERT t1 VALUES (2,1,11), (7,4,40) ON DUPLICATE KEY UPDATE c=c+VALUES(a)",
+    NULL};
+  const char **cur_query;
+
+  myheader("test_prepare_insert_update");
+  
+  for (cur_query= testcase; *cur_query; cur_query++)
+  {
+    printf("\nRunning query: %s", *cur_query);
+    strmov(query, *cur_query);
+    stmt= mysql_simple_prepare(mysql, query);
+    check_stmt(stmt);
+
+    verify_param_count(stmt, 0);
+    rc= mysql_stmt_execute(stmt);
+
+    check_execute(stmt, rc);
+    /* try the last query several times */
+    if (!cur_query[1])
+    {
+      for (i=0; i < 3;i++)
+      {
+        printf("\nExecuting last statement again");
+        rc= mysql_stmt_execute(stmt);
+        check_execute(stmt, rc);
+        rc= mysql_stmt_execute(stmt);
+        check_execute(stmt, rc);
+      }
+    }
+    mysql_stmt_close(stmt);
+  }
+
+  rc= mysql_commit(mysql);
+  myquery(rc);
+}
+
 /* Test simple prepares of all DML statements */
 
 static void test_prepare_simple()
@@ -11513,6 +11563,7 @@ and you are welcome to modify and redistribute it under the GPL license\n");
 
 static struct my_tests_st my_tests[]= {
   { "client_query", client_query },
+  { "test_prepare_insert_update", test_prepare_insert_update},
 #if NOT_YET_WORKING
   { "test_drop_temp", test_drop_temp },
 #endif
-- 
2.30.9