本文整理匯總了Golang中github.com/pingcap/tidb/ast.VariableExpr類的典型用法代碼示例。如果您正苦於以下問題:Golang VariableExpr類的具體用法?Golang VariableExpr怎麽用?Golang VariableExpr使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了VariableExpr類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: variable
func (e *Evaluator) variable(v *ast.VariableExpr) bool {
name := strings.ToLower(v.Name)
sessionVars := variable.GetSessionVars(e.ctx)
globalVars := variable.GetGlobalVarAccessor(e.ctx)
if !v.IsSystem {
// user vars
if value, ok := sessionVars.Users[name]; ok {
v.SetString(value)
return true
}
// select null user vars is permitted.
v.SetNull()
return true
}
_, ok := variable.SysVars[name]
if !ok {
// select null sys vars is not permitted
e.err = variable.UnknownSystemVar.Gen("Unknown system variable '%s'", name)
return false
}
if !v.IsGlobal {
if value, ok := sessionVars.Systems[name]; ok {
v.SetString(value)
return true
}
}
value, err := globalVars.GetGlobalSysVar(e.ctx, name)
if err != nil {
e.err = errors.Trace(err)
return false
}
v.SetString(value)
return true
}
示例2: variable
func (e *Evaluator) variable(v *ast.VariableExpr) bool {
name := strings.ToLower(v.Name)
sessionVars := variable.GetSessionVars(e.ctx)
globalVars := variable.GetGlobalVarAccessor(e.ctx)
if !v.IsSystem {
if v.Value != nil && !v.Value.GetDatum().IsNull() {
strVal, err := v.Value.GetDatum().ToString()
if err != nil {
e.err = errors.Trace(err)
return false
}
sessionVars.Users[name] = strings.ToLower(strVal)
v.SetString(strVal)
return true
}
// user vars
if value, ok := sessionVars.Users[name]; ok {
v.SetString(value)
return true
}
// select null user vars is permitted.
v.SetNull()
return true
}
sysVar, ok := variable.SysVars[name]
if !ok {
// select null sys vars is not permitted
e.err = variable.UnknownSystemVar.Gen("Unknown system variable '%s'", name)
return false
}
if sysVar.Scope == variable.ScopeNone {
v.SetString(sysVar.Value)
return true
}
if !v.IsGlobal {
d := sessionVars.GetSystemVar(name)
if d.IsNull() {
if sysVar.Scope&variable.ScopeGlobal == 0 {
d.SetString(sysVar.Value)
} else {
// Get global system variable and fill it in session.
globalVal, err := globalVars.GetGlobalSysVar(e.ctx, name)
if err != nil {
e.err = errors.Trace(err)
return false
}
d.SetString(globalVal)
err = sessionVars.SetSystemVar(name, d)
if err != nil {
e.err = errors.Trace(err)
return false
}
}
}
v.SetDatum(d)
return true
}
value, err := globalVars.GetGlobalSysVar(e.ctx, name)
if err != nil {
e.err = errors.Trace(err)
return false
}
v.SetString(value)
return true
}