From 30209e3b11061d32a5e02d5daf9aa41ec851a03e Mon Sep 17 00:00:00 2001 From: pingcap-github-bot Date: Fri, 29 May 2020 12:13:20 +0800 Subject: [PATCH] executor: set the DDL query string instead of `execute` (#17407) (#17415) --- executor/adapter.go | 2 ++ session/session_test.go | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/executor/adapter.go b/executor/adapter.go index e05473765b524..f97e459b16c57 100644 --- a/executor/adapter.go +++ b/executor/adapter.go @@ -637,6 +637,8 @@ func (a *ExecStmt) buildExecutor() (Executor, error) { if err != nil { return nil, err } + + a.Ctx.SetValue(sessionctx.QueryString, executorExec.stmt.Text()) a.isPreparedStmt = true a.Plan = executorExec.plan if executorExec.lowerPriority { diff --git a/session/session_test.go b/session/session_test.go index c69b92d7cc996..44c73b0cb5294 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -196,6 +196,18 @@ func (s *testSessionSuite) TestQueryString(c *C) { c.Assert(err, IsNil) qs := tk.Se.Value(sessionctx.QueryString) c.Assert(qs.(string), Equals, "CREATE TABLE t2(id bigint PRIMARY KEY, age int)") + + // Test execution of DDL through the "Execute" interface. + _, err = tk.Se.Execute(context.Background(), "use test;") + c.Assert(err, IsNil) + _, err = tk.Se.Execute(context.Background(), "drop table t2") + c.Assert(err, IsNil) + _, err = tk.Se.Execute(context.Background(), "prepare stmt from 'CREATE TABLE t2(id bigint PRIMARY KEY, age int)'") + c.Assert(err, IsNil) + _, err = tk.Se.Execute(context.Background(), "execute stmt") + c.Assert(err, IsNil) + qs = tk.Se.Value(sessionctx.QueryString) + c.Assert(qs.(string), Equals, "CREATE TABLE t2(id bigint PRIMARY KEY, age int)") } func (s *testSessionSuite) TestAffectedRows(c *C) {