本文整理匯總了Golang中github.com/pingcap/tidb/table.Table.Row方法的典型用法代碼示例。如果您正苦於以下問題:Golang Table.Row方法的具體用法?Golang Table.Row怎麽用?Golang Table.Row使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/table.Table
的用法示例。
在下文中一共展示了Table.Row方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: replaceRow
func replaceRow(ctx context.Context, t table.Table, handle int64, replaceRow []interface{}) error {
row, err := t.Row(ctx, handle)
if err != nil {
return errors.Trace(err)
}
result := 0
isReplace := false
touched := make(map[int]bool, len(row))
for i, val := range row {
result, err = types.Compare(val, replaceRow[i])
if err != nil {
return errors.Trace(err)
}
if result != 0 {
touched[i] = true
isReplace = true
}
}
if isReplace {
variable.GetSessionVars(ctx).AddAffectedRows(1)
if err = t.UpdateRecord(ctx, handle, row, replaceRow, touched); err != nil {
return errors.Trace(err)
}
}
return nil
}
示例2: tryDeleteUsingIndex
func (s *DeleteStmt) tryDeleteUsingIndex(ctx context.Context, t table.Table) (bool, error) {
log.Info("try delete with index", ctx)
p, err := s.indexPlan(ctx)
if p == nil || err != nil {
return false, errors.Trace(err)
}
var rowKeys []*plan.RowKeyEntry
for {
row, err1 := p.Next(ctx)
if err1 != nil {
return false, errors.Trace(err1)
}
if row == nil {
break
}
rowKeys = append(rowKeys, row.RowKeys...)
}
var cnt uint64
for _, rowKey := range rowKeys {
if s.Limit != nil && cnt >= s.Limit.Count {
break
}
handle, err := util.DecodeHandleFromRowKey(rowKey.Key)
if err != nil {
return false, errors.Trace(err)
}
data, err := t.Row(ctx, handle)
if err != nil {
return false, err
}
log.Infof("try delete with index id:%d, ctx:%s", handle, ctx)
ok, err := s.hitWhere(ctx, t, data)
if err != nil {
return false, errors.Trace(err)
}
if !ok {
return true, nil
}
err = s.removeRow(ctx, t, handle, data)
if err != nil {
return false, err
}
cnt++
}
return true, nil
}
示例3: tryDeleteUsingIndex
func (s *DeleteStmt) tryDeleteUsingIndex(ctx context.Context, t table.Table) (bool, error) {
log.Info("try delete with index", ctx)
p, err := s.indexPlan(ctx)
if err != nil {
return false, err
}
if p != nil {
var ids []int64
err := p.Do(ctx, func(id interface{}, _ []interface{}) (bool, error) {
// Generate ids for coming deletion.
ids = append(ids, id.(int64))
return true, nil
})
if err != nil {
return false, err
}
var cnt uint64
for _, id := range ids {
if s.Limit != nil && cnt >= s.Limit.Count {
break
}
data, err := t.Row(ctx, id)
if err != nil {
return false, err
}
log.Infof("try delete with index id:%d, ctx:%s", id, ctx)
ok, err := s.hitWhere(ctx, t, data)
if err != nil {
return false, errors.Trace(err)
}
if !ok {
return true, nil
}
err = s.removeRow(ctx, t, id, data)
if err != nil {
return false, err
}
cnt++
}
return true, nil
}
return false, nil
}
示例4: execOnDuplicateUpdate
func execOnDuplicateUpdate(ctx context.Context, t table.Table, row []interface{}, h int64, cols map[int]*expression.Assignment) error {
// On duplicate key update the duplicate row.
// Evaluate the updated value.
// TODO: report rows affected and last insert id.
data, err := t.Row(ctx, h)
if err != nil {
return errors.Trace(err)
}
toUpdateArgs := map[interface{}]interface{}{}
toUpdateArgs[expression.ExprEvalValuesFunc] = func(name string) (interface{}, error) {
c, err1 := findColumnByName(t, name)
if err1 != nil {
return nil, errors.Trace(err1)
}
return row[c.Offset], nil
}
if err = updateRecord(ctx, h, data, t, cols, toUpdateArgs, 0, true); err != nil {
return errors.Trace(err)
}
return nil
}
示例5: tryUpdateUsingIndex
func (s *UpdateStmt) tryUpdateUsingIndex(ctx context.Context, t table.Table) (bool, error) {
log.Info("update using index")
p, err := s.indexPlan(ctx)
if p == nil {
return false, err
}
var handles []int64
p.Do(ctx, func(id interface{}, _ []interface{}) (more bool, err error) {
// Record handle ids for updating.
handles = append(handles, id.(int64))
return true, nil
})
tcols, err := getUpdateColumns(t, s.List)
if err != nil {
return false, err
}
var cnt uint64
for _, id := range handles {
data, err := t.Row(ctx, id)
if err != nil {
return false, err
}
log.Info("updating ", id)
if s.Limit != nil && cnt >= s.Limit.Count {
break
}
err = updateRecord(ctx, id, data, t, tcols, s.List, nil)
if err != nil {
return false, err
}
cnt++
}
return true, nil
}