本文整理匯總了Golang中github.com/pingcap/tidb/table.Table.WritableCols方法的典型用法代碼示例。如果您正苦於以下問題:Golang Table.WritableCols方法的具體用法?Golang Table.WritableCols怎麽用?Golang Table.WritableCols使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/table.Table
的用法示例。
在下文中一共展示了Table.WritableCols方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: checkAddPublic
func (s *testColumnChangeSuite) checkAddPublic(d *ddl, ctx context.Context, writeOnlyTable, publicTable table.Table) error {
// publicTable Insert t values (4, 4, 4)
h, err := publicTable.AddRecord(ctx, types.MakeDatums(4, 4, 4))
if err != nil {
return errors.Trace(err)
}
err = ctx.CommitTxn()
if err != nil {
return errors.Trace(err)
}
// writeOnlyTable update t set c1 = 3 where c1 = 4
oldRow, err := writeOnlyTable.RowWithCols(ctx, h, writeOnlyTable.WritableCols())
if err != nil {
return errors.Trace(err)
}
if len(oldRow) != 3 {
return errors.Errorf("%v", oldRow)
}
newRow := types.MakeDatums(3, 4, oldRow[2].GetValue())
err = writeOnlyTable.UpdateRecord(ctx, h, oldRow, newRow, touchedMap(writeOnlyTable))
if err != nil {
return errors.Trace(err)
}
err = ctx.CommitTxn()
if err != nil {
return errors.Trace(err)
}
// publicTable select * from t, make sure the new c3 value 4 is not overwritten to default value 3.
err = checkResult(ctx, publicTable, testutil.RowsWithSep(" ", "2 3 3", "3 4 4"))
if err != nil {
return errors.Trace(err)
}
return nil
}
示例2: checkResult
func checkResult(ctx context.Context, t table.Table, rows [][]interface{}) error {
var gotRows [][]interface{}
t.IterRecords(ctx, t.FirstKey(), t.WritableCols(), func(h int64, data []types.Datum, cols []*table.Column) (bool, error) {
gotRows = append(gotRows, datumsToInterfaces(data))
return true, nil
})
got := fmt.Sprintf("%v", gotRows)
expect := fmt.Sprintf("%v", rows)
if got != expect {
return errors.Errorf("expect %v, got %v", expect, got)
}
return nil
}