Skip to content

Commit

Permalink
ddl: fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala committed Oct 9, 2015
1 parent 23e465f commit cf05dfe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 9 additions & 7 deletions ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
"github.com/pingcap/tidb/util/charset"
qerror "github.com/pingcap/tidb/util/errors"
"github.com/pingcap/tidb/util/errors2"
"github.com/pingcap/tidb/util/types"
)

// Pre-defined errors
Expand Down Expand Up @@ -490,7 +489,9 @@ func (d *ddl) addColumn(ctx context.Context, schema model.CIStr, tbl table.Table
tb := tbl.(*tables.Table)
tb.Columns = newCols
// TODO: update index
updateDefaultValue(ctx, tb, col)
if err = updateDefaultValue(ctx, tb, col); err != nil {
return errors.Trace(err)
}

// update infomation schema
err = kv.RunInNewTxn(d.store, false, func(txn kv.Transaction) error {
Expand Down Expand Up @@ -522,23 +523,24 @@ func updateDefaultValue(ctx context.Context, t *tables.Table, col *column.Col) e
for it.Valid() && strings.HasPrefix(it.Key(), prefix) {
handle, err0 := util.DecodeHandleFromRowKey(it.Key())
if err0 != nil {
return errors.Trace(err)
return errors.Trace(err0)
}
k := t.RecordKey(handle, col)
colID, err0 := tables.ColumnID(k)
if err0 != nil {
return errors.Trace(err)
return errors.Trace(err0)
}
if colID != col.ID {
continue
}

types.Convert(col.DefaultValue, &col.FieldType)
t.SetColValue(txn, k, col.DefaultValue)
if err0 = t.SetColValue(txn, k, col.DefaultValue); err0 != nil {
return errors.Trace(err0)
}

rk := t.RecordKey(handle, nil)
if it, err0 = kv.NextUntil(it, util.RowKeyPrefixFilter(rk)); err0 != nil {
return errors.Trace(err)
return errors.Trace(err0)
}
}

Expand Down
1 change: 1 addition & 0 deletions ddl/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (ts *testSuite) TestT(c *C) {
c.Assert(err, IsNil)
c.Assert(tb, NotNil)
_, err = tb.AddRecord(ctx, []interface{}{1})
c.Assert(err, IsNil)
_, err = tb.AddRecord(ctx, []interface{}{2})
c.Assert(err, IsNil)
alterStmt := statement(`alter table t2 add b enum("bbb") first`).(*stmts.AlterTableStmt)
Expand Down

0 comments on commit cf05dfe

Please sign in to comment.