Commit 46afb3fb authored by unknown's avatar unknown
Browse files

Merge rkalimullin@bk-internal.mysql.com:/home/bk/mysql-4.1

into gw.mysql.r18.ru:/usr/home/ram/work/4.1

parents 00d9273a 3606df23
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -1514,6 +1514,27 @@ static bool init_param_array(Prepared_statement *stmt)
}


/* Init statement before execution */

static void cleanup_stmt_for_execute(Prepared_statement *stmt)
{
  THD *thd= stmt->thd;
  LEX *lex= stmt->lex;
  SELECT_LEX *sl= lex->all_selects_list;

  for (; sl; sl= sl->next_select_in_list())
  {
    for (TABLE_LIST *tables= (TABLE_LIST*) sl->table_list.first;
	 tables;
	 tables= tables->next)
    {
      if (tables->table)
        tables->table->insert_values= 0;
    }
  }
}


/*
  Given a query string with parameter markers, create a Prepared Statement
  from it and send PS info back to the client.
@@ -1614,6 +1635,7 @@ int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length,

  if (!error)
    error= send_prepare_results(stmt, test(name));
  cleanup_stmt_for_execute(stmt);

  /* restore to WAIT_PRIOR: QUERY_PRIOR is set inside alloc_query */
  if (!(specialflag & SPECIAL_NO_PRIOR))
@@ -1904,6 +1926,7 @@ static void execute_stmt(THD *thd, Prepared_statement *stmt,
  reset_stmt_params(stmt);
  close_thread_tables(thd);                    // to close derived tables
  thd->set_statement(&thd->stmt_backup);
  cleanup_stmt_for_execute(stmt);
  DBUG_VOID_RETURN;
}

+51 −0
Original line number Diff line number Diff line
@@ -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