Skip to content

Commit

Permalink
stmts: Address comments and modify a unit test case
Browse files Browse the repository at this point in the history
  • Loading branch information
shenli committed Sep 16, 2015
1 parent 70cfab1 commit 6ec054f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion rset/rsets/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (r *JoinRset) Plan(ctx context.Context) (plan.Plan, error) {
return p, nil
}

// MultipleTable checks if the JoinRset contains multiple tables
// MultipleTable checks if the JoinRset contains multiple tables.
func (r *JoinRset) MultipleTable() bool {
if _, ok := r.Left.(*TableSource); ok {
if r.Right == nil {
Expand Down
10 changes: 5 additions & 5 deletions stmt/stmts/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ func (s *UpdateStmt) SetText(text string) {
s.Text = text
}

func getUpdateColumns(t table.Table, assignList []expressions.Assignment, multipleTable bool) ([]*column.Col, error) {
func getUpdateColumns(t table.Table, assignList []expressions.Assignment, isMultipleTable bool) ([]*column.Col, error) {
// TODO: We should check the validate if assignList in somewhere else. Maybe in building plan.
tcols := make([]*column.Col, 0, len(assignList))
tname := t.TableName()
for _, asgn := range assignList {
if multipleTable {
if isMultipleTable {
if !strings.EqualFold(tname.O, asgn.TableName) {
continue
}
}
col := column.FindCol(t.Cols(), asgn.ColName)
if col == nil {
if multipleTable {
if isMultipleTable {
continue
}
return nil, errors.Errorf("UPDATE: unknown column %s", asgn.ColName)
Expand Down Expand Up @@ -242,7 +242,7 @@ func (s *UpdateStmt) Exec(ctx context.Context) (_ rset.Recordset, err error) {
defer p.Close()
updatedRowKeys := make(map[string]bool)
// For single-table syntax, TableRef may contain multiple tables
multipleTables := s.MultipleTable || s.TableRefs.MultipleTable()
isMultipleTable := s.MultipleTable || s.TableRefs.MultipleTable()
for {
row, err1 := p.Next(ctx)
if err1 != nil {
Expand Down Expand Up @@ -279,7 +279,7 @@ func (s *UpdateStmt) Exec(ctx context.Context) (_ rset.Recordset, err error) {
end := start + len(tbl.Cols())
data := rowData[start:end]
start = end
tcols, err2 := getUpdateColumns(tbl, s.List, multipleTables)
tcols, err2 := getUpdateColumns(tbl, s.List, isMultipleTable)
if err2 != nil {
return nil, errors.Trace(err2)
}
Expand Down
6 changes: 3 additions & 3 deletions stmt/stmts/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s *testStmtSuite) fillMultiTableForUpdate(currDB *sql.DB, c *C) {
r := mustExec(c, currDB, `insert into items values (11, "items_price_11"), (12, "items_price_12"), (13, "items_price_13");`)
checkResult(c, r, 3, 0)
// Create and fill table month
mustExec(c, currDB, "CREATE TABLE month (id int, price TEXT);")
mustExec(c, currDB, "CREATE TABLE month (mid int, mprice TEXT);")
r = mustExec(c, currDB, `insert into month values (11, "month_price_11"), (22, "month_price_22"), (13, "month_price_13");`)
checkResult(c, r, 3, 0)
}
Expand All @@ -107,7 +107,7 @@ func (s *testStmtSuite) TestMultipleTableUpdate(c *C) {
c.Assert(err, IsNil)
s.fillMultiTableForUpdate(testDB, c)

r := mustExec(c, testDB, `UPDATE items, month SET items.price=month.price WHERE items.id=month.id;`)
r := mustExec(c, testDB, `UPDATE items, month SET items.price=month.mprice WHERE items.id=month.mid;`)
c.Assert(r, NotNil)

tx := mustBegin(c, testDB)
Expand All @@ -131,7 +131,7 @@ func (s *testStmtSuite) TestMultipleTableUpdate(c *C) {
mustCommit(c, tx)

// Single-table syntax but with multiple tables
r = mustExec(c, testDB, `UPDATE items join month on items.id=month.id SET items.price=month.id;`)
r = mustExec(c, testDB, `UPDATE items join month on items.id=month.mid SET items.price=month.mid;`)
c.Assert(r, NotNil)
tx = mustBegin(c, testDB)
rows, err = tx.Query("SELECT * FROM items")
Expand Down

0 comments on commit 6ec054f

Please sign in to comment.