table: remove dependency on 'LastInsertID'
This commit is contained in:
@ -82,9 +82,9 @@ func (ts *testSuite) TestT(c *C) {
|
||||
tb, err := sessionctx.GetDomain(ctx).InfoSchema().TableByName(tbIdent2.Schema, tbIdent2.Name)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(tb, NotNil)
|
||||
rid0, err := tb.AddRecord(ctx, []interface{}{1})
|
||||
rid0, err := tb.AddRecord(ctx, []interface{}{1}, 0)
|
||||
c.Assert(err, IsNil)
|
||||
rid1, err := tb.AddRecord(ctx, []interface{}{2})
|
||||
rid1, err := tb.AddRecord(ctx, []interface{}{2}, 0)
|
||||
c.Assert(err, IsNil)
|
||||
alterStmt := statement(`alter table t2 add b enum("bb") first`).(*stmts.AlterTableStmt)
|
||||
sessionctx.GetDomain(ctx).DDL().AlterTable(ctx, tbIdent2, alterStmt.Specs)
|
||||
@ -106,7 +106,7 @@ func (ts *testSuite) TestT(c *C) {
|
||||
c.Assert(cols[0], Equals, nil)
|
||||
c.Assert(cols[1], Equals, nil)
|
||||
c.Assert(cols[2], Equals, int64(2))
|
||||
rid3, err := tb.AddRecord(ctx, []interface{}{mysql.Enum{Name: "bb", Value: 1}, "c", 3})
|
||||
rid3, err := tb.AddRecord(ctx, []interface{}{mysql.Enum{Name: "bb", Value: 1}, "c", 3}, 0)
|
||||
c.Assert(err, IsNil)
|
||||
cols, err = tb.Row(ctx, rid3)
|
||||
c.Assert(err, IsNil)
|
||||
@ -118,7 +118,7 @@ func (ts *testSuite) TestT(c *C) {
|
||||
tb, err = sessionctx.GetDomain(ctx).InfoSchema().TableByName(tbIdent.Schema, tbIdent.Name)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(tb, NotNil)
|
||||
_, err = tb.AddRecord(ctx, []interface{}{1, "b", 2, 4})
|
||||
_, err = tb.AddRecord(ctx, []interface{}{1, "b", 2, 4}, 0)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
alterStmt = statement("alter table t add column aa int first").(*stmts.AlterTableStmt)
|
||||
|
||||
@ -100,7 +100,7 @@ func (p *testFromSuit) SetUpSuite(c *C) {
|
||||
|
||||
var i int64
|
||||
for i = 0; i < 10; i++ {
|
||||
p.tbl.AddRecord(p, []interface{}{i * 10, "hello"})
|
||||
p.tbl.AddRecord(p, []interface{}{i * 10, "hello"}, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -93,7 +93,7 @@ func (p *testIndexSuit) SetUpSuite(c *C) {
|
||||
p.tbl.AddIndex(idxCol)
|
||||
var i int64
|
||||
for i = 0; i < 10; i++ {
|
||||
p.tbl.AddRecord(p.ctx, []interface{}{i * 10, "hello"})
|
||||
p.tbl.AddRecord(p.ctx, []interface{}{i * 10, "hello"}, 0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -136,8 +136,7 @@ func (s *InsertValues) execSelect(t table.Table, cols []*column.Col, ctx context
|
||||
}
|
||||
|
||||
for i, r := range bufRecords {
|
||||
variable.GetSessionVars(ctx).SetLastInsertID(lastInsertIds[i])
|
||||
if _, err = t.AddRecord(ctx, r); err != nil {
|
||||
if _, err = t.AddRecord(ctx, r, int64(lastInsertIds[i])); err != nil {
|
||||
return nil, errors.Trace(err)
|
||||
}
|
||||
}
|
||||
@ -286,11 +285,10 @@ func (s *InsertIntoStmt) Exec(ctx context.Context) (_ rset.Recordset, err error)
|
||||
// `t(id int AUTO_INCREMENT, c1 int, PRIMARY KEY (id))`
|
||||
// `insert t (c1) values(1),(2),(3);`
|
||||
// Last insert id will be 1, not 3.
|
||||
variable.GetSessionVars(ctx).SetLastInsertID(lastInsertIds[i])
|
||||
if len(s.OnDuplicate) == 0 {
|
||||
txn.SetOption(kv.PresumeKeyNotExists, nil)
|
||||
}
|
||||
h, err := t.AddRecord(ctx, row)
|
||||
h, err := t.AddRecord(ctx, row, int64(lastInsertIds[i]))
|
||||
txn.DelOption(kv.PresumeKeyNotExists)
|
||||
if err == nil {
|
||||
continue
|
||||
|
||||
@ -89,7 +89,7 @@ func (s *ReplaceIntoStmt) Exec(ctx context.Context) (_ rset.Recordset, err error
|
||||
if err != nil {
|
||||
return nil, errors.Trace(err)
|
||||
}
|
||||
h, err := t.AddRecord(ctx, row)
|
||||
h, err := t.AddRecord(ctx, row, int64(variable.GetSessionVars(ctx).LastInsertID))
|
||||
if err == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ type Table interface {
|
||||
Truncate(ctx context.Context) (err error)
|
||||
|
||||
// AddRecord inserts a row into the table.
|
||||
AddRecord(ctx context.Context, r []interface{}) (recordID int64, err error)
|
||||
AddRecord(ctx context.Context, r []interface{}, h int64) (recordID int64, err error)
|
||||
|
||||
// UpdateRecord updates a row in the table.
|
||||
UpdateRecord(ctx context.Context, h int64, currData []interface{}, newData []interface{}, touched []bool) error
|
||||
|
||||
@ -324,11 +324,10 @@ func (t *Table) rebuildIndices(ctx context.Context, h int64, touched []bool, old
|
||||
}
|
||||
|
||||
// AddRecord implements table.Table AddRecord interface.
|
||||
func (t *Table) AddRecord(ctx context.Context, r []interface{}) (recordID int64, err error) {
|
||||
id := variable.GetSessionVars(ctx).LastInsertID
|
||||
// Already have auto increment ID
|
||||
if id != 0 {
|
||||
recordID = int64(id)
|
||||
func (t *Table) AddRecord(ctx context.Context, r []interface{}, h int64) (recordID int64, err error) {
|
||||
// Already have recordID
|
||||
if h != 0 {
|
||||
recordID = int64(h)
|
||||
} else {
|
||||
recordID, err = t.alloc.Alloc(t.ID)
|
||||
if err != nil {
|
||||
|
||||
@ -69,7 +69,7 @@ func (ts *testSuite) TestBasic(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(autoid, Greater, int64(0))
|
||||
|
||||
rid, err := tb.AddRecord(ctx, []interface{}{1, "abc"})
|
||||
rid, err := tb.AddRecord(ctx, []interface{}{1, "abc"}, 0)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(rid, Greater, int64(0))
|
||||
row, err := tb.Row(ctx, rid)
|
||||
@ -77,9 +77,9 @@ func (ts *testSuite) TestBasic(c *C) {
|
||||
c.Assert(len(row), Equals, 2)
|
||||
c.Assert(row[0].(int64), Equals, int64(1))
|
||||
|
||||
_, err = tb.AddRecord(ctx, []interface{}{1, "aba"})
|
||||
_, err = tb.AddRecord(ctx, []interface{}{1, "aba"}, 0)
|
||||
c.Assert(err, NotNil)
|
||||
_, err = tb.AddRecord(ctx, []interface{}{2, "abc"})
|
||||
_, err = tb.AddRecord(ctx, []interface{}{2, "abc"}, 0)
|
||||
c.Assert(err, NotNil)
|
||||
|
||||
c.Assert(tb.UpdateRecord(ctx, rid, []interface{}{1, "abc"}, []interface{}{1, "cba"}, []bool{false, true}), IsNil)
|
||||
@ -181,9 +181,9 @@ func (ts *testSuite) TestUniqueIndexMultipleNullEntries(c *C) {
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(autoid, Greater, int64(0))
|
||||
|
||||
_, err = tb.AddRecord(ctx, []interface{}{1, nil})
|
||||
_, err = tb.AddRecord(ctx, []interface{}{1, nil}, 0)
|
||||
c.Assert(err, IsNil)
|
||||
_, err = tb.AddRecord(ctx, []interface{}{2, nil})
|
||||
_, err = tb.AddRecord(ctx, []interface{}{2, nil}, 0)
|
||||
c.Assert(err, IsNil)
|
||||
_, err = ts.se.Execute("drop table test.t")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
Reference in New Issue
Block a user