本文整理汇总了Golang中github.com/pingcap/tidb/sessionctx/variable.GetSysVar函数的典型用法代码示例。如果您正苦于以下问题:Golang GetSysVar函数的具体用法?Golang GetSysVar怎么用?Golang GetSysVar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetSysVar函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetGlobalSysVar
// GetGlobalSysVar implements GlobalVarAccessor GetGlobalSysVar interface.
func (c *Context) GetGlobalSysVar(ctx context.Context, name string) (string, error) {
v := variable.GetSysVar(name)
if v == nil {
return "", terror.UnknownSystemVar.Gen("unknown sys variable: %s", name)
}
return v.Value, nil
}
示例2: SetGlobalSysVar
// SetGlobalSysVar implements GlobalVarAccessor SetGlobalSysVar interface.
func (c *Context) SetGlobalSysVar(ctx context.Context, name string, value string) error {
v := variable.GetSysVar(name)
if v == nil {
return terror.UnknownSystemVar.Gen("unknown sys variable: %s", name)
}
v.Value = value
return nil
}
示例3: executeSet
func (e *SimpleExec) executeSet(s *ast.SetStmt) error {
sessionVars := variable.GetSessionVars(e.ctx)
globalVars := variable.GetGlobalVarAccessor(e.ctx)
for _, v := range s.Variables {
// Variable is case insensitive, we use lower case.
if v.Name == ast.SetNames {
// This is set charset stmt.
cs := v.Value.GetValue().(string)
var co string
if v.ExtendValue != nil {
co = v.ExtendValue.GetValue().(string)
}
err := e.setCharset(cs, co)
if err != nil {
return errors.Trace(err)
}
continue
}
name := strings.ToLower(v.Name)
if !v.IsSystem {
// Set user variable.
value, err := evaluator.Eval(e.ctx, v.Value)
if err != nil {
return errors.Trace(err)
}
if value.IsNull() {
delete(sessionVars.Users, name)
} else {
svalue, err1 := value.ToString()
if err1 != nil {
return errors.Trace(err1)
}
sessionVars.Users[name] = fmt.Sprintf("%v", svalue)
}
continue
}
// Set system variable
sysVar := variable.GetSysVar(name)
if sysVar == nil {
return variable.UnknownSystemVar.Gen("Unknown system variable '%s'", name)
}
if sysVar.Scope == variable.ScopeNone {
return errors.Errorf("Variable '%s' is a read only variable", name)
}
if v.IsGlobal {
// Set global scope system variable.
if sysVar.Scope&variable.ScopeGlobal == 0 {
return errors.Errorf("Variable '%s' is a SESSION variable and can't be used with SET GLOBAL", name)
}
value, err := evaluator.Eval(e.ctx, v.Value)
if err != nil {
return errors.Trace(err)
}
if value.IsNull() {
value.SetString("")
}
svalue, err := value.ToString()
if err != nil {
return errors.Trace(err)
}
err = globalVars.SetGlobalSysVar(e.ctx, name, svalue)
if err != nil {
return errors.Trace(err)
}
} else {
// Set session scope system variable.
if sysVar.Scope&variable.ScopeSession == 0 {
return errors.Errorf("Variable '%s' is a GLOBAL variable and should be set with SET GLOBAL", name)
}
value, err := evaluator.Eval(e.ctx, v.Value)
if err != nil {
return errors.Trace(err)
}
err = sessionVars.SetSystemVar(name, value)
if err != nil {
return errors.Trace(err)
}
}
}
return nil
}
示例4: Exec
// Exec implements the stmt.Statement Exec interface.
func (s *SetStmt) Exec(ctx context.Context) (_ rset.Recordset, err error) {
log.Debug("Set sys/user variables")
sessionVars := variable.GetSessionVars(ctx)
globalVars := variable.GetGlobalVarAccessor(ctx)
for _, v := range s.Variables {
// Variable is case insensitive, we use lower case.
name := strings.ToLower(v.Name)
if !v.IsSystem {
// User variable.
value, err := v.getValue(ctx)
if err != nil {
return nil, errors.Trace(err)
}
if value == nil {
delete(sessionVars.Users, name)
} else {
sessionVars.Users[name] = fmt.Sprintf("%v", value)
}
return nil, nil
}
sysVar := variable.GetSysVar(name)
if sysVar == nil {
return nil, variable.UnknownSystemVar.Gen("Unknown system variable '%s'", name)
}
if sysVar.Scope == variable.ScopeNone {
return nil, errors.Errorf("Variable '%s' is a read only variable", name)
}
if v.IsGlobal {
if sysVar.Scope&variable.ScopeGlobal > 0 {
value, err := v.getValue(ctx)
if err != nil {
return nil, errors.Trace(err)
}
if value == nil {
value = ""
}
svalue, err := types.ToString(value)
if err != nil {
return nil, errors.Trace(err)
}
err = globalVars.SetGlobalSysVar(ctx, name, svalue)
return nil, errors.Trace(err)
}
return nil, errors.Errorf("Variable '%s' is a SESSION variable and can't be used with SET GLOBAL", name)
}
if sysVar.Scope&variable.ScopeSession > 0 {
if value, err := v.getValue(ctx); err != nil {
return nil, errors.Trace(err)
} else if value == nil {
sessionVars.Systems[name] = ""
} else {
sessionVars.Systems[name] = fmt.Sprintf("%v", value)
}
return nil, nil
}
return nil, errors.Errorf("Variable '%s' is a GLOBAL variable and should be set with SET GLOBAL", name)
}
return nil, nil
}
示例5: executeSet
func (e *SetExecutor) executeSet() error {
sessionVars := e.ctx.GetSessionVars()
for _, v := range e.vars {
// Variable is case insensitive, we use lower case.
if v.Name == ast.SetNames {
// This is set charset stmt.
cs := v.Expr.(*expression.Constant).Value.GetString()
var co string
if v.ExtendValue != nil {
co = v.ExtendValue.Value.GetString()
}
err := e.setCharset(cs, co)
if err != nil {
return errors.Trace(err)
}
continue
}
name := strings.ToLower(v.Name)
if !v.IsSystem {
// Set user variable.
value, err := v.Expr.Eval(nil, e.ctx)
if err != nil {
return errors.Trace(err)
}
if value.IsNull() {
delete(sessionVars.Users, name)
} else {
svalue, err1 := value.ToString()
if err1 != nil {
return errors.Trace(err1)
}
sessionVars.Users[name] = fmt.Sprintf("%v", svalue)
}
continue
}
// Set system variable
sysVar := variable.GetSysVar(name)
if sysVar == nil {
return variable.UnknownSystemVar.GenByArgs(name)
}
if sysVar.Scope == variable.ScopeNone {
return errors.Errorf("Variable '%s' is a read only variable", name)
}
if v.IsGlobal {
// Set global scope system variable.
if sysVar.Scope&variable.ScopeGlobal == 0 {
return errors.Errorf("Variable '%s' is a SESSION variable and can't be used with SET GLOBAL", name)
}
value, err := e.getVarValue(v, sysVar)
if err != nil {
return errors.Trace(err)
}
if value.IsNull() {
value.SetString("")
}
svalue, err := value.ToString()
if err != nil {
return errors.Trace(err)
}
err = sessionVars.GlobalVarsAccessor.SetGlobalSysVar(name, svalue)
if err != nil {
return errors.Trace(err)
}
} else {
// Set session scope system variable.
if sysVar.Scope&variable.ScopeSession == 0 {
return errors.Errorf("Variable '%s' is a GLOBAL variable and should be set with SET GLOBAL", name)
}
value, err := e.getVarValue(v, nil)
if err != nil {
return errors.Trace(err)
}
err = varsutil.SetSystemVar(sessionVars, name, value)
if err != nil {
return errors.Trace(err)
}
e.loadSnapshotInfoSchemaIfNeeded(name)
log.Infof("[%d] set system variable %s = %s", sessionVars.ConnectionID, name, value.GetString())
}
}
return nil
}
示例6: Exec
// Exec implements the stmt.Statement Exec interface.
func (s *SetStmt) Exec(ctx context.Context) (_ rset.Recordset, err error) {
log.Debug("Set sys/user variables")
sessionVars := variable.GetSessionVars(ctx)
for _, v := range s.Variables {
// Variable is case insensitive, we use lower case.
name := strings.ToLower(v.Name)
if !v.IsSystem {
// User variable.
value, err := v.getValue(ctx)
if err != nil {
return nil, errors.Trace(err)
}
if value == nil {
delete(sessionVars.Users, name)
} else {
sessionVars.Users[name] = fmt.Sprintf("%v", value)
}
return nil, nil
}
// TODO: should get global sys var from db.
sysVar := variable.GetSysVar(name)
if sysVar == nil {
return nil, errors.Errorf("Unknown system variable '%s'", name)
}
if sysVar.Scope == variable.ScopeNone {
return nil, errors.Errorf("Variable '%s' is a read only variable", name)
}
if v.IsGlobal {
if sysVar.Scope&variable.ScopeGlobal > 0 {
value, err := v.getValue(ctx)
if err != nil {
return nil, errors.Trace(err)
}
if value == nil {
sysVar.Value = ""
} else {
// TODO: set global variables in db, now we only change memory global sys var map.
// TODO: check sys variable type if possible.
sysVar.Value = fmt.Sprintf("%v", value)
}
return nil, nil
}
return nil, errors.Errorf("Variable '%s' is a SESSION variable and can't be used with SET GLOBAL", name)
}
if sysVar.Scope&variable.ScopeSession > 0 {
if value, err := v.getValue(ctx); err != nil {
return nil, errors.Trace(err)
} else if value == nil {
sysVar.Value = ""
} else {
// TODO: check sys variable type if possible.
sessionVars.Systems[name] = fmt.Sprintf("%v", value)
}
return nil, nil
}
return nil, errors.Errorf("Variable '%s' is a GLOBAL variable and should be set with SET GLOBAL", name)
}
return nil, nil
}
示例7: executeSet
func (e *SimpleExec) executeSet(s *ast.SetStmt) error {
sessionVars := variable.GetSessionVars(e.ctx)
globalVars := variable.GetGlobalVarAccessor(e.ctx)
for _, v := range s.Variables {
// Variable is case insensitive, we use lower case.
name := strings.ToLower(v.Name)
if !v.IsSystem {
// Set user variable.
value, err := evaluator.Eval(e.ctx, v.Value)
if err != nil {
return errors.Trace(err)
}
if value == nil {
delete(sessionVars.Users, name)
} else {
sessionVars.Users[name] = fmt.Sprintf("%v", value)
}
continue
}
// Set system variable
sysVar := variable.GetSysVar(name)
if sysVar == nil {
return variable.UnknownSystemVar.Gen("Unknown system variable '%s'", name)
}
if sysVar.Scope == variable.ScopeNone {
return errors.Errorf("Variable '%s' is a read only variable", name)
}
if v.IsGlobal {
// Set global scope system variable.
if sysVar.Scope&variable.ScopeGlobal == 0 {
return errors.Errorf("Variable '%s' is a SESSION variable and can't be used with SET GLOBAL", name)
}
value, err := evaluator.Eval(e.ctx, v.Value)
if err != nil {
return errors.Trace(err)
}
if value == nil {
value = ""
}
svalue, err := types.ToString(value)
if err != nil {
return errors.Trace(err)
}
err = globalVars.SetGlobalSysVar(e.ctx, name, svalue)
if err != nil {
return errors.Trace(err)
}
} else {
// Set session scope system variable.
if sysVar.Scope&variable.ScopeSession == 0 {
return errors.Errorf("Variable '%s' is a GLOBAL variable and should be set with SET GLOBAL", name)
}
if value, err := evaluator.Eval(e.ctx, v.Value); err != nil {
return errors.Trace(err)
} else if value == nil {
sessionVars.Systems[name] = ""
} else {
sessionVars.Systems[name] = fmt.Sprintf("%v", value)
}
}
}
return nil
}