Skip to content

Commit

Permalink
executor: fix issue959 and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala committed Mar 10, 2016
1 parent cd0a3db commit ce531c7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
34 changes: 33 additions & 1 deletion executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,45 @@ func (s *testSuite) TestInsertAutoInc(c *C) {

insertSQL := `insert into insert_autoinc_test(c1) values (1), (2)`
tk.MustExec(insertSQL)

tk.MustExec("begin")
r := tk.MustQuery("select * from insert_autoinc_test;")
rowStr1 := fmt.Sprintf("%v %v", "1", "1")
rowStr2 := fmt.Sprintf("%v %v", "2", "2")
r.Check(testkit.Rows(rowStr1, rowStr2))
tk.MustExec("commit")

tk.MustExec("begin")
insertSQL = `insert into insert_autoinc_test(id, c1) values (5,5)`
tk.MustExec(insertSQL)
insertSQL = `insert into insert_autoinc_test(c1) values (6)`
tk.MustExec(insertSQL)
tk.MustExec("commit")
tk.MustExec("begin")
r = tk.MustQuery("select * from insert_autoinc_test;")
rowStr3 := fmt.Sprintf("%v %v", "5", "5")
rowStr4 := fmt.Sprintf("%v %v", "6", "6")
r.Check(testkit.Rows(rowStr1, rowStr2, rowStr3, rowStr4))
tk.MustExec("commit")

tk.MustExec("begin")
insertSQL = `insert into insert_autoinc_test(id, c1) values (3,3)`
tk.MustExec(insertSQL)
tk.MustExec("commit")
tk.MustExec("begin")
r = tk.MustQuery("select * from insert_autoinc_test;")
rowStr5 := fmt.Sprintf("%v %v", "3", "3")
r.Check(testkit.Rows(rowStr1, rowStr2, rowStr5, rowStr3, rowStr4))
tk.MustExec("commit")

tk.MustExec("begin")
insertSQL = `insert into insert_autoinc_test(c1) values (7)`
tk.MustExec(insertSQL)
tk.MustExec("commit")
tk.MustExec("begin")
r = tk.MustQuery("select * from insert_autoinc_test;")
rowStr6 := fmt.Sprintf("%v %v", "7", "7")
r.Check(testkit.Rows(rowStr1, rowStr2, rowStr5, rowStr3, rowStr4, rowStr6))
tk.MustExec("commit")
}

func (s *testSuite) TestReplace(c *C) {
Expand Down
3 changes: 3 additions & 0 deletions executor/executor_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,9 @@ func (e *InsertValues) initDefaultValues(row []types.Datum, marked map[int]struc
var defaultValueCols []*column.Col
for i, c := range e.Table.Cols() {
if row[i].Kind() != types.KindNull {
if mysql.HasAutoIncrementFlag(c.Flag) {
e.Table.RebaseAutoID(row[i].GetValue().(int64))
}
// Column value is not nil, continue.
continue
}
Expand Down
4 changes: 2 additions & 2 deletions meta/autoid/autoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type allocator struct {
dbID int64
}

// Rebase rebase the autoID base for table with tableID and the new base value.
// Rebase rebases the autoID base for table with tableID and the new base value.
func (alloc *allocator) Rebase(tableID, newBase int64) error {
if tableID == 0 {
return errors.New("Invalid tableID")
Expand Down Expand Up @@ -119,7 +119,7 @@ type memoryAllocator struct {
dbID int64
}

// Rebase rebase the autoID base for table with tableID and the new base value.
// Rebase rebases the autoID base for table with tableID and the new base value.
func (alloc *memoryAllocator) Rebase(tableID, newBase int64) error {
// TODO: implement it.
return nil
Expand Down

0 comments on commit ce531c7

Please sign in to comment.