本文整理匯總了Golang中github.com/pingcap/tidb/table.Table.SetColValue方法的典型用法代碼示例。如果您正苦於以下問題:Golang Table.SetColValue方法的具體用法?Golang Table.SetColValue怎麽用?Golang Table.SetColValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/table.Table
的用法示例。
在下文中一共展示了Table.SetColValue方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: backfillColumnData
func (d *ddl) backfillColumnData(t table.Table, columnInfo *model.ColumnInfo, handles []int64, reorgInfo *reorgInfo) error {
for _, handle := range handles {
log.Info("[ddl] backfill column...", handle)
err := kv.RunInNewTxn(d.store, true, func(txn kv.Transaction) error {
if err := d.isReorgRunnable(txn); err != nil {
return errors.Trace(err)
}
// First check if row exists.
exist, err := checkRowExist(txn, t, handle)
if err != nil {
return errors.Trace(err)
} else if !exist {
// If row doesn't exist, skip it.
return nil
}
backfillKey := t.RecordKey(handle, &column.Col{ColumnInfo: *columnInfo})
backfillValue, err := txn.Get(backfillKey)
if err != nil && !kv.IsErrNotFound(err) {
return errors.Trace(err)
}
if backfillValue != nil {
return nil
}
value, _, err := tables.GetColDefaultValue(nil, columnInfo)
if err != nil {
return errors.Trace(err)
}
// must convert to the column field type.
v, err := types.Convert(value, &columnInfo.FieldType)
if err != nil {
return errors.Trace(err)
}
err = lockRow(txn, t, handle)
if err != nil {
return errors.Trace(err)
}
err = t.SetColValue(txn, backfillKey, v)
if err != nil {
return errors.Trace(err)
}
return errors.Trace(reorgInfo.UpdateHandle(txn, handle))
})
if err != nil {
return errors.Trace(err)
}
}
return nil
}
示例2: testIndex
func (s *testSuite) testIndex(c *C, tb table.Table, idx *column.IndexedCol) {
txn, err := s.store.Begin()
c.Assert(err, IsNil)
err = CompareIndexData(txn, tb, idx)
c.Assert(err, IsNil)
cnt, err := GetIndexRecordsCount(txn, idx.X, nil)
c.Assert(err, IsNil)
c.Assert(cnt, Equals, int64(2))
// current index data:
// index data (handle, data): (1, 10), (2, 20), (3, 30)
// index col data (handle, data): (1, 10), (2, 20), (4, 40)
err = idx.X.Create(txn, []interface{}{int64(30)}, 3)
c.Assert(err, IsNil)
col := tb.Cols()[idx.Columns[0].Offset]
key := tb.RecordKey(4, col)
err = tb.SetColValue(txn, key, int64(40))
c.Assert(err, IsNil)
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
c.Assert(err, IsNil)
err = CompareIndexData(txn, tb, idx)
c.Assert(err, NotNil)
record1 := &RecordData{Handle: int64(3), Values: []interface{}{int64(30)}}
diffMsg := newDiffRetError("index", record1, nil)
c.Assert(err.Error(), DeepEquals, diffMsg)
// current index data:
// index data (handle, data): (1, 10), (2, 20), (3, 30), (4, 40)
// index col data (handle, data): (1, 10), (2, 20), (4, 40), (3, 31)
err = idx.X.Create(txn, []interface{}{int64(40)}, 4)
c.Assert(err, IsNil)
key = tb.RecordKey(3, col)
err = tb.SetColValue(txn, key, int64(31))
c.Assert(err, IsNil)
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
c.Assert(err, IsNil)
err = CompareIndexData(txn, tb, idx)
c.Assert(err, NotNil)
record2 := &RecordData{Handle: int64(3), Values: []interface{}{int64(31)}}
diffMsg = newDiffRetError("index", record1, record2)
c.Assert(err.Error(), DeepEquals, diffMsg)
// current index data:
// index data (handle, data): (1, 10), (2, 20), (3, 30), (4, 40)
// index col data (handle, data): (1, 10), (2, 20), (4, 40), (5, 30)
key = tb.RecordKey(3, col)
txn.Delete(key)
key = tb.RecordKey(5, col)
err = tb.SetColValue(txn, key, int64(30))
c.Assert(err, IsNil)
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
c.Assert(err, IsNil)
err = checkRecordAndIndex(txn, tb, idx)
c.Assert(err, NotNil)
record2 = &RecordData{Handle: int64(5), Values: []interface{}{int64(30)}}
diffMsg = newDiffRetError("index", record1, record2)
c.Assert(err.Error(), DeepEquals, diffMsg)
// current index data:
// index data (handle, data): (1, 10), (2, 20), (3, 30), (4, 40)
// index col data (handle, data): (1, 10), (2, 20), (3, 30)
key = tb.RecordKey(4, col)
txn.Delete(key)
key = tb.RecordKey(3, col)
err = tb.SetColValue(txn, key, int64(30))
c.Assert(err, IsNil)
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
c.Assert(err, IsNil)
err = CompareIndexData(txn, tb, idx)
c.Assert(err, NotNil)
record1 = &RecordData{Handle: int64(4), Values: []interface{}{int64(40)}}
diffMsg = newDiffRetError("index", record1, nil)
c.Assert(err.Error(), DeepEquals, diffMsg)
// current index data:
// index data (handle, data): (1, 10), (2, 20), (3, 30)
// index col data (handle, data): (1, 10), (2, 20), (3, 30), (4, 40)
err = idx.X.Delete(txn, []interface{}{int64(40)}, 4)
c.Assert(err, IsNil)
key = tb.RecordKey(4, col)
err = tb.SetColValue(txn, key, int64(40))
c.Assert(err, IsNil)
err = txn.Commit()
c.Assert(err, IsNil)
txn, err = s.store.Begin()
//.........這裏部分代碼省略.........