Skip to content

Commit

Permalink
Merge branch 'release-2.1' into release-2.1-pingcap#8442
Browse files Browse the repository at this point in the history
  • Loading branch information
ngaut authored Nov 28, 2018
2 parents cdc4f8d + 0137def commit 832af62
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
14 changes: 14 additions & 0 deletions executor/prepared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ func (s *testSuite) TestPrepared(c *C) {
c.Assert(err, IsNil)
c.Assert(len(fields), Equals, 0)

// issue 8074
tk.MustExec("drop table if exists prepare1;")
tk.MustExec("create table prepare1 (a decimal(1))")
tk.MustExec("insert into prepare1 values(1);")
_, err = tk.Exec("prepare stmt FROM @sql1")
c.Assert(err.Error(), Equals, "line 1 column 4 near \"\" (total length 4)")
tk.MustExec("SET @sql = 'update prepare1 set a=5 where a=?';")
_, err = tk.Exec("prepare stmt FROM @sql")
c.Assert(err, IsNil)
tk.MustExec("set @var=1;")
_, err = tk.Exec("execute stmt using @var")
c.Assert(err, IsNil)
tk.MustQuery("select a from prepare1;").Check(testkit.Rows("5"))

// Coverage.
exec := &executor.ExecuteExec{}
exec.Next(ctx, nil)
Expand Down
11 changes: 7 additions & 4 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ type planBuilder struct {
inUpdateStmt bool
// colMapper stores the column that must be pre-resolved.
colMapper map[*ast.ColumnNameExpr]int
// Collect the visit information for privilege check.
// visitInfo the visit information for privilege check.
visitInfo []visitInfo
tableHintInfo []tableHintInfo
optFlag uint64
Expand Down Expand Up @@ -248,7 +248,7 @@ func (b *planBuilder) buildSet(v *ast.SetStmt) (Plan, error) {
return p, nil
}

// Detect aggregate function or groupby clause.
// detectSelectAgg detect aggregate function or groupby clause.
func (b *planBuilder) detectSelectAgg(sel *ast.SelectStmt) bool {
if sel.GroupBy != nil {
return true
Expand Down Expand Up @@ -377,8 +377,11 @@ func (b *planBuilder) buildPrepare(x *ast.PrepareStmt) Plan {
Name: x.Name,
}
if x.SQLVar != nil {
// TODO: Prepared statement from variable expression do not work as expected.
// p.SQLText, _ = x.SQLVar.GetValue().(string)
if v, ok := b.ctx.GetSessionVars().Users[x.SQLVar.Name]; ok {
p.SQLText = v
} else {
p.SQLText = "NULL"
}
} else {
p.SQLText = x.SQLText
}
Expand Down

0 comments on commit 832af62

Please sign in to comment.