本文整理汇总了Golang中github.com/pingcap/tidb/util/types.Datum.ToString方法的典型用法代码示例。如果您正苦于以下问题:Golang Datum.ToString方法的具体用法?Golang Datum.ToString怎么用?Golang Datum.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/util/types.Datum
的用法示例。
在下文中一共展示了Datum.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SetSystemVar
// SetSystemVar sets a system variable.
func (s *SessionVars) SetSystemVar(key string, value types.Datum) error {
key = strings.ToLower(key)
if value.IsNull() {
if key != characterSetResults {
return errCantSetToNull
}
delete(s.systems, key)
return nil
}
sVal, err := value.ToString()
if err != nil {
return errors.Trace(err)
}
if key == sqlMode {
sVal = strings.ToUpper(sVal)
if strings.Contains(sVal, "STRICT_TRANS_TABLES") || strings.Contains(sVal, "STRICT_ALL_TABLES") {
s.StrictSQLMode = true
} else {
s.StrictSQLMode = false
}
} else if key == TiDBSnapshot {
err = s.setSnapshotTS(sVal)
if err != nil {
return errors.Trace(err)
}
}
s.systems[key] = sVal
return nil
}
示例2: SetSystemVar
// SetSystemVar sets system variable and updates SessionVars states.
func SetSystemVar(vars *variable.SessionVars, name string, value types.Datum) error {
name = strings.ToLower(name)
if value.IsNull() {
if name != variable.CharacterSetResults {
return variable.ErrCantSetToNull
}
delete(vars.Systems, name)
return nil
}
sVal, err := value.ToString()
if err != nil {
return errors.Trace(err)
}
switch name {
case variable.SQLModeVar:
sVal = strings.ToUpper(sVal)
if strings.Contains(sVal, "STRICT_TRANS_TABLES") || strings.Contains(sVal, "STRICT_ALL_TABLES") {
vars.StrictSQLMode = true
} else {
vars.StrictSQLMode = false
}
case variable.TiDBSnapshot:
err = setSnapshotTS(vars, sVal)
if err != nil {
return errors.Trace(err)
}
case variable.AutocommitVar:
isAutocommit := strings.EqualFold(sVal, "ON") || sVal == "1"
vars.SetStatusFlag(mysql.ServerStatusAutocommit, isAutocommit)
case variable.TiDBSkipConstraintCheck:
vars.SkipConstraintCheck = (sVal == "1")
}
vars.Systems[name] = sVal
return nil
}
示例3: rewriteVariable
func (er *expressionRewriter) rewriteVariable(v *ast.VariableExpr) bool {
stkLen := len(er.ctxStack)
name := strings.ToLower(v.Name)
sessionVars := variable.GetSessionVars(er.b.ctx)
globalVars := variable.GetGlobalVarAccessor(er.b.ctx)
if !v.IsSystem {
var d types.Datum
var err error
if v.Value != nil {
d, err = er.ctxStack[stkLen-1].Eval(nil, er.b.ctx)
if err != nil {
er.err = errors.Trace(err)
return false
}
er.ctxStack = er.ctxStack[:stkLen-1]
}
if !d.IsNull() {
strVal, err := d.ToString()
if err != nil {
er.err = errors.Trace(err)
return false
}
sessionVars.Users[name] = strings.ToLower(strVal)
er.ctxStack = append(er.ctxStack, datumToConstant(d, mysql.TypeString))
} else if value, ok := sessionVars.Users[name]; ok {
er.ctxStack = append(er.ctxStack, datumToConstant(types.NewStringDatum(value), mysql.TypeString))
} else {
// select null user vars is permitted.
er.ctxStack = append(er.ctxStack, &expression.Constant{RetType: types.NewFieldType(mysql.TypeNull)})
}
return true
}
sysVar, ok := variable.SysVars[name]
if !ok {
// select null sys vars is not permitted
er.err = variable.UnknownSystemVar.Gen("Unknown system variable '%s'", name)
return false
}
if sysVar.Scope == variable.ScopeNone {
er.ctxStack = append(er.ctxStack, datumToConstant(types.NewDatum(sysVar.Value), mysql.TypeString))
return true
}
if v.IsGlobal {
value, err := globalVars.GetGlobalSysVar(er.b.ctx, name)
if err != nil {
er.err = errors.Trace(err)
return false
}
er.ctxStack = append(er.ctxStack, datumToConstant(types.NewDatum(value), mysql.TypeString))
return true
}
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(er.b.ctx, name)
if err != nil {
er.err = errors.Trace(err)
return false
}
d.SetString(globalVal)
err = sessionVars.SetSystemVar(name, d)
if err != nil {
er.err = errors.Trace(err)
return false
}
}
}
er.ctxStack = append(er.ctxStack, datumToConstant(d, mysql.TypeString))
return true
}