本文整理匯總了Golang中github.com/pingcap/tidb/context.Context.ClearValue方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.ClearValue方法的具體用法?Golang Context.ClearValue怎麽用?Golang Context.ClearValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pingcap/tidb/context.Context
的用法示例。
在下文中一共展示了Context.ClearValue方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ExecRestrictedSQL
// ExecRestrictedSQL implements SQLHelper interface.
// This is used for executing some restricted sql statements.
func (s *session) ExecRestrictedSQL(ctx context.Context, sql string) (rset.Recordset, error) {
if ctx.Value(&sqlexec.RestrictedSQLExecutorKeyType{}) != nil {
// We do not support run this function concurrently.
// TODO: Maybe we should remove this restriction latter.
return nil, errors.New("Should not call ExecRestrictedSQL concurrently.")
}
statements, err := Compile(ctx, sql)
if err != nil {
log.Errorf("Compile %s with error: %v", sql, err)
return nil, errors.Trace(err)
}
if len(statements) != 1 {
log.Errorf("ExecRestrictedSQL only executes one statement. Too many/few statement in %s", sql)
return nil, errors.New("Wrong number of statement.")
}
st := statements[0]
// Check statement for some restriction
// For example only support DML on system meta table.
// TODO: Add more restrictions.
log.Debugf("Executing %s [%s]", st.OriginText(), sql)
ctx.SetValue(&sqlexec.RestrictedSQLExecutorKeyType{}, true)
defer ctx.ClearValue(&sqlexec.RestrictedSQLExecutorKeyType{})
rs, err := st.Exec(ctx)
return rs, errors.Trace(err)
}
示例2: popRowStack
func popRowStack(ctx context.Context) error {
s := getRowStack(ctx)
if s == nil || len(s.items) == 0 {
return errors.Errorf("pop empty row stack")
}
n := len(s.items) - 1
s.items[n] = nil
s.items = s.items[0:n]
if len(s.items) == 0 {
ctx.ClearValue(rowStackKey)
return nil
}
ctx.SetValue(rowStackKey, s)
return nil
}
示例3: pop
func (sq *SubQuery) pop(ctx context.Context) error {
v := ctx.Value(subQueryStackKey)
if v == nil {
return errors.Errorf("pop empty sub query stack")
}
st := v.([]*SubQuery)
// can not empty
n := len(st) - 1
if st[n] != sq {
return errors.Errorf("pop invalid top sub query in stack, want %v, but top is %v", sq, st[n])
}
st[n] = nil
st = st[0:n]
if len(st) == 0 {
ctx.ClearValue(subQueryStackKey)
return nil
}
ctx.SetValue(subQueryStackKey, st)
return nil
}
示例4: ClearExecArgs
// ClearExecArgs clears executive args from context.
func ClearExecArgs(ctx context.Context) {
ctx.ClearValue(execArgsKey)
}
示例5: ClearBinlog
// ClearBinlog clears binlog in the Context.
func ClearBinlog(ctx context.Context) {
ctx.ClearValue(binlogKey)
}