本文整理匯總了Golang中github.com/pingcap/tidb/ast.CaseExpr類的典型用法代碼示例。如果您正苦於以下問題:Golang CaseExpr類的具體用法?Golang CaseExpr怎麽用?Golang CaseExpr使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了CaseExpr類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: handleCaseExpr
// The return type of a CASE expression is the compatible aggregated type of all return values,
// but also depends on the context in which it is used.
// If used in a string context, the result is returned as a string.
// If used in a numeric context, the result is returned as a decimal, real, or integer value.
func (v *typeInferrer) handleCaseExpr(x *ast.CaseExpr) {
var currType *types.FieldType
for _, w := range x.WhenClauses {
t := w.Result.GetType()
if currType == nil {
currType = t
continue
}
mtp := types.MergeFieldType(currType.Tp, t.Tp)
if mtp == t.Tp && mtp != currType.Tp {
currType.Charset = t.Charset
currType.Collate = t.Collate
}
currType.Tp = mtp
}
if x.ElseClause != nil {
t := x.ElseClause.GetType()
if currType == nil {
currType = t
} else {
mtp := types.MergeFieldType(currType.Tp, t.Tp)
if mtp == t.Tp && mtp != currType.Tp {
currType.Charset = t.Charset
currType.Collate = t.Collate
}
currType.Tp = mtp
}
}
x.SetType(currType)
// TODO: We need a better way to set charset/collation
x.Type.Charset, x.Type.Collate = types.DefaultCharsetForType(x.Type.Tp)
}
示例2: caseExpr
func (e *Evaluator) caseExpr(v *ast.CaseExpr) bool {
tmp := types.NewDatum(boolToInt64(true))
target := &tmp
if v.Value != nil {
target = v.Value.GetDatum()
}
if !target.IsNull() {
for _, val := range v.WhenClauses {
cmp, err := target.CompareDatum(*val.Expr.GetDatum())
if err != nil {
e.err = errors.Trace(err)
return false
}
if cmp == 0 {
v.SetDatum(*val.Result.GetDatum())
return true
}
}
}
if v.ElseClause != nil {
v.SetDatum(*v.ElseClause.GetDatum())
} else {
v.SetNull()
}
return true
}
示例3: caseExpr
func (e *Evaluator) caseExpr(v *ast.CaseExpr) bool {
var target interface{} = true
if v.Value != nil {
target = v.Value.GetValue()
}
if target != nil {
for _, val := range v.WhenClauses {
cmp, err := types.Compare(target, val.Expr.GetValue())
if err != nil {
e.err = errors.Trace(err)
return false
}
if cmp == 0 {
v.SetValue(val.Result.GetValue())
return true
}
}
}
if v.ElseClause != nil {
v.SetValue(v.ElseClause.GetValue())
} else {
v.SetValue(nil)
}
return true
}